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