001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B>Supports additional targets discovery and allows to attach to them.</B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class Target
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private Target () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : Target.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        v = new Vector<String>(1);
078        parameterNames.put("activateTarget", v);
079        Collections.addAll(v, new String[]
080        { "targetId", });
081
082        v = new Vector<String>(2);
083        parameterNames.put("attachToTarget", v);
084        Collections.addAll(v, new String[]
085        { "targetId", "flatten", });
086
087        parameterNames.put("attachToBrowserTarget", EMPTY_VEC_STR);
088
089        v = new Vector<String>(1);
090        parameterNames.put("closeTarget", v);
091        Collections.addAll(v, new String[]
092        { "targetId", });
093
094        v = new Vector<String>(2);
095        parameterNames.put("exposeDevToolsProtocol", v);
096        Collections.addAll(v, new String[]
097        { "targetId", "bindingName", });
098
099        v = new Vector<String>(3);
100        parameterNames.put("createBrowserContext", v);
101        Collections.addAll(v, new String[]
102        { "disposeOnDetach", "proxyServer", "proxyBypassList", });
103
104        parameterNames.put("getBrowserContexts", EMPTY_VEC_STR);
105
106        v = new Vector<String>(7);
107        parameterNames.put("createTarget", v);
108        Collections.addAll(v, new String[]
109        { "url", "width", "height", "browserContextId", "enableBeginFrameControl", "newWindow", "background", });
110
111        v = new Vector<String>(2);
112        parameterNames.put("detachFromTarget", v);
113        Collections.addAll(v, new String[]
114        { "sessionId", "targetId", });
115
116        v = new Vector<String>(1);
117        parameterNames.put("disposeBrowserContext", v);
118        Collections.addAll(v, new String[]
119        { "browserContextId", });
120
121        v = new Vector<String>(1);
122        parameterNames.put("getTargetInfo", v);
123        Collections.addAll(v, new String[]
124        { "targetId", });
125
126        parameterNames.put("getTargets", EMPTY_VEC_STR);
127
128        v = new Vector<String>(3);
129        parameterNames.put("sendMessageToTarget", v);
130        Collections.addAll(v, new String[]
131        { "message", "sessionId", "targetId", });
132
133        v = new Vector<String>(3);
134        parameterNames.put("setAutoAttach", v);
135        Collections.addAll(v, new String[]
136        { "autoAttach", "waitForDebuggerOnStart", "flatten", });
137
138        v = new Vector<String>(2);
139        parameterNames.put("autoAttachRelated", v);
140        Collections.addAll(v, new String[]
141        { "targetId", "waitForDebuggerOnStart", });
142
143        v = new Vector<String>(1);
144        parameterNames.put("setDiscoverTargets", v);
145        Collections.addAll(v, new String[]
146        { "discover", });
147
148        v = new Vector<String>(1);
149        parameterNames.put("setRemoteLocations", v);
150        Collections.addAll(v, new String[]
151        { "locations", });
152    }
153
154
155    // ********************************************************************************************
156    // ********************************************************************************************
157    // Types - Static Inner Classes
158    // ********************************************************************************************
159    // ********************************************************************************************
160
161    // public static class TargetID => String
162    
163    // public static class SessionID => String
164    
165    /** <CODE>[No Description Provided by Google]</CODE> */
166    public static class TargetInfo
167        extends BaseType
168        implements java.io.Serializable
169    {
170        /** For Object Serialization.  java.io.Serializable */
171        protected static final long serialVersionUID = 1;
172        
173        public boolean[] optionals()
174        { return new boolean[] { false, false, false, false, false, true, false, true, true, }; }
175        
176        /** <CODE>[No Description Provided by Google]</CODE> */
177        public final String targetId;
178        
179        /** <CODE>[No Description Provided by Google]</CODE> */
180        public final String type;
181        
182        /** <CODE>[No Description Provided by Google]</CODE> */
183        public final String title;
184        
185        /** <CODE>[No Description Provided by Google]</CODE> */
186        public final String url;
187        
188        /** Whether the target has an attached client. */
189        public final boolean attached;
190        
191        /**
192         * Opener target Id
193         * <BR />
194         * <BR /><B>OPTIONAL</B>
195         */
196        public final String openerId;
197        
198        /**
199         * Whether the target has access to the originating window.
200         * <BR />
201         * <BR /><B>EXPERIMENTAL</B>
202         */
203        public final boolean canAccessOpener;
204        
205        /**
206         * Frame id of originating window (is only set if target has an opener).
207         * <BR />
208         * <BR /><B>OPTIONAL</B>
209         * <BR /><B>EXPERIMENTAL</B>
210         */
211        public final String openerFrameId;
212        
213        /**
214         * <CODE>[No Description Provided by Google]</CODE>
215         * <BR />
216         * <BR /><B>OPTIONAL</B>
217         * <BR /><B>EXPERIMENTAL</B>
218         */
219        public final String browserContextId;
220        
221        /**
222         * Constructor
223         *
224         * @param targetId -
225         * 
226         * @param type -
227         * 
228         * @param title -
229         * 
230         * @param url -
231         * 
232         * @param attached Whether the target has an attached client.
233         * 
234         * @param openerId Opener target Id
235         * <BR /><B>OPTIONAL</B>
236         * 
237         * @param canAccessOpener Whether the target has access to the originating window.
238         * <BR /><B>EXPERIMENTAL</B>
239         * 
240         * @param openerFrameId Frame id of originating window (is only set if target has an opener).
241         * <BR /><B>OPTIONAL</B>
242         * <BR /><B>EXPERIMENTAL</B>
243         * 
244         * @param browserContextId -
245         * <BR /><B>OPTIONAL</B>
246         * <BR /><B>EXPERIMENTAL</B>
247         */
248        public TargetInfo(
249                String targetId, String type, String title, String url, boolean attached, 
250                String openerId, boolean canAccessOpener, String openerFrameId, 
251                String browserContextId
252            )
253        {
254            // Exception-Check(s) to ensure that if any parameters which are not declared as
255            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
256            
257            if (targetId == null) BRDPC.throwNPE("targetId");
258            if (type == null)     BRDPC.throwNPE("type");
259            if (title == null)    BRDPC.throwNPE("title");
260            if (url == null)      BRDPC.throwNPE("url");
261            
262            this.targetId          = targetId;
263            this.type              = type;
264            this.title             = title;
265            this.url               = url;
266            this.attached          = attached;
267            this.openerId          = openerId;
268            this.canAccessOpener   = canAccessOpener;
269            this.openerFrameId     = openerFrameId;
270            this.browserContextId  = browserContextId;
271        }
272        
273        /**
274         * JSON Object Constructor
275         * @param jo A Json-Object having data about an instance of {@code 'TargetInfo'}.
276         */
277        public TargetInfo (JsonObject jo)
278        {
279            this.targetId          = ReadJSON.getString(jo, "targetId", false, true);
280            this.type              = ReadJSON.getString(jo, "type", false, true);
281            this.title             = ReadJSON.getString(jo, "title", false, true);
282            this.url               = ReadJSON.getString(jo, "url", false, true);
283            this.attached          = ReadPrimJSON.getBoolean(jo, "attached");
284            this.openerId          = ReadJSON.getString(jo, "openerId", true, false);
285            this.canAccessOpener   = ReadPrimJSON.getBoolean(jo, "canAccessOpener");
286            this.openerFrameId     = ReadJSON.getString(jo, "openerFrameId", true, false);
287            this.browserContextId  = ReadJSON.getString(jo, "browserContextId", true, false);
288        }
289        
290        
291        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
292        public boolean equals(Object other)
293        {
294            if (other == null)                       return false;
295            if (other.getClass() != this.getClass()) return false;
296        
297            TargetInfo o = (TargetInfo) other;
298        
299            return
300                    Objects.equals(this.targetId, o.targetId)
301                &&  Objects.equals(this.type, o.type)
302                &&  Objects.equals(this.title, o.title)
303                &&  Objects.equals(this.url, o.url)
304                &&  (this.attached == o.attached)
305                &&  Objects.equals(this.openerId, o.openerId)
306                &&  (this.canAccessOpener == o.canAccessOpener)
307                &&  Objects.equals(this.openerFrameId, o.openerFrameId)
308                &&  Objects.equals(this.browserContextId, o.browserContextId);
309        }
310        
311        /** Generates a Hash-Code for {@code 'this'} instance */
312        public int hashCode()
313        {
314            return
315                    Objects.hashCode(this.targetId)
316                +   Objects.hashCode(this.type)
317                +   Objects.hashCode(this.title)
318                +   Objects.hashCode(this.url)
319                +   (this.attached ? 1 : 0)
320                +   Objects.hashCode(this.openerId)
321                +   (this.canAccessOpener ? 1 : 0)
322                +   Objects.hashCode(this.openerFrameId)
323                +   Objects.hashCode(this.browserContextId);
324        }
325    }
326    
327    /**
328     * <CODE>[No Description Provided by Google]</CODE>
329     * <BR />
330     * <BR /><B>EXPERIMENTAL</B>
331     */
332    public static class RemoteLocation
333        extends BaseType
334        implements java.io.Serializable
335    {
336        /** For Object Serialization.  java.io.Serializable */
337        protected static final long serialVersionUID = 1;
338        
339        public boolean[] optionals()
340        { return new boolean[] { false, false, }; }
341        
342        /** <CODE>[No Description Provided by Google]</CODE> */
343        public final String host;
344        
345        /** <CODE>[No Description Provided by Google]</CODE> */
346        public final int port;
347        
348        /**
349         * Constructor
350         *
351         * @param host -
352         * 
353         * @param port -
354         */
355        public RemoteLocation(String host, int port)
356        {
357            // Exception-Check(s) to ensure that if any parameters which are not declared as
358            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
359            
360            if (host == null) BRDPC.throwNPE("host");
361            
362            this.host  = host;
363            this.port  = port;
364        }
365        
366        /**
367         * JSON Object Constructor
368         * @param jo A Json-Object having data about an instance of {@code 'RemoteLocation'}.
369         */
370        public RemoteLocation (JsonObject jo)
371        {
372            this.host  = ReadJSON.getString(jo, "host", false, true);
373            this.port  = ReadPrimJSON.getInt(jo, "port");
374        }
375        
376        
377        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
378        public boolean equals(Object other)
379        {
380            if (other == null)                       return false;
381            if (other.getClass() != this.getClass()) return false;
382        
383            RemoteLocation o = (RemoteLocation) other;
384        
385            return
386                    Objects.equals(this.host, o.host)
387                &&  (this.port == o.port);
388        }
389        
390        /** Generates a Hash-Code for {@code 'this'} instance */
391        public int hashCode()
392        {
393            return
394                    Objects.hashCode(this.host)
395                +   this.port;
396        }
397    }
398    
399    /**
400     * Issued when attached to target because of auto-attach or <CODE>attachToTarget</CODE> command.
401     * <BR />
402     * <BR /><B>EXPERIMENTAL</B>
403     */
404    public static class attachedToTarget
405        extends BrowserEvent
406        implements java.io.Serializable
407    {
408        /** For Object Serialization.  java.io.Serializable */
409        protected static final long serialVersionUID = 1;
410        
411        public boolean[] optionals()
412        { return new boolean[] { false, false, false, }; }
413        
414        /** Identifier assigned to the session used to send/receive messages. */
415        public final String sessionId;
416        
417        /** <CODE>[No Description Provided by Google]</CODE> */
418        public final Target.TargetInfo targetInfo;
419        
420        /** <CODE>[No Description Provided by Google]</CODE> */
421        public final boolean waitingForDebugger;
422        
423        /**
424         * Constructor
425         *
426         * @param sessionId Identifier assigned to the session used to send/receive messages.
427         * 
428         * @param targetInfo -
429         * 
430         * @param waitingForDebugger -
431         */
432        public attachedToTarget
433            (String sessionId, Target.TargetInfo targetInfo, boolean waitingForDebugger)
434        {
435            super("Target", "attachedToTarget", 3);
436            
437            // Exception-Check(s) to ensure that if any parameters which are not declared as
438            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
439            
440            if (sessionId == null)  BRDPC.throwNPE("sessionId");
441            if (targetInfo == null) BRDPC.throwNPE("targetInfo");
442            
443            this.sessionId           = sessionId;
444            this.targetInfo          = targetInfo;
445            this.waitingForDebugger  = waitingForDebugger;
446        }
447        
448        /**
449         * JSON Object Constructor
450         * @param jo A Json-Object having data about an instance of {@code 'attachedToTarget'}.
451         */
452        public attachedToTarget (JsonObject jo)
453        {
454            super("Target", "attachedToTarget", 3);
455        
456            this.sessionId           = ReadJSON.getString(jo, "sessionId", false, true);
457            this.targetInfo          = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true);
458            this.waitingForDebugger  = ReadPrimJSON.getBoolean(jo, "waitingForDebugger");
459        }
460        
461        
462        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
463        public boolean equals(Object other)
464        {
465            if (other == null)                       return false;
466            if (other.getClass() != this.getClass()) return false;
467        
468            attachedToTarget o = (attachedToTarget) other;
469        
470            return
471                    Objects.equals(this.sessionId, o.sessionId)
472                &&  Objects.equals(this.targetInfo, o.targetInfo)
473                &&  (this.waitingForDebugger == o.waitingForDebugger);
474        }
475        
476        /** Generates a Hash-Code for {@code 'this'} instance */
477        public int hashCode()
478        {
479            return
480                    Objects.hashCode(this.sessionId)
481                +   this.targetInfo.hashCode()
482                +   (this.waitingForDebugger ? 1 : 0);
483        }
484    }
485    
486    /**
487     * Issued when detached from target for any reason (including <CODE>detachFromTarget</CODE> command). Can be
488     * issued multiple times per target if multiple sessions have been attached to it.
489     * <BR />
490     * <BR /><B>EXPERIMENTAL</B>
491     */
492    public static class detachedFromTarget
493        extends BrowserEvent
494        implements java.io.Serializable
495    {
496        /** For Object Serialization.  java.io.Serializable */
497        protected static final long serialVersionUID = 1;
498        
499        public boolean[] optionals()
500        { return new boolean[] { false, true, }; }
501        
502        /** Detached session identifier. */
503        public final String sessionId;
504        
505        /**
506         * Deprecated.
507         * <BR />
508         * <BR /><B>OPTIONAL</B>
509         * <BR /><B>DEPRECATED</B>
510         */
511        public final String targetId;
512        
513        /**
514         * Constructor
515         *
516         * @param sessionId Detached session identifier.
517         * 
518         * @param targetId Deprecated.
519         * <BR /><B>OPTIONAL</B>
520         * <BR /><B>DEPRECATED</B>
521         */
522        public detachedFromTarget(String sessionId, String targetId)
523        {
524            super("Target", "detachedFromTarget", 2);
525            
526            // Exception-Check(s) to ensure that if any parameters which are not declared as
527            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
528            
529            if (sessionId == null) BRDPC.throwNPE("sessionId");
530            
531            this.sessionId  = sessionId;
532            this.targetId   = targetId;
533        }
534        
535        /**
536         * JSON Object Constructor
537         * @param jo A Json-Object having data about an instance of {@code 'detachedFromTarget'}.
538         */
539        public detachedFromTarget (JsonObject jo)
540        {
541            super("Target", "detachedFromTarget", 2);
542        
543            this.sessionId  = ReadJSON.getString(jo, "sessionId", false, true);
544            this.targetId   = ReadJSON.getString(jo, "targetId", true, false);
545        }
546        
547        
548        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
549        public boolean equals(Object other)
550        {
551            if (other == null)                       return false;
552            if (other.getClass() != this.getClass()) return false;
553        
554            detachedFromTarget o = (detachedFromTarget) other;
555        
556            return
557                    Objects.equals(this.sessionId, o.sessionId)
558                &&  Objects.equals(this.targetId, o.targetId);
559        }
560        
561        /** Generates a Hash-Code for {@code 'this'} instance */
562        public int hashCode()
563        {
564            return
565                    Objects.hashCode(this.sessionId)
566                +   Objects.hashCode(this.targetId);
567        }
568    }
569    
570    /**
571     * Notifies about a new protocol message received from the session (as reported in
572     * <CODE>attachedToTarget</CODE> event).
573     */
574    public static class receivedMessageFromTarget
575        extends BrowserEvent
576        implements java.io.Serializable
577    {
578        /** For Object Serialization.  java.io.Serializable */
579        protected static final long serialVersionUID = 1;
580        
581        public boolean[] optionals()
582        { return new boolean[] { false, false, true, }; }
583        
584        /** Identifier of a session which sends a message. */
585        public final String sessionId;
586        
587        /** <CODE>[No Description Provided by Google]</CODE> */
588        public final String message;
589        
590        /**
591         * Deprecated.
592         * <BR />
593         * <BR /><B>OPTIONAL</B>
594         * <BR /><B>DEPRECATED</B>
595         */
596        public final String targetId;
597        
598        /**
599         * Constructor
600         *
601         * @param sessionId Identifier of a session which sends a message.
602         * 
603         * @param message -
604         * 
605         * @param targetId Deprecated.
606         * <BR /><B>OPTIONAL</B>
607         * <BR /><B>DEPRECATED</B>
608         */
609        public receivedMessageFromTarget(String sessionId, String message, String targetId)
610        {
611            super("Target", "receivedMessageFromTarget", 3);
612            
613            // Exception-Check(s) to ensure that if any parameters which are not declared as
614            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
615            
616            if (sessionId == null) BRDPC.throwNPE("sessionId");
617            if (message == null)   BRDPC.throwNPE("message");
618            
619            this.sessionId  = sessionId;
620            this.message    = message;
621            this.targetId   = targetId;
622        }
623        
624        /**
625         * JSON Object Constructor
626         * @param jo A Json-Object having data about an instance of {@code 'receivedMessageFromTarget'}.
627         */
628        public receivedMessageFromTarget (JsonObject jo)
629        {
630            super("Target", "receivedMessageFromTarget", 3);
631        
632            this.sessionId  = ReadJSON.getString(jo, "sessionId", false, true);
633            this.message    = ReadJSON.getString(jo, "message", false, true);
634            this.targetId   = ReadJSON.getString(jo, "targetId", true, false);
635        }
636        
637        
638        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
639        public boolean equals(Object other)
640        {
641            if (other == null)                       return false;
642            if (other.getClass() != this.getClass()) return false;
643        
644            receivedMessageFromTarget o = (receivedMessageFromTarget) other;
645        
646            return
647                    Objects.equals(this.sessionId, o.sessionId)
648                &&  Objects.equals(this.message, o.message)
649                &&  Objects.equals(this.targetId, o.targetId);
650        }
651        
652        /** Generates a Hash-Code for {@code 'this'} instance */
653        public int hashCode()
654        {
655            return
656                    Objects.hashCode(this.sessionId)
657                +   Objects.hashCode(this.message)
658                +   Objects.hashCode(this.targetId);
659        }
660    }
661    
662    /** Issued when a possible inspection target is created. */
663    public static class targetCreated
664        extends BrowserEvent
665        implements java.io.Serializable
666    {
667        /** For Object Serialization.  java.io.Serializable */
668        protected static final long serialVersionUID = 1;
669        
670        public boolean[] optionals()
671        { return new boolean[] { false, }; }
672        
673        /** <CODE>[No Description Provided by Google]</CODE> */
674        public final Target.TargetInfo targetInfo;
675        
676        /**
677         * Constructor
678         *
679         * @param targetInfo -
680         */
681        public targetCreated(Target.TargetInfo targetInfo)
682        {
683            super("Target", "targetCreated", 1);
684            
685            // Exception-Check(s) to ensure that if any parameters which are not declared as
686            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
687            
688            if (targetInfo == null) BRDPC.throwNPE("targetInfo");
689            
690            this.targetInfo  = targetInfo;
691        }
692        
693        /**
694         * JSON Object Constructor
695         * @param jo A Json-Object having data about an instance of {@code 'targetCreated'}.
696         */
697        public targetCreated (JsonObject jo)
698        {
699            super("Target", "targetCreated", 1);
700        
701            this.targetInfo  = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true);
702        }
703        
704        
705        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
706        public boolean equals(Object other)
707        {
708            if (other == null)                       return false;
709            if (other.getClass() != this.getClass()) return false;
710        
711            targetCreated o = (targetCreated) other;
712        
713            return
714                    Objects.equals(this.targetInfo, o.targetInfo);
715        }
716        
717        /** Generates a Hash-Code for {@code 'this'} instance */
718        public int hashCode()
719        {
720            return
721                    this.targetInfo.hashCode();
722        }
723    }
724    
725    /** Issued when a target is destroyed. */
726    public static class targetDestroyed
727        extends BrowserEvent
728        implements java.io.Serializable
729    {
730        /** For Object Serialization.  java.io.Serializable */
731        protected static final long serialVersionUID = 1;
732        
733        public boolean[] optionals()
734        { return new boolean[] { false, }; }
735        
736        /** <CODE>[No Description Provided by Google]</CODE> */
737        public final String targetId;
738        
739        /**
740         * Constructor
741         *
742         * @param targetId -
743         */
744        public targetDestroyed(String targetId)
745        {
746            super("Target", "targetDestroyed", 1);
747            
748            // Exception-Check(s) to ensure that if any parameters which are not declared as
749            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
750            
751            if (targetId == null) BRDPC.throwNPE("targetId");
752            
753            this.targetId  = targetId;
754        }
755        
756        /**
757         * JSON Object Constructor
758         * @param jo A Json-Object having data about an instance of {@code 'targetDestroyed'}.
759         */
760        public targetDestroyed (JsonObject jo)
761        {
762            super("Target", "targetDestroyed", 1);
763        
764            this.targetId  = ReadJSON.getString(jo, "targetId", false, true);
765        }
766        
767        
768        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
769        public boolean equals(Object other)
770        {
771            if (other == null)                       return false;
772            if (other.getClass() != this.getClass()) return false;
773        
774            targetDestroyed o = (targetDestroyed) other;
775        
776            return
777                    Objects.equals(this.targetId, o.targetId);
778        }
779        
780        /** Generates a Hash-Code for {@code 'this'} instance */
781        public int hashCode()
782        {
783            return
784                    Objects.hashCode(this.targetId);
785        }
786    }
787    
788    /** Issued when a target has crashed. */
789    public static class targetCrashed
790        extends BrowserEvent
791        implements java.io.Serializable
792    {
793        /** For Object Serialization.  java.io.Serializable */
794        protected static final long serialVersionUID = 1;
795        
796        public boolean[] optionals()
797        { return new boolean[] { false, false, false, }; }
798        
799        /** <CODE>[No Description Provided by Google]</CODE> */
800        public final String targetId;
801        
802        /** Termination status type. */
803        public final String status;
804        
805        /** Termination error code. */
806        public final int errorCode;
807        
808        /**
809         * Constructor
810         *
811         * @param targetId -
812         * 
813         * @param status Termination status type.
814         * 
815         * @param errorCode Termination error code.
816         */
817        public targetCrashed(String targetId, String status, int errorCode)
818        {
819            super("Target", "targetCrashed", 3);
820            
821            // Exception-Check(s) to ensure that if any parameters which are not declared as
822            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
823            
824            if (targetId == null) BRDPC.throwNPE("targetId");
825            if (status == null)   BRDPC.throwNPE("status");
826            
827            this.targetId   = targetId;
828            this.status     = status;
829            this.errorCode  = errorCode;
830        }
831        
832        /**
833         * JSON Object Constructor
834         * @param jo A Json-Object having data about an instance of {@code 'targetCrashed'}.
835         */
836        public targetCrashed (JsonObject jo)
837        {
838            super("Target", "targetCrashed", 3);
839        
840            this.targetId   = ReadJSON.getString(jo, "targetId", false, true);
841            this.status     = ReadJSON.getString(jo, "status", false, true);
842            this.errorCode  = ReadPrimJSON.getInt(jo, "errorCode");
843        }
844        
845        
846        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
847        public boolean equals(Object other)
848        {
849            if (other == null)                       return false;
850            if (other.getClass() != this.getClass()) return false;
851        
852            targetCrashed o = (targetCrashed) other;
853        
854            return
855                    Objects.equals(this.targetId, o.targetId)
856                &&  Objects.equals(this.status, o.status)
857                &&  (this.errorCode == o.errorCode);
858        }
859        
860        /** Generates a Hash-Code for {@code 'this'} instance */
861        public int hashCode()
862        {
863            return
864                    Objects.hashCode(this.targetId)
865                +   Objects.hashCode(this.status)
866                +   this.errorCode;
867        }
868    }
869    
870    /**
871     * Issued when some information about a target has changed. This only happens between
872     * <CODE>targetCreated</CODE> and <CODE>targetDestroyed</CODE>.
873     */
874    public static class targetInfoChanged
875        extends BrowserEvent
876        implements java.io.Serializable
877    {
878        /** For Object Serialization.  java.io.Serializable */
879        protected static final long serialVersionUID = 1;
880        
881        public boolean[] optionals()
882        { return new boolean[] { false, }; }
883        
884        /** <CODE>[No Description Provided by Google]</CODE> */
885        public final Target.TargetInfo targetInfo;
886        
887        /**
888         * Constructor
889         *
890         * @param targetInfo -
891         */
892        public targetInfoChanged(Target.TargetInfo targetInfo)
893        {
894            super("Target", "targetInfoChanged", 1);
895            
896            // Exception-Check(s) to ensure that if any parameters which are not declared as
897            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
898            
899            if (targetInfo == null) BRDPC.throwNPE("targetInfo");
900            
901            this.targetInfo  = targetInfo;
902        }
903        
904        /**
905         * JSON Object Constructor
906         * @param jo A Json-Object having data about an instance of {@code 'targetInfoChanged'}.
907         */
908        public targetInfoChanged (JsonObject jo)
909        {
910            super("Target", "targetInfoChanged", 1);
911        
912            this.targetInfo  = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true);
913        }
914        
915        
916        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
917        public boolean equals(Object other)
918        {
919            if (other == null)                       return false;
920            if (other.getClass() != this.getClass()) return false;
921        
922            targetInfoChanged o = (targetInfoChanged) other;
923        
924            return
925                    Objects.equals(this.targetInfo, o.targetInfo);
926        }
927        
928        /** Generates a Hash-Code for {@code 'this'} instance */
929        public int hashCode()
930        {
931            return
932                    this.targetInfo.hashCode();
933        }
934    }
935    
936    
937    // Counter for keeping the WebSocket Request ID's distinct.
938    private static int counter = 1;
939    
940    /**
941     * Activates (focuses) the target.
942     * 
943     * @param targetId -
944     * 
945     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
946     * {@link Ret0}&gt;</CODE>
947     *
948     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
949     * browser receives the invocation-request.
950     *
951     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
952     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
953     * {@code >} to ensure the Browser Function has run to completion.
954     */
955    public static Script<String, JsonObject, Ret0> activateTarget(String targetId)
956    {
957        // Exception-Check(s) to ensure that if any parameters which are not declared as
958        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
959        
960        if (targetId == null) BRDPC.throwNPE("targetId");
961        
962        final int       webSocketID = 39000000 + counter++;
963        final boolean[] optionals   = { false, };
964        
965        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
966        String requestJSON = WriteJSON.get(
967            parameterTypes.get("activateTarget"),
968            parameterNames.get("activateTarget"),
969            optionals, webSocketID,
970            "Target.activateTarget",
971            targetId
972        );
973        
974        // This Remote Command does not have a Return-Value.
975        return new Script<>
976            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
977    }
978    
979    /**
980     * Attaches to the target with given id.
981     * 
982     * @param targetId -
983     * 
984     * @param flatten 
985     * Enables "flat" access to the session via specifying sessionId attribute in the commands.
986     * We plan to make this the default, deprecate non-flattened mode,
987     * and eventually retire it. See crbug.com/991325.
988     * <BR /><B>OPTIONAL</B>
989     * 
990     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
991     * String&gt;</CODE>
992     * 
993     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
994     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
995     * String&gt;</CODE> will be returned.
996     *
997     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
998     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
999      * may be retrieved.</I>
1000     *
1001     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1002     * <BR /><BR /><UL CLASS=JDUL>
1003     * <LI><CODE>String (<B>sessionId</B></CODE>)
1004     *     <BR />Id assigned to the session.
1005     * </LI>
1006     * </UL> */
1007    public static Script<String, JsonObject, String> attachToTarget
1008        (String targetId, Boolean flatten)
1009    {
1010        // Exception-Check(s) to ensure that if any parameters which are not declared as
1011        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1012        
1013        if (targetId == null) BRDPC.throwNPE("targetId");
1014        
1015        final int       webSocketID = 39001000 + counter++;
1016        final boolean[] optionals   = { false, true, };
1017        
1018        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1019        String requestJSON = WriteJSON.get(
1020            parameterTypes.get("attachToTarget"),
1021            parameterNames.get("attachToTarget"),
1022            optionals, webSocketID,
1023            "Target.attachToTarget",
1024            targetId, flatten
1025        );
1026        
1027        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1028        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1029            ReadJSON.getString(jo, "sessionId", false, true);
1030        
1031        // Pass the 'defaultSender' to Script-Constructor
1032        // The sender that is used can be changed before executing script.
1033        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1034    }
1035    
1036    /**
1037     * Attaches to the browser target, only uses flat sessionId mode.
1038     * <BR /><B>EXPERIMENTAL</B>
1039     * 
1040     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1041     * String&gt;</CODE>
1042     * 
1043     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1044     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1045     * String&gt;</CODE> will be returned.
1046     *
1047     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1048     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1049      * may be retrieved.</I>
1050     *
1051     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1052     * <BR /><BR /><UL CLASS=JDUL>
1053     * <LI><CODE>String (<B>sessionId</B></CODE>)
1054     *     <BR />Id assigned to the session.
1055     * </LI>
1056     * </UL> */
1057    public static Script<String, JsonObject, String> attachToBrowserTarget()
1058    {
1059        final int          webSocketID = 39002000 + counter++;
1060        final boolean[]    optionals   = new boolean[0];
1061        
1062        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1063        String requestJSON = WriteJSON.get(
1064            parameterTypes.get("attachToBrowserTarget"),
1065            parameterNames.get("attachToBrowserTarget"),
1066            optionals, webSocketID,
1067            "Target.attachToBrowserTarget"
1068        );
1069        
1070        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1071        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1072            ReadJSON.getString(jo, "sessionId", false, true);
1073        
1074        // Pass the 'defaultSender' to Script-Constructor
1075        // The sender that is used can be changed before executing script.
1076        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1077    }
1078    
1079    /**
1080     * Closes the target. If the target is a page that gets closed too.
1081     * 
1082     * @param targetId -
1083     * 
1084     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1085     * Boolean&gt;</CODE>
1086     * 
1087     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1088     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1089     * Boolean&gt;</CODE> will be returned.
1090     *
1091     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1092     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1093      * may be retrieved.</I>
1094     *
1095     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1096     * <BR /><BR /><UL CLASS=JDUL>
1097     * <LI><CODE>Boolean (<B>success</B></CODE>)
1098     *     <BR />Always set to true. If an error occurs, the response indicates protocol error.
1099     * </LI>
1100     * </UL> */
1101    public static Script<String, JsonObject, Boolean> closeTarget(String targetId)
1102    {
1103        // Exception-Check(s) to ensure that if any parameters which are not declared as
1104        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1105        
1106        if (targetId == null) BRDPC.throwNPE("targetId");
1107        
1108        final int       webSocketID = 39003000 + counter++;
1109        final boolean[] optionals   = { false, };
1110        
1111        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1112        String requestJSON = WriteJSON.get(
1113            parameterTypes.get("closeTarget"),
1114            parameterNames.get("closeTarget"),
1115            optionals, webSocketID,
1116            "Target.closeTarget",
1117            targetId
1118        );
1119        
1120        // 'JSON Binding' ... Converts Browser Response-JSON to 'Boolean'
1121        Function<JsonObject, Boolean> responseProcessor = (JsonObject jo) ->
1122            ReadPrimJSON.getBoolean(jo, "success");
1123        
1124        // Pass the 'defaultSender' to Script-Constructor
1125        // The sender that is used can be changed before executing script.
1126        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1127    }
1128    
1129    /**
1130     * Inject object to the target's main frame that provides a communication
1131     * channel with browser target.
1132     * 
1133     * Injected object will be available as <CODE>window[bindingName]</CODE>.
1134     * 
1135     * The object has the follwing API:
1136     * - <CODE>binding.send(json)</CODE> - a method to send messages over the remote debugging protocol
1137     * - <CODE>binding.onmessage = json =&gt; handleMessage(json)</CODE> - a callback that will be called for the protocol notifications and command responses.
1138     * <BR /><B>EXPERIMENTAL</B>
1139     * 
1140     * @param targetId -
1141     * 
1142     * @param bindingName Binding name, 'cdp' if not specified.
1143     * <BR /><B>OPTIONAL</B>
1144     * 
1145     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1146     * {@link Ret0}&gt;</CODE>
1147     *
1148     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1149     * browser receives the invocation-request.
1150     *
1151     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1152     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1153     * {@code >} to ensure the Browser Function has run to completion.
1154     */
1155    public static Script<String, JsonObject, Ret0> exposeDevToolsProtocol
1156        (String targetId, String bindingName)
1157    {
1158        // Exception-Check(s) to ensure that if any parameters which are not declared as
1159        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1160        
1161        if (targetId == null) BRDPC.throwNPE("targetId");
1162        
1163        final int       webSocketID = 39004000 + counter++;
1164        final boolean[] optionals   = { false, true, };
1165        
1166        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1167        String requestJSON = WriteJSON.get(
1168            parameterTypes.get("exposeDevToolsProtocol"),
1169            parameterNames.get("exposeDevToolsProtocol"),
1170            optionals, webSocketID,
1171            "Target.exposeDevToolsProtocol",
1172            targetId, bindingName
1173        );
1174        
1175        // This Remote Command does not have a Return-Value.
1176        return new Script<>
1177            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1178    }
1179    
1180    /**
1181     * Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than
1182     * one.
1183     * <BR /><B>EXPERIMENTAL</B>
1184     * 
1185     * @param disposeOnDetach If specified, disposes this context when debugging session disconnects.
1186     * <BR /><B>OPTIONAL</B>
1187     * 
1188     * @param proxyServer Proxy server, similar to the one passed to --proxy-server
1189     * <BR /><B>OPTIONAL</B>
1190     * 
1191     * @param proxyBypassList Proxy bypass list, similar to the one passed to --proxy-bypass-list
1192     * <BR /><B>OPTIONAL</B>
1193     * 
1194     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1195     * String&gt;</CODE>
1196     * 
1197     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1198     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1199     * String&gt;</CODE> will be returned.
1200     *
1201     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1202     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1203      * may be retrieved.</I>
1204     *
1205     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1206     * <BR /><BR /><UL CLASS=JDUL>
1207     * <LI><CODE>String (<B>browserContextId</B></CODE>)
1208     *     <BR />The id of the context created.
1209     * </LI>
1210     * </UL> */
1211    public static Script<String, JsonObject, String> createBrowserContext
1212        (Boolean disposeOnDetach, String proxyServer, String proxyBypassList)
1213    {
1214        final int       webSocketID = 39005000 + counter++;
1215        final boolean[] optionals   = { true, true, true, };
1216        
1217        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1218        String requestJSON = WriteJSON.get(
1219            parameterTypes.get("createBrowserContext"),
1220            parameterNames.get("createBrowserContext"),
1221            optionals, webSocketID,
1222            "Target.createBrowserContext",
1223            disposeOnDetach, proxyServer, proxyBypassList
1224        );
1225        
1226        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1227        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1228            ReadJSON.getString(jo, "browserContextId", false, true);
1229        
1230        // Pass the 'defaultSender' to Script-Constructor
1231        // The sender that is used can be changed before executing script.
1232        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1233    }
1234    
1235    /**
1236     * Returns all browser contexts created with <CODE>Target.createBrowserContext</CODE> method.
1237     * <BR /><B>EXPERIMENTAL</B>
1238     * 
1239     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1240     * String[]&gt;</CODE>
1241     * 
1242     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1243     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1244     * String[]&gt;</CODE> will be returned.
1245     *
1246     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1247     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1248      * may be retrieved.</I>
1249     *
1250     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1251     * <BR /><BR /><UL CLASS=JDUL>
1252     * <LI><CODE>String[] (<B>browserContextIds</B></CODE>)
1253     *     <BR />An array of browser context ids.
1254     * </LI>
1255     * </UL> */
1256    public static Script<String, JsonObject, String[]> getBrowserContexts()
1257    {
1258        final int          webSocketID = 39006000 + counter++;
1259        final boolean[]    optionals   = new boolean[0];
1260        
1261        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1262        String requestJSON = WriteJSON.get(
1263            parameterTypes.get("getBrowserContexts"),
1264            parameterNames.get("getBrowserContexts"),
1265            optionals, webSocketID,
1266            "Target.getBrowserContexts"
1267        );
1268        
1269        // 'JSON Binding' ... Converts Browser Response-JSON to 'String[]'
1270        Function<JsonObject, String[]> responseProcessor = (JsonObject jo) ->
1271            (jo.getJsonArray("browserContextIds") == null)
1272                ? null
1273                : ReadArrJSON.DimN.strArr(jo.getJsonArray("browserContextIds"), null, 0, String[].class);
1274        
1275        // Pass the 'defaultSender' to Script-Constructor
1276        // The sender that is used can be changed before executing script.
1277        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1278    }
1279    
1280    /**
1281     * Creates a new page.
1282     * 
1283     * @param url The initial URL the page will be navigated to. An empty string indicates about:blank.
1284     * 
1285     * @param width Frame width in DIP (headless chrome only).
1286     * <BR /><B>OPTIONAL</B>
1287     * 
1288     * @param height Frame height in DIP (headless chrome only).
1289     * <BR /><B>OPTIONAL</B>
1290     * 
1291     * @param browserContextId The browser context to create the page in.
1292     * <BR /><B>OPTIONAL</B>
1293     * <BR /><B>EXPERIMENTAL</B>
1294     * 
1295     * @param enableBeginFrameControl 
1296     * Whether BeginFrames for this target will be controlled via DevTools (headless chrome only,
1297     * not supported on MacOS yet, false by default).
1298     * <BR /><B>OPTIONAL</B>
1299     * <BR /><B>EXPERIMENTAL</B>
1300     * 
1301     * @param newWindow Whether to create a new Window or Tab (chrome-only, false by default).
1302     * <BR /><B>OPTIONAL</B>
1303     * 
1304     * @param background 
1305     * Whether to create the target in background or foreground (chrome-only,
1306     * false by default).
1307     * <BR /><B>OPTIONAL</B>
1308     * 
1309     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1310     * String&gt;</CODE>
1311     * 
1312     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1313     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1314     * String&gt;</CODE> will be returned.
1315     *
1316     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1317     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1318      * may be retrieved.</I>
1319     *
1320     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1321     * <BR /><BR /><UL CLASS=JDUL>
1322     * <LI><CODE>String (<B>targetId</B></CODE>)
1323     *     <BR />The id of the page opened.
1324     * </LI>
1325     * </UL> */
1326    public static Script<String, JsonObject, String> createTarget(
1327            String url, Integer width, Integer height, String browserContextId, 
1328            Boolean enableBeginFrameControl, Boolean newWindow, Boolean background
1329        )
1330    {
1331        // Exception-Check(s) to ensure that if any parameters which are not declared as
1332        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1333        
1334        if (url == null) BRDPC.throwNPE("url");
1335        
1336        final int       webSocketID = 39007000 + counter++;
1337        final boolean[] optionals   = { false, true, true, true, true, true, true, };
1338        
1339        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1340        String requestJSON = WriteJSON.get(
1341            parameterTypes.get("createTarget"),
1342            parameterNames.get("createTarget"),
1343            optionals, webSocketID,
1344            "Target.createTarget",
1345            url, width, height, browserContextId, enableBeginFrameControl, newWindow, background
1346        );
1347        
1348        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1349        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1350            ReadJSON.getString(jo, "targetId", false, true);
1351        
1352        // Pass the 'defaultSender' to Script-Constructor
1353        // The sender that is used can be changed before executing script.
1354        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1355    }
1356    
1357    /**
1358     * Detaches session with given id.
1359     * 
1360     * @param sessionId Session to detach.
1361     * <BR /><B>OPTIONAL</B>
1362     * 
1363     * @param targetId Deprecated.
1364     * <BR /><B>OPTIONAL</B>
1365     * <BR /><B>DEPRECATED</B>
1366     * 
1367     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1368     * {@link Ret0}&gt;</CODE>
1369     *
1370     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1371     * browser receives the invocation-request.
1372     *
1373     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1374     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1375     * {@code >} to ensure the Browser Function has run to completion.
1376     */
1377    public static Script<String, JsonObject, Ret0> detachFromTarget
1378        (String sessionId, String targetId)
1379    {
1380        final int       webSocketID = 39008000 + counter++;
1381        final boolean[] optionals   = { true, true, };
1382        
1383        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1384        String requestJSON = WriteJSON.get(
1385            parameterTypes.get("detachFromTarget"),
1386            parameterNames.get("detachFromTarget"),
1387            optionals, webSocketID,
1388            "Target.detachFromTarget",
1389            sessionId, targetId
1390        );
1391        
1392        // This Remote Command does not have a Return-Value.
1393        return new Script<>
1394            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1395    }
1396    
1397    /**
1398     * Deletes a BrowserContext. All the belonging pages will be closed without calling their
1399     * beforeunload hooks.
1400     * <BR /><B>EXPERIMENTAL</B>
1401     * 
1402     * @param browserContextId -
1403     * 
1404     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1405     * {@link Ret0}&gt;</CODE>
1406     *
1407     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1408     * browser receives the invocation-request.
1409     *
1410     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1411     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1412     * {@code >} to ensure the Browser Function has run to completion.
1413     */
1414    public static Script<String, JsonObject, Ret0> disposeBrowserContext
1415        (String browserContextId)
1416    {
1417        // Exception-Check(s) to ensure that if any parameters which are not declared as
1418        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1419        
1420        if (browserContextId == null) BRDPC.throwNPE("browserContextId");
1421        
1422        final int       webSocketID = 39009000 + counter++;
1423        final boolean[] optionals   = { false, };
1424        
1425        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1426        String requestJSON = WriteJSON.get(
1427            parameterTypes.get("disposeBrowserContext"),
1428            parameterNames.get("disposeBrowserContext"),
1429            optionals, webSocketID,
1430            "Target.disposeBrowserContext",
1431            browserContextId
1432        );
1433        
1434        // This Remote Command does not have a Return-Value.
1435        return new Script<>
1436            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1437    }
1438    
1439    /**
1440     * Returns information about a target.
1441     * <BR /><B>EXPERIMENTAL</B>
1442     * 
1443     * @param targetId -
1444     * <BR /><B>OPTIONAL</B>
1445     * 
1446     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1447     * {@link Target.TargetInfo}&gt;</CODE>
1448     * 
1449     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1450     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1451     * {@link Target.TargetInfo}&gt;</CODE> will be returned.
1452     *
1453     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1454     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1455      * may be retrieved.</I>
1456     *
1457     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1458     * <BR /><BR /><UL CLASS=JDUL>
1459     * <LI><CODE>{@link Target.TargetInfo} (<B>targetInfo</B></CODE>)
1460     *     <BR />-
1461     * </LI>
1462     * </UL> */
1463    public static Script<String, JsonObject, Target.TargetInfo> getTargetInfo(String targetId)
1464    {
1465        final int       webSocketID = 39010000 + counter++;
1466        final boolean[] optionals   = { true, };
1467        
1468        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1469        String requestJSON = WriteJSON.get(
1470            parameterTypes.get("getTargetInfo"),
1471            parameterNames.get("getTargetInfo"),
1472            optionals, webSocketID,
1473            "Target.getTargetInfo",
1474            targetId
1475        );
1476        
1477        // 'JSON Binding' ... Converts Browser Response-JSON to 'Target.TargetInfo'
1478        Function<JsonObject, Target.TargetInfo> responseProcessor = (JsonObject jo) ->
1479            ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true);
1480        
1481        // Pass the 'defaultSender' to Script-Constructor
1482        // The sender that is used can be changed before executing script.
1483        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1484    }
1485    
1486    /**
1487     * Retrieves a list of available targets.
1488     * 
1489     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1490     * {@link Target.TargetInfo}[]&gt;</CODE>
1491     * 
1492     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1493     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1494     * {@link Target.TargetInfo}[]&gt;</CODE> will be returned.
1495     *
1496     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1497     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1498      * may be retrieved.</I>
1499     *
1500     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1501     * <BR /><BR /><UL CLASS=JDUL>
1502     * <LI><CODE>{@link Target.TargetInfo}[] (<B>targetInfos</B></CODE>)
1503     *     <BR />The list of targets.
1504     * </LI>
1505     * </UL> */
1506    public static Script<String, JsonObject, Target.TargetInfo[]> getTargets()
1507    {
1508        final int          webSocketID = 39011000 + counter++;
1509        final boolean[]    optionals   = new boolean[0];
1510        
1511        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1512        String requestJSON = WriteJSON.get(
1513            parameterTypes.get("getTargets"),
1514            parameterNames.get("getTargets"),
1515            optionals, webSocketID,
1516            "Target.getTargets"
1517        );
1518        
1519        // 'JSON Binding' ... Converts Browser Response-JSON to 'Target.TargetInfo[]'
1520        Function<JsonObject, Target.TargetInfo[]> responseProcessor = (JsonObject jo) ->
1521            (jo.getJsonArray("targetInfos") == null)
1522                ? null
1523                : ReadArrJSON.DimN.objArr(jo.getJsonArray("targetInfos"), null, 0, Target.TargetInfo[].class);
1524        
1525        // Pass the 'defaultSender' to Script-Constructor
1526        // The sender that is used can be changed before executing script.
1527        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1528    }
1529    
1530    /**
1531     * Sends protocol message over session with given id.
1532     * Consider using flat mode instead; see commands attachToTarget, setAutoAttach,
1533     * and crbug.com/991325.
1534     * <BR /><B>DEPRECATED</B>
1535     * 
1536     * @param message -
1537     * 
1538     * @param sessionId Identifier of the session.
1539     * <BR /><B>OPTIONAL</B>
1540     * 
1541     * @param targetId Deprecated.
1542     * <BR /><B>OPTIONAL</B>
1543     * <BR /><B>DEPRECATED</B>
1544     * 
1545     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1546     * {@link Ret0}&gt;</CODE>
1547     *
1548     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1549     * browser receives the invocation-request.
1550     *
1551     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1552     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1553     * {@code >} to ensure the Browser Function has run to completion.
1554     */
1555    public static Script<String, JsonObject, Ret0> sendMessageToTarget
1556        (String message, String sessionId, String targetId)
1557    {
1558        // Exception-Check(s) to ensure that if any parameters which are not declared as
1559        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1560        
1561        if (message == null) BRDPC.throwNPE("message");
1562        
1563        final int       webSocketID = 39012000 + counter++;
1564        final boolean[] optionals   = { false, true, true, };
1565        
1566        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1567        String requestJSON = WriteJSON.get(
1568            parameterTypes.get("sendMessageToTarget"),
1569            parameterNames.get("sendMessageToTarget"),
1570            optionals, webSocketID,
1571            "Target.sendMessageToTarget",
1572            message, sessionId, targetId
1573        );
1574        
1575        // This Remote Command does not have a Return-Value.
1576        return new Script<>
1577            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1578    }
1579    
1580    /**
1581     * Controls whether to automatically attach to new targets which are considered to be related to
1582     * this one. When turned on, attaches to all existing related targets as well. When turned off,
1583     * automatically detaches from all currently attached targets.
1584     * This also clears all targets added by <CODE>autoAttachRelated</CODE> from the list of targets to watch
1585     * for creation of related targets.
1586     * <BR /><B>EXPERIMENTAL</B>
1587     * 
1588     * @param autoAttach Whether to auto-attach to related targets.
1589     * 
1590     * @param waitForDebuggerOnStart 
1591     * Whether to pause new targets when attaching to them. Use <CODE>RunTime.runIfWaitingForDebugger</CODE>
1592     * to run paused targets.
1593     * 
1594     * @param flatten 
1595     * Enables "flat" access to the session via specifying sessionId attribute in the commands.
1596     * We plan to make this the default, deprecate non-flattened mode,
1597     * and eventually retire it. See crbug.com/991325.
1598     * <BR /><B>OPTIONAL</B>
1599     * 
1600     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1601     * {@link Ret0}&gt;</CODE>
1602     *
1603     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1604     * browser receives the invocation-request.
1605     *
1606     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1607     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1608     * {@code >} to ensure the Browser Function has run to completion.
1609     */
1610    public static Script<String, JsonObject, Ret0> setAutoAttach
1611        (boolean autoAttach, boolean waitForDebuggerOnStart, Boolean flatten)
1612    {
1613        final int       webSocketID = 39013000 + counter++;
1614        final boolean[] optionals   = { false, false, true, };
1615        
1616        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1617        String requestJSON = WriteJSON.get(
1618            parameterTypes.get("setAutoAttach"),
1619            parameterNames.get("setAutoAttach"),
1620            optionals, webSocketID,
1621            "Target.setAutoAttach",
1622            autoAttach, waitForDebuggerOnStart, flatten
1623        );
1624        
1625        // This Remote Command does not have a Return-Value.
1626        return new Script<>
1627            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1628    }
1629    
1630    /**
1631     * Adds the specified target to the list of targets that will be monitored for any related target
1632     * creation (such as child frames, child workers and new versions of service worker) and reported
1633     * through <CODE>attachedToTarget</CODE>. The specified target is also auto-attached.
1634     * This cancels the effect of any previous <CODE>setAutoAttach</CODE> and is also cancelled by subsequent
1635     * <CODE>setAutoAttach</CODE>. Only available at the Browser target.
1636     * <BR /><B>EXPERIMENTAL</B>
1637     * 
1638     * @param targetId -
1639     * 
1640     * @param waitForDebuggerOnStart 
1641     * Whether to pause new targets when attaching to them. Use <CODE>RunTime.runIfWaitingForDebugger</CODE>
1642     * to run paused targets.
1643     * 
1644     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1645     * {@link Ret0}&gt;</CODE>
1646     *
1647     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1648     * browser receives the invocation-request.
1649     *
1650     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1651     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1652     * {@code >} to ensure the Browser Function has run to completion.
1653     */
1654    public static Script<String, JsonObject, Ret0> autoAttachRelated
1655        (String targetId, boolean waitForDebuggerOnStart)
1656    {
1657        // Exception-Check(s) to ensure that if any parameters which are not declared as
1658        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1659        
1660        if (targetId == null) BRDPC.throwNPE("targetId");
1661        
1662        final int       webSocketID = 39014000 + counter++;
1663        final boolean[] optionals   = { false, false, };
1664        
1665        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1666        String requestJSON = WriteJSON.get(
1667            parameterTypes.get("autoAttachRelated"),
1668            parameterNames.get("autoAttachRelated"),
1669            optionals, webSocketID,
1670            "Target.autoAttachRelated",
1671            targetId, waitForDebuggerOnStart
1672        );
1673        
1674        // This Remote Command does not have a Return-Value.
1675        return new Script<>
1676            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1677    }
1678    
1679    /**
1680     * Controls whether to discover available targets and notify via
1681     * <CODE>targetCreated/targetInfoChanged/targetDestroyed</CODE> events.
1682     * 
1683     * @param discover Whether to discover available targets.
1684     * 
1685     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1686     * {@link Ret0}&gt;</CODE>
1687     *
1688     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1689     * browser receives the invocation-request.
1690     *
1691     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1692     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1693     * {@code >} to ensure the Browser Function has run to completion.
1694     */
1695    public static Script<String, JsonObject, Ret0> setDiscoverTargets(boolean discover)
1696    {
1697        final int       webSocketID = 39015000 + counter++;
1698        final boolean[] optionals   = { false, };
1699        
1700        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1701        String requestJSON = WriteJSON.get(
1702            parameterTypes.get("setDiscoverTargets"),
1703            parameterNames.get("setDiscoverTargets"),
1704            optionals, webSocketID,
1705            "Target.setDiscoverTargets",
1706            discover
1707        );
1708        
1709        // This Remote Command does not have a Return-Value.
1710        return new Script<>
1711            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1712    }
1713    
1714    /**
1715     * Enables target discovery for the specified locations, when <CODE>setDiscoverTargets</CODE> was set to
1716     * <CODE>true</CODE>.
1717     * <BR /><B>EXPERIMENTAL</B>
1718     * 
1719     * @param locations List of remote locations.
1720     * 
1721     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1722     * {@link Ret0}&gt;</CODE>
1723     *
1724     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1725     * browser receives the invocation-request.
1726     *
1727     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1728     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1729     * {@code >} to ensure the Browser Function has run to completion.
1730     */
1731    public static Script<String, JsonObject, Ret0> setRemoteLocations
1732        (Target.RemoteLocation[] locations)
1733    {
1734        // Exception-Check(s) to ensure that if any parameters which are not declared as
1735        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1736        
1737        if (locations == null) BRDPC.throwNPE("locations");
1738        
1739        final int       webSocketID = 39016000 + counter++;
1740        final boolean[] optionals   = { false, };
1741        
1742        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1743        String requestJSON = WriteJSON.get(
1744            parameterTypes.get("setRemoteLocations"),
1745            parameterNames.get("setRemoteLocations"),
1746            optionals, webSocketID,
1747            "Target.setRemoteLocations",
1748            (Object) locations
1749        );
1750        
1751        // This Remote Command does not have a Return-Value.
1752        return new Script<>
1753            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1754    }
1755    
1756}