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>A domain for letting clients substitute browser's network layer with client code.</B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class Fetch
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private Fetch () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : Fetch.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        parameterNames.put("disable", EMPTY_VEC_STR);
078
079        v = new Vector<String>(2);
080        parameterNames.put("enable", v);
081        Collections.addAll(v, new String[]
082        { "patterns", "handleAuthRequests", });
083
084        v = new Vector<String>(2);
085        parameterNames.put("failRequest", v);
086        Collections.addAll(v, new String[]
087        { "requestId", "errorReason", });
088
089        v = new Vector<String>(6);
090        parameterNames.put("fulfillRequest", v);
091        Collections.addAll(v, new String[]
092        { "requestId", "responseCode", "responseHeaders", "binaryResponseHeaders", "body", "responsePhrase", });
093
094        v = new Vector<String>(6);
095        parameterNames.put("continueRequest", v);
096        Collections.addAll(v, new String[]
097        { "requestId", "url", "method", "postData", "headers", "interceptResponse", });
098
099        v = new Vector<String>(2);
100        parameterNames.put("continueWithAuth", v);
101        Collections.addAll(v, new String[]
102        { "requestId", "authChallengeResponse", });
103
104        v = new Vector<String>(5);
105        parameterNames.put("continueResponse", v);
106        Collections.addAll(v, new String[]
107        { "requestId", "responseCode", "responsePhrase", "responseHeaders", "binaryResponseHeaders", });
108
109        v = new Vector<String>(1);
110        parameterNames.put("getResponseBody", v);
111        Collections.addAll(v, new String[]
112        { "requestId", });
113
114        v = new Vector<String>(1);
115        parameterNames.put("takeResponseBodyAsStream", v);
116        Collections.addAll(v, new String[]
117        { "requestId", });
118    }
119
120
121    // ********************************************************************************************
122    // ********************************************************************************************
123    // Types - Static Inner Classes
124    // ********************************************************************************************
125    // ********************************************************************************************
126
127    // public static class RequestId => String
128    
129    /**
130     * Stages of the request to handle. Request will intercept before the request is
131     * sent. Response will intercept after the response is received (but before response
132     * body is received).
133     */
134    public static final String[] RequestStage =
135    { "Request", "Response", };
136    
137    /** <CODE>[No Description Provided by Google]</CODE> */
138    public static class RequestPattern
139        extends BaseType
140        implements java.io.Serializable
141    {
142        /** For Object Serialization.  java.io.Serializable */
143        protected static final long serialVersionUID = 1;
144        
145        public boolean[] optionals()
146        { return new boolean[] { true, true, true, }; }
147        
148        /**
149         * Wildcards (<CODE>'*'</CODE> -&gt; zero or more, <CODE>'?'</CODE> -&gt; exactly one) are allowed. Escape character is
150         * backslash. Omitting is equivalent to <CODE>"*"</CODE>.
151         * <BR />
152         * <BR /><B>OPTIONAL</B>
153         */
154        public final String urlPattern;
155        
156        /**
157         * If set, only requests for matching resource types will be intercepted.
158         * <BR />
159         * <BR /><B>OPTIONAL</B>
160         */
161        public final String resourceType;
162        
163        /**
164         * Stage at which to begin intercepting requests. Default is Request.
165         * <BR />
166         * <BR /><B>OPTIONAL</B>
167         */
168        public final String requestStage;
169        
170        /**
171         * Constructor
172         *
173         * @param urlPattern 
174         * Wildcards (<CODE>'*'</CODE> -&gt; zero or more, <CODE>'?'</CODE> -&gt; exactly one) are allowed. Escape character is
175         * backslash. Omitting is equivalent to <CODE>"*"</CODE>.
176         * <BR /><B>OPTIONAL</B>
177         * 
178         * @param resourceType If set, only requests for matching resource types will be intercepted.
179         * <BR /><B>OPTIONAL</B>
180         * 
181         * @param requestStage Stage at which to begin intercepting requests. Default is Request.
182         * <BR /><B>OPTIONAL</B>
183         */
184        public RequestPattern(String urlPattern, String resourceType, String requestStage)
185        {
186            // Exception-Check(s) to ensure that if any parameters which must adhere to a
187            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
188            
189            THROWS.checkIAE("resourceType", resourceType, "Network.ResourceType", Network.ResourceType);
190            THROWS.checkIAE("requestStage", requestStage, "Fetch.RequestStage", Fetch.RequestStage);
191            
192            this.urlPattern    = urlPattern;
193            this.resourceType  = resourceType;
194            this.requestStage  = requestStage;
195        }
196        
197        /**
198         * JSON Object Constructor
199         * @param jo A Json-Object having data about an instance of {@code 'RequestPattern'}.
200         */
201        public RequestPattern (JsonObject jo)
202        {
203            this.urlPattern    = ReadJSON.getString(jo, "urlPattern", true, false);
204            this.resourceType  = ReadJSON.getString(jo, "resourceType", true, false);
205            this.requestStage  = ReadJSON.getString(jo, "requestStage", true, false);
206        }
207        
208        
209        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
210        public boolean equals(Object other)
211        {
212            if (this == other)                       return true;
213            if (other == null)                       return false;
214            if (other.getClass() != this.getClass()) return false;
215        
216            RequestPattern o = (RequestPattern) other;
217        
218            return
219                    Objects.equals(this.urlPattern, o.urlPattern)
220                &&  Objects.equals(this.resourceType, o.resourceType)
221                &&  Objects.equals(this.requestStage, o.requestStage);
222        }
223        
224        /** Generates a Hash-Code for {@code 'this'} instance */
225        public int hashCode()
226        {
227            return
228                    Objects.hashCode(this.urlPattern)
229                +   Objects.hashCode(this.resourceType)
230                +   Objects.hashCode(this.requestStage);
231        }
232    }
233    
234    /** Response HTTP header entry */
235    public static class HeaderEntry
236        extends BaseType
237        implements java.io.Serializable
238    {
239        /** For Object Serialization.  java.io.Serializable */
240        protected static final long serialVersionUID = 1;
241        
242        public boolean[] optionals()
243        { return new boolean[] { false, false, }; }
244        
245        /** <CODE>[No Description Provided by Google]</CODE> */
246        public final String name;
247        
248        /** <CODE>[No Description Provided by Google]</CODE> */
249        public final String value;
250        
251        /**
252         * Constructor
253         *
254         * @param name -
255         * 
256         * @param value -
257         */
258        public HeaderEntry(String name, String value)
259        {
260            // Exception-Check(s) to ensure that if any parameters which are not declared as
261            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
262            
263            if (name == null)  THROWS.throwNPE("name");
264            if (value == null) THROWS.throwNPE("value");
265            
266            this.name   = name;
267            this.value  = value;
268        }
269        
270        /**
271         * JSON Object Constructor
272         * @param jo A Json-Object having data about an instance of {@code 'HeaderEntry'}.
273         */
274        public HeaderEntry (JsonObject jo)
275        {
276            this.name   = ReadJSON.getString(jo, "name", false, true);
277            this.value  = ReadJSON.getString(jo, "value", false, true);
278        }
279        
280        
281        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
282        public boolean equals(Object other)
283        {
284            if (this == other)                       return true;
285            if (other == null)                       return false;
286            if (other.getClass() != this.getClass()) return false;
287        
288            HeaderEntry o = (HeaderEntry) other;
289        
290            return
291                    Objects.equals(this.name, o.name)
292                &&  Objects.equals(this.value, o.value);
293        }
294        
295        /** Generates a Hash-Code for {@code 'this'} instance */
296        public int hashCode()
297        {
298            return
299                    Objects.hashCode(this.name)
300                +   Objects.hashCode(this.value);
301        }
302    }
303    
304    /** Authorization challenge for HTTP status code 401 or 407. */
305    public static class AuthChallenge
306        extends BaseType
307        implements java.io.Serializable
308    {
309        /** For Object Serialization.  java.io.Serializable */
310        protected static final long serialVersionUID = 1;
311        
312        public boolean[] optionals()
313        { return new boolean[] { true, false, false, false, }; }
314        
315        /**
316         * Source of the authentication challenge.
317         * <BR />
318         * <BR /><B>OPTIONAL</B>
319         */
320        public final String source;
321        
322        /** Origin of the challenger. */
323        public final String origin;
324        
325        /** The authentication scheme used, such as basic or digest */
326        public final String scheme;
327        
328        /** The realm of the challenge. May be empty. */
329        public final String realm;
330        
331        /**
332         * Constructor
333         *
334         * @param source Source of the authentication challenge.
335         * <BR />Acceptable Values: ["Server", "Proxy"]
336         * <BR /><B>OPTIONAL</B>
337         * 
338         * @param origin Origin of the challenger.
339         * 
340         * @param scheme The authentication scheme used, such as basic or digest
341         * 
342         * @param realm The realm of the challenge. May be empty.
343         */
344        public AuthChallenge(String source, String origin, String scheme, String realm)
345        {
346            // Exception-Check(s) to ensure that if any parameters which are not declared as
347            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
348            
349            if (origin == null) THROWS.throwNPE("origin");
350            if (scheme == null) THROWS.throwNPE("scheme");
351            if (realm == null)  THROWS.throwNPE("realm");
352            
353            // Exception-Check(s) to ensure that if any parameters which must adhere to a
354            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
355            
356            THROWS.checkIAE(
357                "source", source,
358                "Server", "Proxy"
359            );
360            
361            this.source  = source;
362            this.origin  = origin;
363            this.scheme  = scheme;
364            this.realm   = realm;
365        }
366        
367        /**
368         * JSON Object Constructor
369         * @param jo A Json-Object having data about an instance of {@code 'AuthChallenge'}.
370         */
371        public AuthChallenge (JsonObject jo)
372        {
373            this.source  = ReadJSON.getString(jo, "source", true, false);
374            this.origin  = ReadJSON.getString(jo, "origin", false, true);
375            this.scheme  = ReadJSON.getString(jo, "scheme", false, true);
376            this.realm   = ReadJSON.getString(jo, "realm", false, true);
377        }
378        
379        
380        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
381        public boolean equals(Object other)
382        {
383            if (this == other)                       return true;
384            if (other == null)                       return false;
385            if (other.getClass() != this.getClass()) return false;
386        
387            AuthChallenge o = (AuthChallenge) other;
388        
389            return
390                    Objects.equals(this.source, o.source)
391                &&  Objects.equals(this.origin, o.origin)
392                &&  Objects.equals(this.scheme, o.scheme)
393                &&  Objects.equals(this.realm, o.realm);
394        }
395        
396        /** Generates a Hash-Code for {@code 'this'} instance */
397        public int hashCode()
398        {
399            return
400                    Objects.hashCode(this.source)
401                +   Objects.hashCode(this.origin)
402                +   Objects.hashCode(this.scheme)
403                +   Objects.hashCode(this.realm);
404        }
405    }
406    
407    /** Response to an AuthChallenge. */
408    public static class AuthChallengeResponse
409        extends BaseType
410        implements java.io.Serializable
411    {
412        /** For Object Serialization.  java.io.Serializable */
413        protected static final long serialVersionUID = 1;
414        
415        public boolean[] optionals()
416        { return new boolean[] { false, true, true, }; }
417        
418        /**
419         * The decision on what to do in response to the authorization challenge.  Default means
420         * deferring to the default behavior of the net stack, which will likely either the Cancel
421         * authentication or display a popup dialog box.
422         */
423        public final String response;
424        
425        /**
426         * The username to provide, possibly empty. Should only be set if response is
427         * ProvideCredentials.
428         * <BR />
429         * <BR /><B>OPTIONAL</B>
430         */
431        public final String username;
432        
433        /**
434         * The password to provide, possibly empty. Should only be set if response is
435         * ProvideCredentials.
436         * <BR />
437         * <BR /><B>OPTIONAL</B>
438         */
439        public final String password;
440        
441        /**
442         * Constructor
443         *
444         * @param response 
445         * The decision on what to do in response to the authorization challenge.  Default means
446         * deferring to the default behavior of the net stack, which will likely either the Cancel
447         * authentication or display a popup dialog box.
448         * <BR />Acceptable Values: ["Default", "CancelAuth", "ProvideCredentials"]
449         * 
450         * @param username 
451         * The username to provide, possibly empty. Should only be set if response is
452         * ProvideCredentials.
453         * <BR /><B>OPTIONAL</B>
454         * 
455         * @param password 
456         * The password to provide, possibly empty. Should only be set if response is
457         * ProvideCredentials.
458         * <BR /><B>OPTIONAL</B>
459         */
460        public AuthChallengeResponse(String response, String username, String password)
461        {
462            // Exception-Check(s) to ensure that if any parameters which are not declared as
463            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
464            
465            if (response == null) THROWS.throwNPE("response");
466            
467            // Exception-Check(s) to ensure that if any parameters which must adhere to a
468            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
469            
470            THROWS.checkIAE(
471                "response", response,
472                "Default", "CancelAuth", "ProvideCredentials"
473            );
474            
475            this.response  = response;
476            this.username  = username;
477            this.password  = password;
478        }
479        
480        /**
481         * JSON Object Constructor
482         * @param jo A Json-Object having data about an instance of {@code 'AuthChallengeResponse'}.
483         */
484        public AuthChallengeResponse (JsonObject jo)
485        {
486            this.response  = ReadJSON.getString(jo, "response", false, true);
487            this.username  = ReadJSON.getString(jo, "username", true, false);
488            this.password  = ReadJSON.getString(jo, "password", true, false);
489        }
490        
491        
492        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
493        public boolean equals(Object other)
494        {
495            if (this == other)                       return true;
496            if (other == null)                       return false;
497            if (other.getClass() != this.getClass()) return false;
498        
499            AuthChallengeResponse o = (AuthChallengeResponse) other;
500        
501            return
502                    Objects.equals(this.response, o.response)
503                &&  Objects.equals(this.username, o.username)
504                &&  Objects.equals(this.password, o.password);
505        }
506        
507        /** Generates a Hash-Code for {@code 'this'} instance */
508        public int hashCode()
509        {
510            return
511                    Objects.hashCode(this.response)
512                +   Objects.hashCode(this.username)
513                +   Objects.hashCode(this.password);
514        }
515    }
516    
517    /**
518     * Issued when the domain is enabled and the request URL matches the
519     * specified filter. The request is paused until the client responds
520     * with one of continueRequest, failRequest or fulfillRequest.
521     * The stage of the request can be determined by presence of responseErrorReason
522     * and responseStatusCode -- the request is at the response stage if either
523     * of these fields is present and in the request stage otherwise.
524     */
525    public static class requestPaused
526        extends BrowserEvent
527        implements java.io.Serializable
528    {
529        /** For Object Serialization.  java.io.Serializable */
530        protected static final long serialVersionUID = 1;
531        
532        public boolean[] optionals()
533        { return new boolean[] { false, false, false, false, true, true, true, true, true, }; }
534        
535        /** Each request the page makes will have a unique id. */
536        public final String requestId;
537        
538        /** The details of the request. */
539        public final Network.Request request;
540        
541        /** The id of the frame that initiated the request. */
542        public final String frameId;
543        
544        /** How the requested resource will be used. */
545        public final String resourceType;
546        
547        /**
548         * Response error if intercepted at response stage.
549         * <BR />
550         * <BR /><B>OPTIONAL</B>
551         */
552        public final String responseErrorReason;
553        
554        /**
555         * Response code if intercepted at response stage.
556         * <BR />
557         * <BR /><B>OPTIONAL</B>
558         */
559        public final Integer responseStatusCode;
560        
561        /**
562         * Response status text if intercepted at response stage.
563         * <BR />
564         * <BR /><B>OPTIONAL</B>
565         */
566        public final String responseStatusText;
567        
568        /**
569         * Response headers if intercepted at the response stage.
570         * <BR />
571         * <BR /><B>OPTIONAL</B>
572         */
573        public final Fetch.HeaderEntry[] responseHeaders;
574        
575        /**
576         * If the intercepted request had a corresponding Network.requestWillBeSent event fired for it,
577         * then this networkId will be the same as the requestId present in the requestWillBeSent event.
578         * <BR />
579         * <BR /><B>OPTIONAL</B>
580         */
581        public final String networkId;
582        
583        /**
584         * Constructor
585         *
586         * @param requestId Each request the page makes will have a unique id.
587         * 
588         * @param request The details of the request.
589         * 
590         * @param frameId The id of the frame that initiated the request.
591         * 
592         * @param resourceType How the requested resource will be used.
593         * 
594         * @param responseErrorReason Response error if intercepted at response stage.
595         * <BR /><B>OPTIONAL</B>
596         * 
597         * @param responseStatusCode Response code if intercepted at response stage.
598         * <BR /><B>OPTIONAL</B>
599         * 
600         * @param responseStatusText Response status text if intercepted at response stage.
601         * <BR /><B>OPTIONAL</B>
602         * 
603         * @param responseHeaders Response headers if intercepted at the response stage.
604         * <BR /><B>OPTIONAL</B>
605         * 
606         * @param networkId 
607         * If the intercepted request had a corresponding Network.requestWillBeSent event fired for it,
608         * then this networkId will be the same as the requestId present in the requestWillBeSent event.
609         * <BR /><B>OPTIONAL</B>
610         */
611        public requestPaused(
612                String requestId, Network.Request request, String frameId, String resourceType, 
613                String responseErrorReason, Integer responseStatusCode, String responseStatusText, 
614                Fetch.HeaderEntry[] responseHeaders, String networkId
615            )
616        {
617            super("Fetch", "requestPaused", 9);
618            
619            // Exception-Check(s) to ensure that if any parameters which are not declared as
620            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
621            
622            if (requestId == null)    THROWS.throwNPE("requestId");
623            if (request == null)      THROWS.throwNPE("request");
624            if (frameId == null)      THROWS.throwNPE("frameId");
625            if (resourceType == null) THROWS.throwNPE("resourceType");
626            
627            // Exception-Check(s) to ensure that if any parameters which must adhere to a
628            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
629            
630            THROWS.checkIAE("resourceType", resourceType, "Network.ResourceType", Network.ResourceType);
631            THROWS.checkIAE("responseErrorReason", responseErrorReason, "Network.ErrorReason", Network.ErrorReason);
632            
633            this.requestId            = requestId;
634            this.request              = request;
635            this.frameId              = frameId;
636            this.resourceType         = resourceType;
637            this.responseErrorReason  = responseErrorReason;
638            this.responseStatusCode   = responseStatusCode;
639            this.responseStatusText   = responseStatusText;
640            this.responseHeaders      = responseHeaders;
641            this.networkId            = networkId;
642        }
643        
644        /**
645         * JSON Object Constructor
646         * @param jo A Json-Object having data about an instance of {@code 'requestPaused'}.
647         */
648        public requestPaused (JsonObject jo)
649        {
650            super("Fetch", "requestPaused", 9);
651        
652            this.requestId            = ReadJSON.getString(jo, "requestId", false, true);
653            this.request              = ReadJSON.getObject(jo, "request", Network.Request.class, false, true);
654            this.frameId              = ReadJSON.getString(jo, "frameId", false, true);
655            this.resourceType         = ReadJSON.getString(jo, "resourceType", false, true);
656            this.responseErrorReason  = ReadJSON.getString(jo, "responseErrorReason", true, false);
657            this.responseStatusCode   = ReadBoxedJSON.getInteger(jo, "responseStatusCode", true);
658            this.responseStatusText   = ReadJSON.getString(jo, "responseStatusText", true, false);
659            this.responseHeaders = (jo.getJsonArray("responseHeaders") == null)
660                ? null
661                : RJArrIntoStream.objArr(jo.getJsonArray("responseHeaders"), null, 0, Fetch.HeaderEntry.class).toArray(Fetch.HeaderEntry[]::new);
662        
663            this.networkId            = ReadJSON.getString(jo, "networkId", true, false);
664        }
665        
666        
667        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
668        public boolean equals(Object other)
669        {
670            if (this == other)                       return true;
671            if (other == null)                       return false;
672            if (other.getClass() != this.getClass()) return false;
673        
674            requestPaused o = (requestPaused) other;
675        
676            return
677                    Objects.equals(this.requestId, o.requestId)
678                &&  Objects.equals(this.request, o.request)
679                &&  Objects.equals(this.frameId, o.frameId)
680                &&  Objects.equals(this.resourceType, o.resourceType)
681                &&  Objects.equals(this.responseErrorReason, o.responseErrorReason)
682                &&  Objects.equals(this.responseStatusCode, o.responseStatusCode)
683                &&  Objects.equals(this.responseStatusText, o.responseStatusText)
684                &&  Arrays.deepEquals(this.responseHeaders, o.responseHeaders)
685                &&  Objects.equals(this.networkId, o.networkId);
686        }
687        
688        /** Generates a Hash-Code for {@code 'this'} instance */
689        public int hashCode()
690        {
691            return
692                    Objects.hashCode(this.requestId)
693                +   this.request.hashCode()
694                +   Objects.hashCode(this.frameId)
695                +   Objects.hashCode(this.resourceType)
696                +   Objects.hashCode(this.responseErrorReason)
697                +   Objects.hashCode(this.responseStatusCode)
698                +   Objects.hashCode(this.responseStatusText)
699                +   Arrays.deepHashCode(this.responseHeaders)
700                +   Objects.hashCode(this.networkId);
701        }
702    }
703    
704    /**
705     * Issued when the domain is enabled with handleAuthRequests set to true.
706     * The request is paused until client responds with continueWithAuth.
707     */
708    public static class authRequired
709        extends BrowserEvent
710        implements java.io.Serializable
711    {
712        /** For Object Serialization.  java.io.Serializable */
713        protected static final long serialVersionUID = 1;
714        
715        public boolean[] optionals()
716        { return new boolean[] { false, false, false, false, false, }; }
717        
718        /** Each request the page makes will have a unique id. */
719        public final String requestId;
720        
721        /** The details of the request. */
722        public final Network.Request request;
723        
724        /** The id of the frame that initiated the request. */
725        public final String frameId;
726        
727        /** How the requested resource will be used. */
728        public final String resourceType;
729        
730        /**
731         * Details of the Authorization Challenge encountered.
732         * If this is set, client should respond with continueRequest that
733         * contains AuthChallengeResponse.
734         */
735        public final Fetch.AuthChallenge authChallenge;
736        
737        /**
738         * Constructor
739         *
740         * @param requestId Each request the page makes will have a unique id.
741         * 
742         * @param request The details of the request.
743         * 
744         * @param frameId The id of the frame that initiated the request.
745         * 
746         * @param resourceType How the requested resource will be used.
747         * 
748         * @param authChallenge 
749         * Details of the Authorization Challenge encountered.
750         * If this is set, client should respond with continueRequest that
751         * contains AuthChallengeResponse.
752         */
753        public authRequired(
754                String requestId, Network.Request request, String frameId, String resourceType, 
755                Fetch.AuthChallenge authChallenge
756            )
757        {
758            super("Fetch", "authRequired", 5);
759            
760            // Exception-Check(s) to ensure that if any parameters which are not declared as
761            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
762            
763            if (requestId == null)     THROWS.throwNPE("requestId");
764            if (request == null)       THROWS.throwNPE("request");
765            if (frameId == null)       THROWS.throwNPE("frameId");
766            if (resourceType == null)  THROWS.throwNPE("resourceType");
767            if (authChallenge == null) THROWS.throwNPE("authChallenge");
768            
769            // Exception-Check(s) to ensure that if any parameters which must adhere to a
770            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
771            
772            THROWS.checkIAE("resourceType", resourceType, "Network.ResourceType", Network.ResourceType);
773            
774            this.requestId      = requestId;
775            this.request        = request;
776            this.frameId        = frameId;
777            this.resourceType   = resourceType;
778            this.authChallenge  = authChallenge;
779        }
780        
781        /**
782         * JSON Object Constructor
783         * @param jo A Json-Object having data about an instance of {@code 'authRequired'}.
784         */
785        public authRequired (JsonObject jo)
786        {
787            super("Fetch", "authRequired", 5);
788        
789            this.requestId      = ReadJSON.getString(jo, "requestId", false, true);
790            this.request        = ReadJSON.getObject(jo, "request", Network.Request.class, false, true);
791            this.frameId        = ReadJSON.getString(jo, "frameId", false, true);
792            this.resourceType   = ReadJSON.getString(jo, "resourceType", false, true);
793            this.authChallenge  = ReadJSON.getObject(jo, "authChallenge", Fetch.AuthChallenge.class, false, true);
794        }
795        
796        
797        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
798        public boolean equals(Object other)
799        {
800            if (this == other)                       return true;
801            if (other == null)                       return false;
802            if (other.getClass() != this.getClass()) return false;
803        
804            authRequired o = (authRequired) other;
805        
806            return
807                    Objects.equals(this.requestId, o.requestId)
808                &&  Objects.equals(this.request, o.request)
809                &&  Objects.equals(this.frameId, o.frameId)
810                &&  Objects.equals(this.resourceType, o.resourceType)
811                &&  Objects.equals(this.authChallenge, o.authChallenge);
812        }
813        
814        /** Generates a Hash-Code for {@code 'this'} instance */
815        public int hashCode()
816        {
817            return
818                    Objects.hashCode(this.requestId)
819                +   this.request.hashCode()
820                +   Objects.hashCode(this.frameId)
821                +   Objects.hashCode(this.resourceType)
822                +   this.authChallenge.hashCode();
823        }
824    }
825    
826    
827    // Counter for keeping the WebSocket Request ID's distinct.
828    private static int counter = 1;
829    
830    /**
831     * Disables the fetch domain.
832     * 
833     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
834     * {@link Ret0}&gt;</CODE>
835     *
836     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
837     * browser receives the invocation-request.
838     *
839     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
840     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
841     * {@code >} to ensure the Browser Function has run to completion.
842     */
843    public static Script<String, JsonObject, Ret0> disable()
844    {
845        final int          webSocketID = 42000000 + counter++;
846        final boolean[]    optionals   = new boolean[0];
847        
848        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
849        String requestJSON = WriteJSON.get(
850            parameterTypes.get("disable"),
851            parameterNames.get("disable"),
852            optionals, webSocketID,
853            "Fetch.disable"
854        );
855        
856        // This Remote Command does not have a Return-Value.
857        return new Script<>
858            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
859    }
860    
861    /**
862     * Enables issuing of requestPaused events. A request will be paused until client
863     * calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
864     * 
865     * @param patterns 
866     * If specified, only requests matching any of these patterns will produce
867     * fetchRequested event and will be paused until clients response. If not set,
868     * all requests will be affected.
869     * <BR /><B>OPTIONAL</B>
870     * 
871     * @param handleAuthRequests 
872     * If true, authRequired events will be issued and requests will be paused
873     * expecting a call to continueWithAuth.
874     * <BR /><B>OPTIONAL</B>
875     * 
876     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
877     * {@link Ret0}&gt;</CODE>
878     *
879     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
880     * browser receives the invocation-request.
881     *
882     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
883     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
884     * {@code >} to ensure the Browser Function has run to completion.
885     */
886    public static Script<String, JsonObject, Ret0> enable
887        (Fetch.RequestPattern[] patterns, Boolean handleAuthRequests)
888    {
889        final int       webSocketID = 42001000 + counter++;
890        final boolean[] optionals   = { true, true, };
891        
892        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
893        String requestJSON = WriteJSON.get(
894            parameterTypes.get("enable"),
895            parameterNames.get("enable"),
896            optionals, webSocketID,
897            "Fetch.enable",
898            patterns, handleAuthRequests
899        );
900        
901        // This Remote Command does not have a Return-Value.
902        return new Script<>
903            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
904    }
905    
906    /**
907     * Causes the request to fail with specified reason.
908     * 
909     * @param requestId An id the client received in requestPaused event.
910     * 
911     * @param errorReason Causes the request to fail with the given reason.
912     * 
913     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
914     * {@link Ret0}&gt;</CODE>
915     *
916     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
917     * browser receives the invocation-request.
918     *
919     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
920     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
921     * {@code >} to ensure the Browser Function has run to completion.
922     */
923    public static Script<String, JsonObject, Ret0> failRequest
924        (String requestId, String errorReason)
925    {
926        // Exception-Check(s) to ensure that if any parameters which are not declared as
927        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
928        
929        if (requestId == null)   THROWS.throwNPE("requestId");
930        if (errorReason == null) THROWS.throwNPE("errorReason");
931        
932        // Exception-Check(s) to ensure that if any parameters which must adhere to a
933        // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
934        
935        THROWS.checkIAE("errorReason", errorReason, "Network.ErrorReason", Network.ErrorReason);
936        
937        final int       webSocketID = 42002000 + counter++;
938        final boolean[] optionals   = { false, false, };
939        
940        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
941        String requestJSON = WriteJSON.get(
942            parameterTypes.get("failRequest"),
943            parameterNames.get("failRequest"),
944            optionals, webSocketID,
945            "Fetch.failRequest",
946            requestId, errorReason
947        );
948        
949        // This Remote Command does not have a Return-Value.
950        return new Script<>
951            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
952    }
953    
954    /**
955     * Provides response to the request.
956     * 
957     * @param requestId An id the client received in requestPaused event.
958     * 
959     * @param responseCode An HTTP response code.
960     * 
961     * @param responseHeaders Response headers.
962     * <BR /><B>OPTIONAL</B>
963     * 
964     * @param binaryResponseHeaders 
965     * Alternative way of specifying response headers as a \0-separated
966     * series of name: value pairs. Prefer the above method unless you
967     * need to represent some non-UTF8 values that can't be transmitted
968     * over the protocol as text. (Encoded as a base64 string when passed over JSON)
969     * <BR /><B>OPTIONAL</B>
970     * 
971     * @param body 
972     * A response body. If absent, original response body will be used if
973     * the request is intercepted at the response stage and empty body
974     * will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)
975     * <BR /><B>OPTIONAL</B>
976     * 
977     * @param responsePhrase 
978     * A textual representation of responseCode.
979     * If absent, a standard phrase matching responseCode is used.
980     * <BR /><B>OPTIONAL</B>
981     * 
982     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
983     * {@link Ret0}&gt;</CODE>
984     *
985     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
986     * browser receives the invocation-request.
987     *
988     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
989     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
990     * {@code >} to ensure the Browser Function has run to completion.
991     */
992    public static Script<String, JsonObject, Ret0> fulfillRequest(
993            String requestId, int responseCode, Fetch.HeaderEntry[] responseHeaders, 
994            String binaryResponseHeaders, String body, String responsePhrase
995        )
996    {
997        // Exception-Check(s) to ensure that if any parameters which are not declared as
998        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
999        
1000        if (requestId == null) THROWS.throwNPE("requestId");
1001        
1002        final int       webSocketID = 42003000 + counter++;
1003        final boolean[] optionals   = { false, false, true, true, true, true, };
1004        
1005        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1006        String requestJSON = WriteJSON.get(
1007            parameterTypes.get("fulfillRequest"),
1008            parameterNames.get("fulfillRequest"),
1009            optionals, webSocketID,
1010            "Fetch.fulfillRequest",
1011            requestId, responseCode, responseHeaders, binaryResponseHeaders, body, responsePhrase
1012        );
1013        
1014        // This Remote Command does not have a Return-Value.
1015        return new Script<>
1016            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
1017    }
1018    
1019    /**
1020     * Continues the request, optionally modifying some of its parameters.
1021     * 
1022     * @param requestId An id the client received in requestPaused event.
1023     * 
1024     * @param url If set, the request url will be modified in a way that's not observable by page.
1025     * <BR /><B>OPTIONAL</B>
1026     * 
1027     * @param method If set, the request method is overridden.
1028     * <BR /><B>OPTIONAL</B>
1029     * 
1030     * @param postData If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)
1031     * <BR /><B>OPTIONAL</B>
1032     * 
1033     * @param headers If set, overrides the request headers.
1034     * <BR /><B>OPTIONAL</B>
1035     * 
1036     * @param interceptResponse If set, overrides response interception behavior for this request.
1037     * <BR /><B>OPTIONAL</B>
1038     * <BR /><B>EXPERIMENTAL</B>
1039     * 
1040     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1041     * {@link Ret0}&gt;</CODE>
1042     *
1043     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1044     * browser receives the invocation-request.
1045     *
1046     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1047     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1048     * {@code >} to ensure the Browser Function has run to completion.
1049     */
1050    public static Script<String, JsonObject, Ret0> continueRequest(
1051            String requestId, String url, String method, String postData, 
1052            Fetch.HeaderEntry[] headers, Boolean interceptResponse
1053        )
1054    {
1055        // Exception-Check(s) to ensure that if any parameters which are not declared as
1056        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1057        
1058        if (requestId == null) THROWS.throwNPE("requestId");
1059        
1060        final int       webSocketID = 42004000 + counter++;
1061        final boolean[] optionals   = { false, true, true, true, true, true, };
1062        
1063        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1064        String requestJSON = WriteJSON.get(
1065            parameterTypes.get("continueRequest"),
1066            parameterNames.get("continueRequest"),
1067            optionals, webSocketID,
1068            "Fetch.continueRequest",
1069            requestId, url, method, postData, headers, interceptResponse
1070        );
1071        
1072        // This Remote Command does not have a Return-Value.
1073        return new Script<>
1074            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
1075    }
1076    
1077    /**
1078     * Continues a request supplying authChallengeResponse following authRequired event.
1079     * 
1080     * @param requestId An id the client received in authRequired event.
1081     * 
1082     * @param authChallengeResponse Response to  with an authChallenge.
1083     * 
1084     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1085     * {@link Ret0}&gt;</CODE>
1086     *
1087     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1088     * browser receives the invocation-request.
1089     *
1090     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1091     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1092     * {@code >} to ensure the Browser Function has run to completion.
1093     */
1094    public static Script<String, JsonObject, Ret0> continueWithAuth
1095        (String requestId, Fetch.AuthChallengeResponse authChallengeResponse)
1096    {
1097        // Exception-Check(s) to ensure that if any parameters which are not declared as
1098        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1099        
1100        if (requestId == null)             THROWS.throwNPE("requestId");
1101        if (authChallengeResponse == null) THROWS.throwNPE("authChallengeResponse");
1102        
1103        final int       webSocketID = 42005000 + counter++;
1104        final boolean[] optionals   = { false, false, };
1105        
1106        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1107        String requestJSON = WriteJSON.get(
1108            parameterTypes.get("continueWithAuth"),
1109            parameterNames.get("continueWithAuth"),
1110            optionals, webSocketID,
1111            "Fetch.continueWithAuth",
1112            requestId, authChallengeResponse
1113        );
1114        
1115        // This Remote Command does not have a Return-Value.
1116        return new Script<>
1117            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
1118    }
1119    
1120    /**
1121     * Continues loading of the paused response, optionally modifying the
1122     * response headers. If either responseCode or headers are modified, all of them
1123     * must be present.
1124     * <BR /><B>EXPERIMENTAL</B>
1125     * 
1126     * @param requestId An id the client received in requestPaused event.
1127     * 
1128     * @param responseCode An HTTP response code. If absent, original response code will be used.
1129     * <BR /><B>OPTIONAL</B>
1130     * 
1131     * @param responsePhrase 
1132     * A textual representation of responseCode.
1133     * If absent, a standard phrase matching responseCode is used.
1134     * <BR /><B>OPTIONAL</B>
1135     * 
1136     * @param responseHeaders Response headers. If absent, original response headers will be used.
1137     * <BR /><B>OPTIONAL</B>
1138     * 
1139     * @param binaryResponseHeaders 
1140     * Alternative way of specifying response headers as a \0-separated
1141     * series of name: value pairs. Prefer the above method unless you
1142     * need to represent some non-UTF8 values that can't be transmitted
1143     * over the protocol as text. (Encoded as a base64 string when passed over JSON)
1144     * <BR /><B>OPTIONAL</B>
1145     * 
1146     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1147     * {@link Ret0}&gt;</CODE>
1148     *
1149     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1150     * browser receives the invocation-request.
1151     *
1152     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1153     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1154     * {@code >} to ensure the Browser Function has run to completion.
1155     */
1156    public static Script<String, JsonObject, Ret0> continueResponse(
1157            String requestId, Integer responseCode, String responsePhrase, 
1158            Fetch.HeaderEntry[] responseHeaders, String binaryResponseHeaders
1159        )
1160    {
1161        // Exception-Check(s) to ensure that if any parameters which are not declared as
1162        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1163        
1164        if (requestId == null) THROWS.throwNPE("requestId");
1165        
1166        final int       webSocketID = 42006000 + counter++;
1167        final boolean[] optionals   = { false, true, true, true, true, };
1168        
1169        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1170        String requestJSON = WriteJSON.get(
1171            parameterTypes.get("continueResponse"),
1172            parameterNames.get("continueResponse"),
1173            optionals, webSocketID,
1174            "Fetch.continueResponse",
1175            requestId, responseCode, responsePhrase, responseHeaders, binaryResponseHeaders
1176        );
1177        
1178        // This Remote Command does not have a Return-Value.
1179        return new Script<>
1180            (webSocketID, requestJSON, VOID_RETURN.NoReturnValues);
1181    }
1182    
1183    /**
1184     * Causes the body of the response to be received from the server and
1185     * returned as a single string. May only be issued for a request that
1186     * is paused in the Response stage and is mutually exclusive with
1187     * takeResponseBodyForInterceptionAsStream. Calling other methods that
1188     * affect the request or disabling fetch domain before body is received
1189     * results in an undefined behavior.
1190     * 
1191     * @param requestId Identifier for the intercepted request to get body for.
1192     * 
1193     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1194     * {@link Ret2}&gt;</CODE>
1195     *
1196     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
1197     * {@link Script#exec()}), and a {@link Promise} returned.
1198     *
1199     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
1200     * (using {@link Promise#await()}), the {@code Ret2} will subsequently
1201     * be returned from that call.
1202     * 
1203     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
1204     * in an instance of <B>{@link Ret2}</B>
1205     *
1206     * <BR /><BR /><UL CLASS=JDUL>
1207     * <LI><CODE><B>Ret2.a:</B> String (<B>body</B>)</CODE>
1208     *     <BR />Response body.
1209     *     <BR /><BR /></LI>
1210     * <LI><CODE><B>Ret2.b:</B> Boolean (<B>base64Encoded</B>)</CODE>
1211     *     <BR />True, if content was sent as base64.
1212     *     </LI>
1213     * </UL>
1214     */
1215    public static Script<String, JsonObject, Ret2<String, Boolean>> getResponseBody
1216        (String requestId)
1217    {
1218        // Exception-Check(s) to ensure that if any parameters which are not declared as
1219        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1220        
1221        if (requestId == null) THROWS.throwNPE("requestId");
1222        
1223        final int       webSocketID = 42007000 + counter++;
1224        final boolean[] optionals   = { false, };
1225        
1226        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1227        String requestJSON = WriteJSON.get(
1228            parameterTypes.get("getResponseBody"),
1229            parameterNames.get("getResponseBody"),
1230            optionals, webSocketID,
1231            "Fetch.getResponseBody",
1232            requestId
1233        );
1234        
1235        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret2'
1236        Function<JsonObject, Ret2<String, Boolean>> 
1237            responseProcessor = (JsonObject jo) -> new Ret2<>(
1238                ReadJSON.getString(jo, "body", false, true),
1239                ReadBoxedJSON.getBoolean(jo, "base64Encoded", true)
1240            );
1241        
1242        return new Script<>(webSocketID, requestJSON, responseProcessor);
1243    }
1244    
1245    /**
1246     * Returns a handle to the stream representing the response body.
1247     * The request must be paused in the HeadersReceived stage.
1248     * Note that after this command the request can't be continued
1249     * as is -- client either needs to cancel it or to provide the
1250     * response body.
1251     * The stream only supports sequential read, IO.read will fail if the position
1252     * is specified.
1253     * This method is mutually exclusive with getResponseBody.
1254     * Calling other methods that affect the request or disabling fetch
1255     * domain before body is received results in an undefined behavior.
1256     * 
1257     * @param requestId -
1258     * 
1259     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1260     * String&gt;</CODE>
1261     * 
1262     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1263     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1264     * String&gt;</CODE> will be returned.
1265     *
1266     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1267     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1268      * may be retrieved.</I>
1269     *
1270     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1271     * <BR /><BR /><UL CLASS=JDUL>
1272     * <LI><CODE>String (<B>stream</B></CODE>)
1273     *     <BR />-
1274     * </LI>
1275     * </UL> */
1276    public static Script<String, JsonObject, String> takeResponseBodyAsStream(String requestId)
1277    {
1278        // Exception-Check(s) to ensure that if any parameters which are not declared as
1279        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1280        
1281        if (requestId == null) THROWS.throwNPE("requestId");
1282        
1283        final int       webSocketID = 42008000 + counter++;
1284        final boolean[] optionals   = { false, };
1285        
1286        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1287        String requestJSON = WriteJSON.get(
1288            parameterTypes.get("takeResponseBodyAsStream"),
1289            parameterNames.get("takeResponseBodyAsStream"),
1290            optionals, webSocketID,
1291            "Fetch.takeResponseBodyAsStream",
1292            requestId
1293        );
1294        
1295        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1296        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1297            ReadJSON.getString(jo, "stream", false, true);
1298        
1299        return new Script<>(webSocketID, requestJSON, responseProcessor);
1300    }
1301    
1302}