001package Torello.Browser.BrowserAPI; 002 003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 004// Java-HTML Imports 005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 006 007import Torello.Browser.*; 008import Torello.Browser.helper.*; 009import Torello.Browser.JavaScriptAPI.*; 010import Torello.JSON.*; 011 012import Torello.Java.ReadOnly.ReadOnlyList; 013import Torello.Java.ReadOnly.ReadOnlyArrayList; 014 015import Torello.JavaDoc.Annotations.StaticFunctional; 016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg; 017 018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.Fetch$$Commands; 019 020 021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 022// JDK Imports 023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 024 025import javax.json.JsonObject; 026import javax.json.JsonValue; 027 028/** 029 * <SPAN CLASS=COPIEDJDK><B>A domain for letting clients substitute browser's network layer with client code.</B></SPAN> 030 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE> 031 */ 032@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE") 033public class Fetch 034{ 035 // No Pubic Constructors 036 private Fetch() { } 037 038 039 // ******************************************************************************************** 040 // ******************************************************************************************** 041 // Eliminated Types 042 // ******************************************************************************************** 043 // ******************************************************************************************** 044 045 046 /** 047 * Unique request identifier. 048 * Note that this does not identify individual HTTP requests that are part of 049 * a network request. 050 051 * <EMBED CLASS='external-html' DATA-CTAS='String' DATA-FILE-ID=CDP.EliminatedType 052 * DATA-NAME=RequestId> 053 */ 054 public static final String RequestId = 055 "RequestId has been eliminated.\n" + 056 "It was replaced with the standard Java-Type: String"; 057 058 059 // ******************************************************************************************** 060 // ******************************************************************************************** 061 // Enumerated String Constants Lists 062 // ******************************************************************************************** 063 // ******************************************************************************************** 064 065 066 /** 067 * Stages of the request to handle. Request will intercept before the request is 068 * sent. Response will intercept after the response is received (but before response 069 * body is received). 070 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 071 */ 072 public static final ReadOnlyList<String> RequestStage = new ReadOnlyArrayList<> 073 (String.class, "Request", "Response"); 074 075 076 077 // ******************************************************************************************** 078 // ******************************************************************************************** 079 // Basic Types 080 // ******************************************************************************************** 081 // ******************************************************************************************** 082 083 084 /** 085 * Authorization challenge for HTTP status code 401 or 407. 086 * 087 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 088 */ 089 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 090 public static class AuthChallenge 091 extends BaseType<AuthChallenge> 092 implements java.io.Serializable 093 { 094 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 095 protected static final long serialVersionUID = 1; 096 097 private static final NestedHelper<Fetch.AuthChallenge> singleton = 098 Torello.Browser.BrowserAPI.NestedHelpers.Types. 099 Fetch$$AuthChallenge$$.singleton; 100 101 /** 102 * Source of the authentication challenge. 103 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 104 * <EMBED CLASS='external-html' DATA-D=Fetch DATA-C=AuthChallenge DATA-F=source DATA-FILE-ID=CDP.EL1> 105 * @see BaseType#enumStrList(String) 106 */ 107 public final String source; 108 109 /** Origin of the challenger. */ 110 public final String origin; 111 112 /** The authentication scheme used, such as basic or digest */ 113 public final String scheme; 114 115 /** The realm of the challenge. May be empty. */ 116 public final String realm; 117 118 /** Constructor. Please review this class' fields for documentation. */ 119 public AuthChallenge( 120 ReadOnlyList<Boolean> isPresent, String source, String origin, String scheme, 121 String realm 122 ) 123 { 124 super(singleton, Domains.Fetch, "AuthChallenge", 4); 125 126 this.source = source; 127 this.origin = origin; 128 this.scheme = scheme; 129 this.realm = realm; 130 131 this.isPresent = (isPresent == null) 132 ? singleton.generateIsPresentList(this) 133 : THROWS.check(isPresent, 4, "Fetch.AuthChallenge"); 134 } 135 136 /** Creates an instance of this class from a {@link JsonObject}.*/ 137 public static AuthChallenge fromJSON(JsonObject jo) 138 { return singleton.fromJSON(jo); } 139 140 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 141 public static NestedDescriptor<AuthChallenge> descriptor() 142 { return singleton.descriptor(); } 143 } 144 145 /** 146 * Response to an AuthChallenge. 147 * 148 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 149 */ 150 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 151 public static class AuthChallengeResponse 152 extends BaseType<AuthChallengeResponse> 153 implements java.io.Serializable 154 { 155 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 156 protected static final long serialVersionUID = 1; 157 158 private static final NestedHelper<Fetch.AuthChallengeResponse> singleton = 159 Torello.Browser.BrowserAPI.NestedHelpers.Types. 160 Fetch$$AuthChallengeResponse$$.singleton; 161 162 /** 163 * The decision on what to do in response to the authorization challenge. Default means 164 * deferring to the default behavior of the net stack, which will likely either the Cancel 165 * authentication or display a popup dialog box. 166 * <EMBED CLASS='external-html' DATA-D=Fetch DATA-C=AuthChallengeResponse DATA-F=response DATA-FILE-ID=CDP.EL1> 167 * @see BaseType#enumStrList(String) 168 */ 169 public final String response; 170 171 /** 172 * The username to provide, possibly empty. Should only be set if response is 173 * ProvideCredentials. 174 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 175 */ 176 public final String username; 177 178 /** 179 * The password to provide, possibly empty. Should only be set if response is 180 * ProvideCredentials. 181 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 182 */ 183 public final String password; 184 185 /** Constructor. Please review this class' fields for documentation. */ 186 public AuthChallengeResponse 187 (ReadOnlyList<Boolean> isPresent, String response, String username, String password) 188 { 189 super(singleton, Domains.Fetch, "AuthChallengeResponse", 3); 190 191 this.response = response; 192 this.username = username; 193 this.password = password; 194 195 this.isPresent = (isPresent == null) 196 ? singleton.generateIsPresentList(this) 197 : THROWS.check(isPresent, 3, "Fetch.AuthChallengeResponse"); 198 } 199 200 /** Creates an instance of this class from a {@link JsonObject}.*/ 201 public static AuthChallengeResponse fromJSON(JsonObject jo) 202 { return singleton.fromJSON(jo); } 203 204 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 205 public static NestedDescriptor<AuthChallengeResponse> descriptor() 206 { return singleton.descriptor(); } 207 } 208 209 /** 210 * Response HTTP header entry 211 * 212 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 213 */ 214 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 215 public static class HeaderEntry 216 extends BaseType<HeaderEntry> 217 implements java.io.Serializable 218 { 219 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 220 protected static final long serialVersionUID = 1; 221 222 private static final NestedHelper<Fetch.HeaderEntry> singleton = 223 Torello.Browser.BrowserAPI.NestedHelpers.Types. 224 Fetch$$HeaderEntry$$.singleton; 225 226 /** <CODE>[No Description Provided by Google]</CODE> */ 227 public final String name; 228 229 /** <CODE>[No Description Provided by Google]</CODE> */ 230 public final String value; 231 232 /** Constructor. Please review this class' fields for documentation. */ 233 public HeaderEntry(ReadOnlyList<Boolean> isPresent, String name, String value) 234 { 235 super(singleton, Domains.Fetch, "HeaderEntry", 2); 236 237 this.name = name; 238 this.value = value; 239 240 this.isPresent = (isPresent == null) 241 ? singleton.generateIsPresentList(this) 242 : THROWS.check(isPresent, 2, "Fetch.HeaderEntry"); 243 } 244 245 /** Creates an instance of this class from a {@link JsonObject}.*/ 246 public static HeaderEntry fromJSON(JsonObject jo) 247 { return singleton.fromJSON(jo); } 248 249 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 250 public static NestedDescriptor<HeaderEntry> descriptor() 251 { return singleton.descriptor(); } 252 } 253 254 /** 255 * <CODE>[No Description Provided by Google]</CODE> 256 * 257 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 258 */ 259 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 260 public static class RequestPattern 261 extends BaseType<RequestPattern> 262 implements java.io.Serializable 263 { 264 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 265 protected static final long serialVersionUID = 1; 266 267 private static final NestedHelper<Fetch.RequestPattern> singleton = 268 Torello.Browser.BrowserAPI.NestedHelpers.Types. 269 Fetch$$RequestPattern$$.singleton; 270 271 /** 272 * Wildcards (<CODE>'*'</CODE> -> zero or more, <CODE>'?'</CODE> -> exactly one) are allowed. Escape character is 273 * backslash. Omitting is equivalent to <CODE>"*"</CODE>. 274 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 275 */ 276 public final String urlPattern; 277 278 /** 279 * If set, only requests for matching resource types will be intercepted. 280 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 281 * <EMBED CLASS='external-html' DATA-D=Network DATA-C=ResourceType DATA-F=resourceType DATA-FILE-ID=CDP.EL2> 282 * @see BaseType#enumStrList(String) 283 */ 284 public final String resourceType; 285 286 /** 287 * Stage at which to begin intercepting requests. Default is Request. 288 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 289 * <EMBED CLASS='external-html' DATA-D=Fetch DATA-C=RequestStage DATA-F=requestStage DATA-FILE-ID=CDP.EL2> 290 * @see BaseType#enumStrList(String) 291 */ 292 public final String requestStage; 293 294 /** Constructor. Please review this class' fields for documentation. */ 295 public RequestPattern( 296 ReadOnlyList<Boolean> isPresent, String urlPattern, String resourceType, 297 String requestStage 298 ) 299 { 300 super(singleton, Domains.Fetch, "RequestPattern", 3); 301 302 this.urlPattern = urlPattern; 303 this.resourceType = resourceType; 304 this.requestStage = requestStage; 305 306 this.isPresent = (isPresent == null) 307 ? singleton.generateIsPresentList(this) 308 : THROWS.check(isPresent, 3, "Fetch.RequestPattern"); 309 } 310 311 /** Creates an instance of this class from a {@link JsonObject}.*/ 312 public static RequestPattern fromJSON(JsonObject jo) 313 { return singleton.fromJSON(jo); } 314 315 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 316 public static NestedDescriptor<RequestPattern> descriptor() 317 { return singleton.descriptor(); } 318 } 319 320 321 // ******************************************************************************************** 322 // ******************************************************************************************** 323 // Command-Return Types 324 // ******************************************************************************************** 325 // ******************************************************************************************** 326 327 328 /** 329 * Causes the body of the response to be received from the server and 330 * returned as a single string. May only be issued for a request that 331 * is paused in the Response stage and is mutually exclusive with 332 * takeResponseBodyForInterceptionAsStream. Calling other methods that 333 * affect the request or disabling fetch domain before body is received 334 * results in an undefined behavior. 335 * Note that the response body is not available for redirects. Requests 336 * paused in the _redirect received_ state may be differentiated by 337 * <CODE>responseCode</CODE> and presence of <CODE>location</CODE> response header, see 338 * comments to <CODE>requestPaused</CODE> for details. 339 * 340 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI DATA-CMD=getResponseBody> 341 * @see Fetch#getResponseBody 342 */ 343 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_CMD_JDHBI") 344 public static class getResponseBody$$RET 345 extends BaseType<getResponseBody$$RET> 346 implements java.io.Serializable 347 { 348 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 349 protected static final long serialVersionUID = 1; 350 351 private static final NestedHelper<Fetch.getResponseBody$$RET> singleton = 352 Torello.Browser.BrowserAPI.NestedHelpers.CmdReturns. 353 Fetch$$getResponseBody$$RET.singleton; 354 355 /** Response body. */ 356 public final String body; 357 358 /** True, if content was sent as base64. */ 359 public final boolean base64Encoded; 360 361 /** Constructor. Please review this class' fields for documentation. */ 362 public getResponseBody$$RET 363 (ReadOnlyList<Boolean> isPresent, String body, boolean base64Encoded) 364 { 365 super(singleton, Domains.Fetch, "getResponseBody", 2); 366 367 this.body = body; 368 this.base64Encoded = base64Encoded; 369 370 this.isPresent = (isPresent == null) 371 ? singleton.generateIsPresentList(this) 372 : THROWS.check(isPresent, 2, "Fetch.getResponseBody$$RET"); 373 } 374 375 /** Creates an instance of this class from a {@link JsonObject}.*/ 376 public static getResponseBody$$RET fromJSON(JsonObject jo) 377 { return singleton.fromJSON(jo); } 378 379 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 380 public static NestedDescriptor<getResponseBody$$RET> descriptor() 381 { return singleton.descriptor(); } 382 } 383 384 385 // ******************************************************************************************** 386 // ******************************************************************************************** 387 // Event Types 388 // ******************************************************************************************** 389 // ******************************************************************************************** 390 391 392 /** 393 * Issued when the domain is enabled with handleAuthRequests set to true. 394 * The request is paused until client responds with continueWithAuth. 395 * 396 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 397 */ 398 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 399 public static class authRequired 400 extends BrowserEvent<authRequired> 401 implements java.io.Serializable 402 { 403 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 404 protected static final long serialVersionUID = 1; 405 406 private static final NestedHelper<Fetch.authRequired> singleton = 407 Torello.Browser.BrowserAPI.NestedHelpers.Events. 408 Fetch$$authRequired$$.singleton; 409 410 /** Each request the page makes will have a unique id. */ 411 public final String requestId; 412 413 /** The details of the request. */ 414 public final Network.Request request; 415 416 /** The id of the frame that initiated the request. */ 417 public final String frameId; 418 419 /** 420 * How the requested resource will be used. 421 * <EMBED CLASS='external-html' DATA-D=Network DATA-C=ResourceType DATA-F=resourceType DATA-FILE-ID=CDP.EL2> 422 * @see BaseType#enumStrList(String) 423 */ 424 public final String resourceType; 425 426 /** 427 * Details of the Authorization Challenge encountered. 428 * If this is set, client should respond with continueRequest that 429 * contains AuthChallengeResponse. 430 */ 431 public final Fetch.AuthChallenge authChallenge; 432 433 /** Constructor. Please review this class' fields for documentation. */ 434 public authRequired( 435 ReadOnlyList<Boolean> isPresent, String requestId, Network.Request request, 436 String frameId, String resourceType, AuthChallenge authChallenge 437 ) 438 { 439 super(singleton, Domains.Fetch, "authRequired", 5); 440 441 this.requestId = requestId; 442 this.request = request; 443 this.frameId = frameId; 444 this.resourceType = resourceType; 445 this.authChallenge = authChallenge; 446 447 this.isPresent = (isPresent == null) 448 ? singleton.generateIsPresentList(this) 449 : THROWS.check(isPresent, 5, "Fetch.authRequired"); 450 } 451 452 /** Creates an instance of this class from a {@link JsonObject}.*/ 453 public static authRequired fromJSON(JsonObject jo) 454 { return singleton.fromJSON(jo); } 455 456 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 457 public static NestedDescriptor<authRequired> descriptor() 458 { return singleton.descriptor(); } 459 } 460 461 /** 462 * Issued when the domain is enabled and the request URL matches the 463 * specified filter. The request is paused until the client responds 464 * with one of continueRequest, failRequest or fulfillRequest. 465 * The stage of the request can be determined by presence of responseErrorReason 466 * and responseStatusCode -- the request is at the response stage if either 467 * of these fields is present and in the request stage otherwise. 468 * Redirect responses and subsequent requests are reported similarly to regular 469 * responses and requests. Redirect responses may be distinguished by the value 470 * of <CODE>responseStatusCode</CODE> (which is one of 301, 302, 303, 307, 308) along with 471 * presence of the <CODE>location</CODE> header. Requests resulting from a redirect will 472 * have <CODE>redirectedRequestId</CODE> field set. 473 * 474 * <EMBED CLASS=globalDefs DATA-DOMAIN=Fetch DATA-API=BrowserAPI> 475 */ 476 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI") 477 public static class requestPaused 478 extends BrowserEvent<requestPaused> 479 implements java.io.Serializable 480 { 481 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 482 protected static final long serialVersionUID = 1; 483 484 private static final NestedHelper<Fetch.requestPaused> singleton = 485 Torello.Browser.BrowserAPI.NestedHelpers.Events. 486 Fetch$$requestPaused$$.singleton; 487 488 /** Each request the page makes will have a unique id. */ 489 public final String requestId; 490 491 /** The details of the request. */ 492 public final Network.Request request; 493 494 /** The id of the frame that initiated the request. */ 495 public final String frameId; 496 497 /** 498 * How the requested resource will be used. 499 * <EMBED CLASS='external-html' DATA-D=Network DATA-C=ResourceType DATA-F=resourceType DATA-FILE-ID=CDP.EL2> 500 * @see BaseType#enumStrList(String) 501 */ 502 public final String resourceType; 503 504 /** 505 * Response error if intercepted at response stage. 506 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 507 * <EMBED CLASS='external-html' DATA-D=Network DATA-C=ErrorReason DATA-F=responseErrorReason DATA-FILE-ID=CDP.EL2> 508 * @see BaseType#enumStrList(String) 509 */ 510 public final String responseErrorReason; 511 512 /** 513 * Response code if intercepted at response stage. 514 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 515 */ 516 public final Integer responseStatusCode; 517 518 /** 519 * Response status text if intercepted at response stage. 520 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 521 */ 522 public final String responseStatusText; 523 524 /** 525 * Response headers if intercepted at the response stage. 526 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 527 */ 528 public final Fetch.HeaderEntry[] responseHeaders; 529 530 /** 531 * If the intercepted request had a corresponding Network.requestWillBeSent event fired for it, 532 * then this networkId will be the same as the requestId present in the requestWillBeSent event. 533 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 534 */ 535 public final String networkId; 536 537 /** 538 * If the request is due to a redirect response from the server, the id of the request that 539 * has caused the redirect. 540 * <BR /><B CLASS=Opt-Top>OPTIONAL</B><B CLASS=Exp-Top>EXPERIMENTAL</B> 541 */ 542 public final String redirectedRequestId; 543 544 /** Constructor. Please review this class' fields for documentation. */ 545 public requestPaused( 546 ReadOnlyList<Boolean> isPresent, String requestId, Network.Request request, 547 String frameId, String resourceType, String responseErrorReason, 548 Integer responseStatusCode, String responseStatusText, 549 HeaderEntry[] responseHeaders, String networkId, String redirectedRequestId 550 ) 551 { 552 super(singleton, Domains.Fetch, "requestPaused", 10); 553 554 this.requestId = requestId; 555 this.request = request; 556 this.frameId = frameId; 557 this.resourceType = resourceType; 558 this.responseErrorReason = responseErrorReason; 559 this.responseStatusCode = responseStatusCode; 560 this.responseStatusText = responseStatusText; 561 this.responseHeaders = responseHeaders; 562 this.networkId = networkId; 563 this.redirectedRequestId = redirectedRequestId; 564 565 this.isPresent = (isPresent == null) 566 ? singleton.generateIsPresentList(this) 567 : THROWS.check(isPresent, 10, "Fetch.requestPaused"); 568 } 569 570 /** Creates an instance of this class from a {@link JsonObject}.*/ 571 public static requestPaused fromJSON(JsonObject jo) 572 { return singleton.fromJSON(jo); } 573 574 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 575 public static NestedDescriptor<requestPaused> descriptor() 576 { return singleton.descriptor(); } 577 } 578 579 580 581 582 // ******************************************************************************************** 583 // ******************************************************************************************** 584 // Commands 585 // ******************************************************************************************** 586 // ******************************************************************************************** 587 588 589 /** 590 * Continues the request, optionally modifying some of its parameters. 591 * 592 * <BR /><BR /><DIV CLASS=JDHint> 593 * 👍 Because of the sheer number of input parameters to this method, there is a 594 * a {@link CommandBuilder} variant to this method which may be invoked instead. 595 * 596 * <BR /><BR /> 597 * Please View: {@link #continueRequest()} 598 * </DIV> 599 * 600 * @param requestId An id the client received in requestPaused event. 601 * 602 * @param url If set, the request url will be modified in a way that's not observable by page. 603 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 604 * 605 * @param method If set, the request method is overridden. 606 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 607 * 608 * @param postData If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON) 609 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 610 * 611 * @param headers 612 * If set, overrides the request headers. Note that the overrides do not 613 * extend to subsequent redirect hops, if a redirect happens. Another override 614 * may be applied to a different request produced by a redirect. 615 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 616 * 617 * @param interceptResponse If set, overrides response interception behavior for this request. 618 * <BR /><B CLASS=Opt-Top>OPTIONAL</B><B CLASS=Exp-Top>EXPERIMENTAL</B> 619 * 620 * @return An instance of <CODE>{@link Script}<Void></CODE> 621 * 622 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 623 * browser receives the invocation-request. 624 * 625 * <BR /><BR /><DIV CLASS=JDHint> 626 * This Browser-Function <I>does not have</I> a return-value. You may choose to 627 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 628 * the Browser Function has run to completion. 629 * </DIV> 630 */ 631 public static Script<Void> continueRequest( 632 String requestId, String url, String method, String postData, HeaderEntry[] headers, 633 Boolean interceptResponse 634 ) 635 { 636 // Convert all Method Parameters into a JSON Request-Object (as a String) 637 final String requestJSON = WriteJSON.get( 638 Fetch$$Commands.continueRequest$$, "Fetch.continueRequest", 639 requestId, url, method, postData, headers, interceptResponse 640 ); 641 642 return Script.NO_RET(Domains.Fetch, "continueRequest", requestJSON); 643 } 644 645 /** 646 * Continues loading of the paused response, optionally modifying the 647 * response headers. If either responseCode or headers are modified, all of them 648 * must be present. 649 * 650 * <BR /><B CLASS=Exp-Top>EXPERIMENTAL</B> 651 * 652 * <BR /><BR /><DIV CLASS=JDHint> 653 * 👍 Because of the sheer number of input parameters to this method, there is a 654 * a {@link CommandBuilder} variant to this method which may be invoked instead. 655 * 656 * <BR /><BR /> 657 * Please View: {@link #continueResponse()} 658 * </DIV> 659 * 660 * @param requestId An id the client received in requestPaused event. 661 * 662 * @param responseCode An HTTP response code. If absent, original response code will be used. 663 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 664 * 665 * @param responsePhrase 666 * A textual representation of responseCode. 667 * If absent, a standard phrase matching responseCode is used. 668 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 669 * 670 * @param responseHeaders Response headers. If absent, original response headers will be used. 671 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 672 * 673 * @param binaryResponseHeaders 674 * Alternative way of specifying response headers as a \0-separated 675 * series of name: value pairs. Prefer the above method unless you 676 * need to represent some non-UTF8 values that can't be transmitted 677 * over the protocol as text. (Encoded as a base64 string when passed over JSON) 678 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 679 * 680 * @return An instance of <CODE>{@link Script}<Void></CODE> 681 * 682 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 683 * browser receives the invocation-request. 684 * 685 * <BR /><BR /><DIV CLASS=JDHint> 686 * This Browser-Function <I>does not have</I> a return-value. You may choose to 687 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 688 * the Browser Function has run to completion. 689 * </DIV> 690 */ 691 public static Script<Void> continueResponse( 692 String requestId, Integer responseCode, String responsePhrase, 693 HeaderEntry[] responseHeaders, String binaryResponseHeaders 694 ) 695 { 696 // Convert all Method Parameters into a JSON Request-Object (as a String) 697 final String requestJSON = WriteJSON.get( 698 Fetch$$Commands.continueResponse$$, "Fetch.continueResponse", 699 requestId, responseCode, responsePhrase, responseHeaders, binaryResponseHeaders 700 ); 701 702 return Script.NO_RET(Domains.Fetch, "continueResponse", requestJSON); 703 } 704 705 /** 706 * Continues a request supplying authChallengeResponse following authRequired event. 707 * 708 * @param requestId An id the client received in authRequired event. 709 * 710 * @param authChallengeResponse Response to with an authChallenge. 711 * 712 * @return An instance of <CODE>{@link Script}<Void></CODE> 713 * 714 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 715 * browser receives the invocation-request. 716 * 717 * <BR /><BR /><DIV CLASS=JDHint> 718 * This Browser-Function <I>does not have</I> a return-value. You may choose to 719 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 720 * the Browser Function has run to completion. 721 * </DIV> 722 */ 723 public static Script<Void> continueWithAuth 724 (String requestId, AuthChallengeResponse authChallengeResponse) 725 { 726 // Convert all Method Parameters into a JSON Request-Object (as a String) 727 final String requestJSON = WriteJSON.get( 728 Fetch$$Commands.continueWithAuth$$, "Fetch.continueWithAuth", 729 requestId, authChallengeResponse 730 ); 731 732 return Script.NO_RET(Domains.Fetch, "continueWithAuth", requestJSON); 733 } 734 735 /** 736 * Disables the fetch domain. 737 * 738 * @return An instance of <CODE>{@link Script}<Void></CODE> 739 * 740 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 741 * browser receives the invocation-request. 742 * 743 * <BR /><BR /><DIV CLASS=JDHint> 744 * This Browser-Function <I>does not have</I> a return-value. You may choose to 745 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 746 * the Browser Function has run to completion. 747 * </DIV> 748 */ 749 public static Script<Void> disable() 750 { 751 // Ultra-Simple Request JSON - Because this method has no parameters 752 final String requestJSON = "{\"method\":\"Fetch.disable\"}"; 753 754 return Script.NO_RET(Domains.Fetch, "disable", requestJSON); 755 } 756 757 /** 758 * Enables issuing of requestPaused events. A request will be paused until client 759 * calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth. 760 * 761 * @param patterns 762 * If specified, only requests matching any of these patterns will produce 763 * fetchRequested event and will be paused until clients response. If not set, 764 * all requests will be affected. 765 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 766 * 767 * @param handleAuthRequests 768 * If true, authRequired events will be issued and requests will be paused 769 * expecting a call to continueWithAuth. 770 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 771 * 772 * @return An instance of <CODE>{@link Script}<Void></CODE> 773 * 774 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 775 * browser receives the invocation-request. 776 * 777 * <BR /><BR /><DIV CLASS=JDHint> 778 * This Browser-Function <I>does not have</I> a return-value. You may choose to 779 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 780 * the Browser Function has run to completion. 781 * </DIV> 782 */ 783 public static Script<Void> enable(RequestPattern[] patterns, Boolean handleAuthRequests) 784 { 785 // Convert all Method Parameters into a JSON Request-Object (as a String) 786 final String requestJSON = WriteJSON.get( 787 Fetch$$Commands.enable$$, "Fetch.enable", 788 patterns, handleAuthRequests 789 ); 790 791 return Script.NO_RET(Domains.Fetch, "enable", requestJSON); 792 } 793 794 /** 795 * Causes the request to fail with specified reason. 796 * 797 * @param requestId An id the client received in requestPaused event. 798 * 799 * @param errorReason Causes the request to fail with the given reason. 800 * 801 * @return An instance of <CODE>{@link Script}<Void></CODE> 802 * 803 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 804 * browser receives the invocation-request. 805 * 806 * <BR /><BR /><DIV CLASS=JDHint> 807 * This Browser-Function <I>does not have</I> a return-value. You may choose to 808 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 809 * the Browser Function has run to completion. 810 * </DIV> 811 */ 812 public static Script<Void> failRequest(String requestId, String errorReason) 813 { 814 // Convert all Method Parameters into a JSON Request-Object (as a String) 815 final String requestJSON = WriteJSON.get( 816 Fetch$$Commands.failRequest$$, "Fetch.failRequest", 817 requestId, errorReason 818 ); 819 820 return Script.NO_RET(Domains.Fetch, "failRequest", requestJSON); 821 } 822 823 /** 824 * Provides response to the request. 825 * 826 * <BR /><BR /><DIV CLASS=JDHint> 827 * 👍 Because of the sheer number of input parameters to this method, there is a 828 * a {@link CommandBuilder} variant to this method which may be invoked instead. 829 * 830 * <BR /><BR /> 831 * Please View: {@link #fulfillRequest()} 832 * </DIV> 833 * 834 * @param requestId An id the client received in requestPaused event. 835 * 836 * @param responseCode An HTTP response code. 837 * 838 * @param responseHeaders Response headers. 839 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 840 * 841 * @param binaryResponseHeaders 842 * Alternative way of specifying response headers as a \0-separated 843 * series of name: value pairs. Prefer the above method unless you 844 * need to represent some non-UTF8 values that can't be transmitted 845 * over the protocol as text. (Encoded as a base64 string when passed over JSON) 846 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 847 * 848 * @param body 849 * A response body. If absent, original response body will be used if 850 * the request is intercepted at the response stage and empty body 851 * will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON) 852 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 853 * 854 * @param responsePhrase 855 * A textual representation of responseCode. 856 * If absent, a standard phrase matching responseCode is used. 857 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 858 * 859 * @return An instance of <CODE>{@link Script}<Void></CODE> 860 * 861 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 862 * browser receives the invocation-request. 863 * 864 * <BR /><BR /><DIV CLASS=JDHint> 865 * This Browser-Function <I>does not have</I> a return-value. You may choose to 866 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 867 * the Browser Function has run to completion. 868 * </DIV> 869 */ 870 public static Script<Void> fulfillRequest( 871 String requestId, int responseCode, HeaderEntry[] responseHeaders, 872 String binaryResponseHeaders, String body, String responsePhrase 873 ) 874 { 875 // Convert all Method Parameters into a JSON Request-Object (as a String) 876 final String requestJSON = WriteJSON.get( 877 Fetch$$Commands.fulfillRequest$$, "Fetch.fulfillRequest", 878 requestId, responseCode, responseHeaders, binaryResponseHeaders, body, responsePhrase 879 ); 880 881 return Script.NO_RET(Domains.Fetch, "fulfillRequest", requestJSON); 882 } 883 884 /** 885 * Causes the body of the response to be received from the server and 886 * returned as a single string. May only be issued for a request that 887 * is paused in the Response stage and is mutually exclusive with 888 * takeResponseBodyForInterceptionAsStream. Calling other methods that 889 * affect the request or disabling fetch domain before body is received 890 * results in an undefined behavior. 891 * Note that the response body is not available for redirects. Requests 892 * paused in the _redirect received_ state may be differentiated by 893 * <CODE>responseCode</CODE> and presence of <CODE>location</CODE> response header, see 894 * comments to <CODE>requestPaused</CODE> for details. 895 * 896 * @param requestId Identifier for the intercepted request to get body for. 897 * 898 * @return An instance of <CODE>{@link Script}<{@link getResponseBody$$RET}></CODE> 899 * 900 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 901 * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise} 902 * <CODE><{@link getResponseBody$$RET}></CODE> will be returned 903 * 904 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 905 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 906 * be retrieved.</I> 907 * 908 * <BR /><BR /><DIV CLASS=JDHint> 909 * This Browser Function's {@code Promise} returns:{@link getResponseBody$$RET} 910 * A dedicated return type implies that the browser may return more than 1 datum 911 * </DIV> 912 */ 913 public static Script<getResponseBody$$RET> getResponseBody(String requestId) 914 { 915 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 916 final String requestJSON = WriteJSON.get 917 (CDPTypes.STRING, "requestId", false, "Fetch.getResponseBody", requestId); 918 919 return new Script<>( 920 Domains.Fetch, "getResponseBody", requestJSON, 921 getResponseBody$$RET::fromJSON, 922 getResponseBody$$RET.class 923 ); 924 } 925 926 /** 927 * Returns a handle to the stream representing the response body. 928 * The request must be paused in the HeadersReceived stage. 929 * Note that after this command the request can't be continued 930 * as is -- client either needs to cancel it or to provide the 931 * response body. 932 * The stream only supports sequential read, IO.read will fail if the position 933 * is specified. 934 * This method is mutually exclusive with getResponseBody. 935 * Calling other methods that affect the request or disabling fetch 936 * domain before body is received results in an undefined behavior. 937 * 938 * @param requestId - 939 * 940 * @return An instance of <CODE>{@link Script}<String></CODE> 941 * 942 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 943 * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise} 944 * <CODE><String></CODE> will be returned 945 * 946 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 947 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 948 * be retrieved.</I> 949 * 950 * <BR /><BR /><DIV CLASS=JDHint> 951 * This Browser Function's {@code Promise} returns: 952 * <CODE>String (<B>stream</B>)</CODE> 953 * </DIV> 954 */ 955 public static Script<String> takeResponseBodyAsStream(String requestId) 956 { 957 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 958 final String requestJSON = WriteJSON.get 959 (CDPTypes.STRING, "requestId", false, "Fetch.takeResponseBodyAsStream", requestId); 960 961 return new Script<>( 962 Domains.Fetch, "takeResponseBodyAsStream", requestJSON, 963 jo -> ReadJSON.getString(jo, "stream", true, false), 964 String.class 965 ); 966 } 967 968 969 // ******************************************************************************************** 970 // ******************************************************************************************** 971 // CommandBuilder Getter-Methods 972 // ******************************************************************************************** 973 // ******************************************************************************************** 974 975 976 /** 977 * Creates a buider for conveniently assigning parameters to this method. 978 * 979 * <BR /><BR /><DIV CLASS=JDHint> 980 * Note that the original method expects 6 parameters, and can be cumbersome. 981 * </DIV> 982 * 983 * @return {@link CommandBuilder} instance, for assigning parameter values, one by one. 984 * @see #continueRequest 985 */ 986 public static CommandBuilder<Void> continueRequest() 987 { return CommandBuilder.builder(Fetch$$Commands.continueRequest$$); } 988 989 /** 990 * Creates a buider for conveniently assigning parameters to this method. 991 * 992 * <BR /><BR /><DIV CLASS=JDHint> 993 * Note that the original method expects 5 parameters, and can be cumbersome. 994 * </DIV> 995 * 996 * @return {@link CommandBuilder} instance, for assigning parameter values, one by one. 997 * @see #continueResponse 998 */ 999 public static CommandBuilder<Void> continueResponse() 1000 { return CommandBuilder.builder(Fetch$$Commands.continueResponse$$); } 1001 1002 /** 1003 * Creates a buider for conveniently assigning parameters to this method. 1004 * 1005 * <BR /><BR /><DIV CLASS=JDHint> 1006 * Note that the original method expects 6 parameters, and can be cumbersome. 1007 * </DIV> 1008 * 1009 * @return {@link CommandBuilder} instance, for assigning parameter values, one by one. 1010 * @see #fulfillRequest 1011 */ 1012 public static CommandBuilder<Void> fulfillRequest() 1013 { return CommandBuilder.builder(Fetch$$Commands.fulfillRequest$$); } 1014 1015 1016}