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