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>DOM debugging allows setting breakpoints on particular DOM operations and events. JavaScript
024 * execution will stop on these operations as if there was a regular breakpoint set.</B></SPAN>
025 * 
026 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
027 */
028@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
029@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
030public class DOMDebugger
031{
032    // ********************************************************************************************
033    // ********************************************************************************************
034    // Class Header Stuff
035    // ********************************************************************************************
036    // ********************************************************************************************
037
038
039    // No Pubic Constructors
040    private DOMDebugger () { }
041
042    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
043    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
044    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
045    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
046
047    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
048    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
049    // offically, two empty-vectors.  One for String's, and the other for Classes.
050
051    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
052    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
053
054    static
055    {
056        for (Method m : DOMDebugger.class.getMethods())
057        {
058            // This doesn't work!  The parameter names are all "arg0" ... "argN"
059            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
060            //
061            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
062
063            Vector<Class<?>> parameterTypesList = new Vector<>();
064        
065            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
066
067            parameterTypes.put(
068                m.getName(),
069                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
070            );
071        }
072    }
073
074    static
075    {
076        Vector<String> v = null;
077
078        v = new Vector<String>(3);
079        parameterNames.put("getEventListeners", v);
080        Collections.addAll(v, new String[]
081        { "objectId", "depth", "pierce", });
082
083        v = new Vector<String>(2);
084        parameterNames.put("removeDOMBreakpoint", v);
085        Collections.addAll(v, new String[]
086        { "nodeId", "type", });
087
088        v = new Vector<String>(2);
089        parameterNames.put("removeEventListenerBreakpoint", v);
090        Collections.addAll(v, new String[]
091        { "eventName", "targetName", });
092
093        v = new Vector<String>(1);
094        parameterNames.put("removeInstrumentationBreakpoint", v);
095        Collections.addAll(v, new String[]
096        { "eventName", });
097
098        v = new Vector<String>(1);
099        parameterNames.put("removeXHRBreakpoint", v);
100        Collections.addAll(v, new String[]
101        { "url", });
102
103        v = new Vector<String>(1);
104        parameterNames.put("setBreakOnCSPViolation", v);
105        Collections.addAll(v, new String[]
106        { "violationTypes", });
107
108        v = new Vector<String>(2);
109        parameterNames.put("setDOMBreakpoint", v);
110        Collections.addAll(v, new String[]
111        { "nodeId", "type", });
112
113        v = new Vector<String>(2);
114        parameterNames.put("setEventListenerBreakpoint", v);
115        Collections.addAll(v, new String[]
116        { "eventName", "targetName", });
117
118        v = new Vector<String>(1);
119        parameterNames.put("setInstrumentationBreakpoint", v);
120        Collections.addAll(v, new String[]
121        { "eventName", });
122
123        v = new Vector<String>(1);
124        parameterNames.put("setXHRBreakpoint", v);
125        Collections.addAll(v, new String[]
126        { "url", });
127    }
128
129
130    // ********************************************************************************************
131    // ********************************************************************************************
132    // Types - Static Inner Classes
133    // ********************************************************************************************
134    // ********************************************************************************************
135
136    /** DOM breakpoint type. */
137    public static final String[] DOMBreakpointType =
138    { "subtree-modified", "attribute-modified", "node-removed", };
139    
140    /**
141     * CSP Violation type.
142     * <BR />
143     * <BR /><B>EXPERIMENTAL</B>
144     */
145    public static final String[] CSPViolationType =
146    { "trustedtype-sink-violation", "trustedtype-policy-violation", };
147    
148    /** Object event listener. */
149    public static class EventListener
150        extends BaseType
151        implements java.io.Serializable
152    {
153        /** For Object Serialization.  java.io.Serializable */
154        protected static final long serialVersionUID = 1;
155        
156        public boolean[] optionals()
157        { return new boolean[] { false, false, false, false, false, false, false, true, true, true, }; }
158        
159        /** <CODE>EventListener</CODE>'s type. */
160        public final String type;
161        
162        /** <CODE>EventListener</CODE>'s useCapture. */
163        public final boolean useCapture;
164        
165        /** <CODE>EventListener</CODE>'s passive flag. */
166        public final boolean passive;
167        
168        /** <CODE>EventListener</CODE>'s once flag. */
169        public final boolean once;
170        
171        /** Script id of the handler code. */
172        public final String scriptId;
173        
174        /** Line number in the script (0-based). */
175        public final int lineNumber;
176        
177        /** Column number in the script (0-based). */
178        public final int columnNumber;
179        
180        /**
181         * Event handler function value.
182         * <BR />
183         * <BR /><B>OPTIONAL</B>
184         */
185        public final RunTime.RemoteObject handler;
186        
187        /**
188         * Event original handler function value.
189         * <BR />
190         * <BR /><B>OPTIONAL</B>
191         */
192        public final RunTime.RemoteObject originalHandler;
193        
194        /**
195         * Node the listener is added to (if any).
196         * <BR />
197         * <BR /><B>OPTIONAL</B>
198         */
199        public final Integer backendNodeId;
200        
201        /**
202         * Constructor
203         *
204         * @param type <CODE>EventListener</CODE>'s type.
205         * 
206         * @param useCapture <CODE>EventListener</CODE>'s useCapture.
207         * 
208         * @param passive <CODE>EventListener</CODE>'s passive flag.
209         * 
210         * @param once <CODE>EventListener</CODE>'s once flag.
211         * 
212         * @param scriptId Script id of the handler code.
213         * 
214         * @param lineNumber Line number in the script (0-based).
215         * 
216         * @param columnNumber Column number in the script (0-based).
217         * 
218         * @param handler Event handler function value.
219         * <BR /><B>OPTIONAL</B>
220         * 
221         * @param originalHandler Event original handler function value.
222         * <BR /><B>OPTIONAL</B>
223         * 
224         * @param backendNodeId Node the listener is added to (if any).
225         * <BR /><B>OPTIONAL</B>
226         */
227        public EventListener(
228                String type, boolean useCapture, boolean passive, boolean once, String scriptId, 
229                int lineNumber, int columnNumber, RunTime.RemoteObject handler, 
230                RunTime.RemoteObject originalHandler, Integer backendNodeId
231            )
232        {
233            // Exception-Check(s) to ensure that if any parameters which are not declared as
234            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
235            
236            if (type == null)     BRDPC.throwNPE("type");
237            if (scriptId == null) BRDPC.throwNPE("scriptId");
238            
239            this.type             = type;
240            this.useCapture       = useCapture;
241            this.passive          = passive;
242            this.once             = once;
243            this.scriptId         = scriptId;
244            this.lineNumber       = lineNumber;
245            this.columnNumber     = columnNumber;
246            this.handler          = handler;
247            this.originalHandler  = originalHandler;
248            this.backendNodeId    = backendNodeId;
249        }
250        
251        /**
252         * JSON Object Constructor
253         * @param jo A Json-Object having data about an instance of {@code 'EventListener'}.
254         */
255        public EventListener (JsonObject jo)
256        {
257            this.type             = ReadJSON.getString(jo, "type", false, true);
258            this.useCapture       = ReadPrimJSON.getBoolean(jo, "useCapture");
259            this.passive          = ReadPrimJSON.getBoolean(jo, "passive");
260            this.once             = ReadPrimJSON.getBoolean(jo, "once");
261            this.scriptId         = ReadJSON.getString(jo, "scriptId", false, true);
262            this.lineNumber       = ReadPrimJSON.getInt(jo, "lineNumber");
263            this.columnNumber     = ReadPrimJSON.getInt(jo, "columnNumber");
264            this.handler          = ReadJSON.getObject(jo, "handler", RunTime.RemoteObject.class, true, false);
265            this.originalHandler  = ReadJSON.getObject(jo, "originalHandler", RunTime.RemoteObject.class, true, false);
266            this.backendNodeId    = ReadBoxedJSON.getInteger(jo, "backendNodeId", true);
267        }
268        
269        
270        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
271        public boolean equals(Object other)
272        {
273            if (other == null)                       return false;
274            if (other.getClass() != this.getClass()) return false;
275        
276            EventListener o = (EventListener) other;
277        
278            return
279                    Objects.equals(this.type, o.type)
280                &&  (this.useCapture == o.useCapture)
281                &&  (this.passive == o.passive)
282                &&  (this.once == o.once)
283                &&  Objects.equals(this.scriptId, o.scriptId)
284                &&  (this.lineNumber == o.lineNumber)
285                &&  (this.columnNumber == o.columnNumber)
286                &&  Objects.equals(this.handler, o.handler)
287                &&  Objects.equals(this.originalHandler, o.originalHandler)
288                &&  Objects.equals(this.backendNodeId, o.backendNodeId);
289        }
290        
291        /** Generates a Hash-Code for {@code 'this'} instance */
292        public int hashCode()
293        {
294            return
295                    Objects.hashCode(this.type)
296                +   (this.useCapture ? 1 : 0)
297                +   (this.passive ? 1 : 0)
298                +   (this.once ? 1 : 0)
299                +   Objects.hashCode(this.scriptId)
300                +   this.lineNumber
301                +   this.columnNumber
302                +   this.handler.hashCode()
303                +   this.originalHandler.hashCode()
304                +   Objects.hashCode(this.backendNodeId);
305        }
306    }
307    
308    
309    // Counter for keeping the WebSocket Request ID's distinct.
310    private static int counter = 1;
311    
312    /**
313     * Returns event listeners of the given object.
314     * 
315     * @param objectId Identifier of the object to return listeners for.
316     * 
317     * @param depth 
318     * The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the
319     * entire subtree or provide an integer larger than 0.
320     * <BR /><B>OPTIONAL</B>
321     * 
322     * @param pierce 
323     * Whether or not iframes and shadow roots should be traversed when returning the subtree
324     * (default is false). Reports listeners for all contexts if pierce is enabled.
325     * <BR /><B>OPTIONAL</B>
326     * 
327     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
328     * {@link DOMDebugger.EventListener}[]&gt;</CODE>
329     * 
330     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
331     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
332     * {@link DOMDebugger.EventListener}[]&gt;</CODE> will be returned.
333     *
334     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
335     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
336      * may be retrieved.</I>
337     *
338     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
339     * <BR /><BR /><UL CLASS=JDUL>
340     * <LI><CODE>{@link DOMDebugger.EventListener}[] (<B>listeners</B></CODE>)
341     *     <BR />Array of relevant listeners.
342     * </LI>
343     * </UL> */
344    public static Script<String, JsonObject, DOMDebugger.EventListener[]> getEventListeners
345        (String objectId, Integer depth, Boolean pierce)
346    {
347        // Exception-Check(s) to ensure that if any parameters which are not declared as
348        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
349        
350        if (objectId == null) BRDPC.throwNPE("objectId");
351        
352        final int       webSocketID = 16000000 + counter++;
353        final boolean[] optionals   = { false, true, true, };
354        
355        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
356        String requestJSON = WriteJSON.get(
357            parameterTypes.get("getEventListeners"),
358            parameterNames.get("getEventListeners"),
359            optionals, webSocketID,
360            "DOMDebugger.getEventListeners",
361            objectId, depth, pierce
362        );
363        
364        // 'JSON Binding' ... Converts Browser Response-JSON to 'DOMDebugger.EventListener[]'
365        Function<JsonObject, DOMDebugger.EventListener[]> responseProcessor = (JsonObject jo) ->
366            (jo.getJsonArray("listeners") == null)
367                ? null
368                : ReadArrJSON.DimN.objArr(jo.getJsonArray("listeners"), null, 0, DOMDebugger.EventListener[].class);
369        
370        // Pass the 'defaultSender' to Script-Constructor
371        // The sender that is used can be changed before executing script.
372        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
373    }
374    
375    /**
376     * Removes DOM breakpoint that was set using <CODE>setDOMBreakpoint</CODE>.
377     * 
378     * @param nodeId Identifier of the node to remove breakpoint from.
379     * 
380     * @param type Type of the breakpoint to remove.
381     * 
382     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
383     * {@link Ret0}&gt;</CODE>
384     *
385     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
386     * browser receives the invocation-request.
387     *
388     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
389     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
390     * {@code >} to ensure the Browser Function has run to completion.
391     */
392    public static Script<String, JsonObject, Ret0> removeDOMBreakpoint(int nodeId, String type)
393    {
394        // Exception-Check(s) to ensure that if any parameters which are not declared as
395        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
396        
397        if (type == null) BRDPC.throwNPE("type");
398        
399        // Exception-Check(s) to ensure that if any parameters which must adhere to a
400        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
401        
402        BRDPC.checkIAE("type", type, "DOMDebugger.DOMBreakpointType", DOMDebugger.DOMBreakpointType);
403        
404        final int       webSocketID = 16001000 + counter++;
405        final boolean[] optionals   = { false, false, };
406        
407        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
408        String requestJSON = WriteJSON.get(
409            parameterTypes.get("removeDOMBreakpoint"),
410            parameterNames.get("removeDOMBreakpoint"),
411            optionals, webSocketID,
412            "DOMDebugger.removeDOMBreakpoint",
413            nodeId, type
414        );
415        
416        // This Remote Command does not have a Return-Value.
417        return new Script<>
418            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
419    }
420    
421    /**
422     * Removes breakpoint on particular DOM event.
423     * 
424     * @param eventName Event name.
425     * 
426     * @param targetName EventTarget interface name.
427     * <BR /><B>OPTIONAL</B>
428     * <BR /><B>EXPERIMENTAL</B>
429     * 
430     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
431     * {@link Ret0}&gt;</CODE>
432     *
433     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
434     * browser receives the invocation-request.
435     *
436     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
437     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
438     * {@code >} to ensure the Browser Function has run to completion.
439     */
440    public static Script<String, JsonObject, Ret0> removeEventListenerBreakpoint
441        (String eventName, String targetName)
442    {
443        // Exception-Check(s) to ensure that if any parameters which are not declared as
444        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
445        
446        if (eventName == null) BRDPC.throwNPE("eventName");
447        
448        final int       webSocketID = 16002000 + counter++;
449        final boolean[] optionals   = { false, true, };
450        
451        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
452        String requestJSON = WriteJSON.get(
453            parameterTypes.get("removeEventListenerBreakpoint"),
454            parameterNames.get("removeEventListenerBreakpoint"),
455            optionals, webSocketID,
456            "DOMDebugger.removeEventListenerBreakpoint",
457            eventName, targetName
458        );
459        
460        // This Remote Command does not have a Return-Value.
461        return new Script<>
462            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
463    }
464    
465    /**
466     * Removes breakpoint on particular native event.
467     * <BR /><B>EXPERIMENTAL</B>
468     * 
469     * @param eventName Instrumentation name to stop on.
470     * 
471     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
472     * {@link Ret0}&gt;</CODE>
473     *
474     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
475     * browser receives the invocation-request.
476     *
477     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
478     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
479     * {@code >} to ensure the Browser Function has run to completion.
480     */
481    public static Script<String, JsonObject, Ret0> removeInstrumentationBreakpoint
482        (String eventName)
483    {
484        // Exception-Check(s) to ensure that if any parameters which are not declared as
485        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
486        
487        if (eventName == null) BRDPC.throwNPE("eventName");
488        
489        final int       webSocketID = 16003000 + counter++;
490        final boolean[] optionals   = { false, };
491        
492        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
493        String requestJSON = WriteJSON.get(
494            parameterTypes.get("removeInstrumentationBreakpoint"),
495            parameterNames.get("removeInstrumentationBreakpoint"),
496            optionals, webSocketID,
497            "DOMDebugger.removeInstrumentationBreakpoint",
498            eventName
499        );
500        
501        // This Remote Command does not have a Return-Value.
502        return new Script<>
503            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
504    }
505    
506    /**
507     * Removes breakpoint from XMLHttpRequest.
508     * 
509     * @param url Resource URL substring.
510     * 
511     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
512     * {@link Ret0}&gt;</CODE>
513     *
514     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
515     * browser receives the invocation-request.
516     *
517     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
518     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
519     * {@code >} to ensure the Browser Function has run to completion.
520     */
521    public static Script<String, JsonObject, Ret0> removeXHRBreakpoint(String url)
522    {
523        // Exception-Check(s) to ensure that if any parameters which are not declared as
524        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
525        
526        if (url == null) BRDPC.throwNPE("url");
527        
528        final int       webSocketID = 16004000 + counter++;
529        final boolean[] optionals   = { false, };
530        
531        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
532        String requestJSON = WriteJSON.get(
533            parameterTypes.get("removeXHRBreakpoint"),
534            parameterNames.get("removeXHRBreakpoint"),
535            optionals, webSocketID,
536            "DOMDebugger.removeXHRBreakpoint",
537            url
538        );
539        
540        // This Remote Command does not have a Return-Value.
541        return new Script<>
542            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
543    }
544    
545    /**
546     * Sets breakpoint on particular CSP violations.
547     * <BR /><B>EXPERIMENTAL</B>
548     * 
549     * @param violationTypes CSP Violations to stop upon.
550     * 
551     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
552     * {@link Ret0}&gt;</CODE>
553     *
554     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
555     * browser receives the invocation-request.
556     *
557     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
558     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
559     * {@code >} to ensure the Browser Function has run to completion.
560     */
561    public static Script<String, JsonObject, Ret0> setBreakOnCSPViolation
562        (String[] violationTypes)
563    {
564        // Exception-Check(s) to ensure that if any parameters which are not declared as
565        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
566        
567        if (violationTypes == null) BRDPC.throwNPE("violationTypes");
568        
569        final int       webSocketID = 16005000 + counter++;
570        final boolean[] optionals   = { false, };
571        
572        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
573        String requestJSON = WriteJSON.get(
574            parameterTypes.get("setBreakOnCSPViolation"),
575            parameterNames.get("setBreakOnCSPViolation"),
576            optionals, webSocketID,
577            "DOMDebugger.setBreakOnCSPViolation",
578            (Object) violationTypes
579        );
580        
581        // This Remote Command does not have a Return-Value.
582        return new Script<>
583            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
584    }
585    
586    /**
587     * Sets breakpoint on particular operation with DOM.
588     * 
589     * @param nodeId Identifier of the node to set breakpoint on.
590     * 
591     * @param type Type of the operation to stop upon.
592     * 
593     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
594     * {@link Ret0}&gt;</CODE>
595     *
596     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
597     * browser receives the invocation-request.
598     *
599     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
600     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
601     * {@code >} to ensure the Browser Function has run to completion.
602     */
603    public static Script<String, JsonObject, Ret0> setDOMBreakpoint(int nodeId, String type)
604    {
605        // Exception-Check(s) to ensure that if any parameters which are not declared as
606        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
607        
608        if (type == null) BRDPC.throwNPE("type");
609        
610        // Exception-Check(s) to ensure that if any parameters which must adhere to a
611        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
612        
613        BRDPC.checkIAE("type", type, "DOMDebugger.DOMBreakpointType", DOMDebugger.DOMBreakpointType);
614        
615        final int       webSocketID = 16006000 + counter++;
616        final boolean[] optionals   = { false, false, };
617        
618        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
619        String requestJSON = WriteJSON.get(
620            parameterTypes.get("setDOMBreakpoint"),
621            parameterNames.get("setDOMBreakpoint"),
622            optionals, webSocketID,
623            "DOMDebugger.setDOMBreakpoint",
624            nodeId, type
625        );
626        
627        // This Remote Command does not have a Return-Value.
628        return new Script<>
629            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
630    }
631    
632    /**
633     * Sets breakpoint on particular DOM event.
634     * 
635     * @param eventName DOM Event name to stop on (any DOM event will do).
636     * 
637     * @param targetName 
638     * EventTarget interface name to stop on. If equal to <CODE>"*"</CODE> or not provided, will stop on any
639     * EventTarget.
640     * <BR /><B>OPTIONAL</B>
641     * <BR /><B>EXPERIMENTAL</B>
642     * 
643     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
644     * {@link Ret0}&gt;</CODE>
645     *
646     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
647     * browser receives the invocation-request.
648     *
649     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
650     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
651     * {@code >} to ensure the Browser Function has run to completion.
652     */
653    public static Script<String, JsonObject, Ret0> setEventListenerBreakpoint
654        (String eventName, String targetName)
655    {
656        // Exception-Check(s) to ensure that if any parameters which are not declared as
657        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
658        
659        if (eventName == null) BRDPC.throwNPE("eventName");
660        
661        final int       webSocketID = 16007000 + counter++;
662        final boolean[] optionals   = { false, true, };
663        
664        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
665        String requestJSON = WriteJSON.get(
666            parameterTypes.get("setEventListenerBreakpoint"),
667            parameterNames.get("setEventListenerBreakpoint"),
668            optionals, webSocketID,
669            "DOMDebugger.setEventListenerBreakpoint",
670            eventName, targetName
671        );
672        
673        // This Remote Command does not have a Return-Value.
674        return new Script<>
675            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
676    }
677    
678    /**
679     * Sets breakpoint on particular native event.
680     * <BR /><B>EXPERIMENTAL</B>
681     * 
682     * @param eventName Instrumentation name to stop on.
683     * 
684     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
685     * {@link Ret0}&gt;</CODE>
686     *
687     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
688     * browser receives the invocation-request.
689     *
690     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
691     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
692     * {@code >} to ensure the Browser Function has run to completion.
693     */
694    public static Script<String, JsonObject, Ret0> setInstrumentationBreakpoint
695        (String eventName)
696    {
697        // Exception-Check(s) to ensure that if any parameters which are not declared as
698        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
699        
700        if (eventName == null) BRDPC.throwNPE("eventName");
701        
702        final int       webSocketID = 16008000 + counter++;
703        final boolean[] optionals   = { false, };
704        
705        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
706        String requestJSON = WriteJSON.get(
707            parameterTypes.get("setInstrumentationBreakpoint"),
708            parameterNames.get("setInstrumentationBreakpoint"),
709            optionals, webSocketID,
710            "DOMDebugger.setInstrumentationBreakpoint",
711            eventName
712        );
713        
714        // This Remote Command does not have a Return-Value.
715        return new Script<>
716            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
717    }
718    
719    /**
720     * Sets breakpoint on XMLHttpRequest.
721     * 
722     * @param url Resource URL substring. All XHRs having this substring in the URL will get stopped upon.
723     * 
724     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
725     * {@link Ret0}&gt;</CODE>
726     *
727     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
728     * browser receives the invocation-request.
729     *
730     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
731     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
732     * {@code >} to ensure the Browser Function has run to completion.
733     */
734    public static Script<String, JsonObject, Ret0> setXHRBreakpoint(String url)
735    {
736        // Exception-Check(s) to ensure that if any parameters which are not declared as
737        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
738        
739        if (url == null) BRDPC.throwNPE("url");
740        
741        final int       webSocketID = 16009000 + counter++;
742        final boolean[] optionals   = { false, };
743        
744        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
745        String requestJSON = WriteJSON.get(
746            parameterTypes.get("setXHRBreakpoint"),
747            parameterNames.get("setXHRBreakpoint"),
748            optionals, webSocketID,
749            "DOMDebugger.setXHRBreakpoint",
750            url
751        );
752        
753        // This Remote Command does not have a Return-Value.
754        return new Script<>
755            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
756    }
757    
758}