Fetch Domain
A domain for letting clients substitute browser's network layer with client code.
Methods
- Fetch.continueRequest
- Fetch.continueWithAuth
- Fetch.disable
- Fetch.enable
- Fetch.failRequest
- Fetch.fulfillRequest
- Fetch.getResponseBody
- Fetch.takeResponseBodyAsStream
- Fetch.continueResponse Experimental
Events
Types
Methods
Fetch.continueRequest #
Continues the request, optionally modifying some of its parameters.
Parameters
requestId
An id the client received in requestPaused event.
url
Optional
string
If set, the request url will be modified in a way that's not observable by page.
method
Optional
string
If set, the request method is overridden.
postData
Optional
string
If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)
headers
Optional
array[ HeaderEntry ]
If set, overrides the request headers. Note that the overrides do not extend to subsequent redirect hops, if a redirect happens. Another override may be applied to a different request produced by a redirect.
interceptResponse
Optional
boolean
If set, overrides response interception behavior for this request.
Fetch.continueWithAuth #
Continues a request supplying authChallengeResponse following authRequired event.
Parameters
requestId
An id the client received in authRequired event.
authChallengeResponse
Response to with an authChallenge.
Fetch.enable #
Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
Parameters
patterns
Optional
array[ RequestPattern ]
If specified, only requests matching any of these patterns will produce fetchRequested event and will be paused until clients response. If not set, all requests will be affected.
handleAuthRequests
Optional
boolean
If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth.
Fetch.failRequest #
Causes the request to fail with specified reason.
Parameters
requestId
An id the client received in requestPaused event.
errorReason
Causes the request to fail with the given reason.
Fetch.fulfillRequest #
Provides response to the request.
Parameters
requestId
An id the client received in requestPaused event.
responseCode
integer
An HTTP response code.
responseHeaders
Optional
array[ HeaderEntry ]
Response headers.
binaryResponseHeaders
Optional
string
Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)
body
Optional
string
A response body. If absent, original response body will be used if the request is intercepted at the response stage and empty body will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)
responsePhrase
Optional
string
A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.
Fetch.getResponseBody #
Causes the body of the response to be received from the server and
returned as a single string. May only be issued for a request that
is paused in the Response stage and is mutually exclusive with
takeResponseBodyForInterceptionAsStream. Calling other methods that
affect the request or disabling fetch domain before body is received
results in an undefined behavior.
Note that the response body is not available for redirects. Requests
paused in the redirect received state may be differentiated by
responseCode
and presence of location
response header, see
comments to requestPaused
for details.
Parameters
requestId
Identifier for the intercepted request to get body for.
Return object
body
string
Response body.
base64Encoded
boolean
True, if content was sent as base64.
Fetch.takeResponseBodyAsStream #
Returns a handle to the stream representing the response body. The request must be paused in the HeadersReceived stage. Note that after this command the request can't be continued as is -- client either needs to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified. This method is mutually exclusive with getResponseBody. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.
Parameters
requestId
Return object
stream
Fetch.continueResponse Experimental#
Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.
Parameters
requestId
An id the client received in requestPaused event.
responseCode
Optional
integer
An HTTP response code. If absent, original response code will be used.
responsePhrase
Optional
string
A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.
responseHeaders
Optional
array[ HeaderEntry ]
Response headers. If absent, original response headers will be used.
binaryResponseHeaders
Optional
string
Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)
Events
Fetch.authRequired #
Issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.
Parameters
requestId
Each request the page makes will have a unique id.
request
The details of the request.
frameId
The id of the frame that initiated the request.
resourceType
How the requested resource will be used.
authChallenge
Details of the Authorization Challenge encountered. If this is set, client should respond with continueRequest that contains AuthChallengeResponse.
Fetch.requestPaused #
Issued when the domain is enabled and the request URL matches the
specified filter. The request is paused until the client responds
with one of continueRequest, failRequest or fulfillRequest.
The stage of the request can be determined by presence of responseErrorReason
and responseStatusCode -- the request is at the response stage if either
of these fields is present and in the request stage otherwise.
Redirect responses and subsequent requests are reported similarly to regular
responses and requests. Redirect responses may be distinguished by the value
of responseStatusCode
(which is one of 301, 302, 303, 307, 308) along with
presence of the location
header. Requests resulting from a redirect will
have redirectedRequestId
field set.
Parameters
requestId
Each request the page makes will have a unique id.
request
The details of the request.
frameId
The id of the frame that initiated the request.
resourceType
How the requested resource will be used.
responseErrorReason
Optional
Response error if intercepted at response stage.
responseStatusCode
Optional
integer
Response code if intercepted at response stage.
responseStatusText
Optional
string
Response status text if intercepted at response stage.
responseHeaders
Optional
array[ HeaderEntry ]
Response headers if intercepted at the response stage.
networkId
Optional
If the intercepted request had a corresponding Network.requestWillBeSent event fired for it, then this networkId will be the same as the requestId present in the requestWillBeSent event.
redirectedRequestId
Optional
If the request is due to a redirect response from the server, the id of the request that has caused the redirect.
Types
Fetch.AuthChallenge #
Authorization challenge for HTTP status code 401 or 407.
Type: object
Properties
source
Optional
string
Source of the authentication challenge.
Allowed values: Server
, Proxy
origin
string
Origin of the challenger.
scheme
string
The authentication scheme used, such as basic or digest
realm
string
The realm of the challenge. May be empty.
Fetch.AuthChallengeResponse #
Response to an AuthChallenge.
Type: object
Properties
response
string
The decision on what to do in response to the authorization challenge. Default means deferring to the default behavior of the net stack, which will likely either the Cancel authentication or display a popup dialog box.
Allowed values: Default
, CancelAuth
, ProvideCredentials
username
Optional
string
The username to provide, possibly empty. Should only be set if response is ProvideCredentials.
password
Optional
string
The password to provide, possibly empty. Should only be set if response is ProvideCredentials.
Fetch.RequestPattern #
Type: object
Properties
urlPattern
Optional
string
Wildcards ('*'
-> zero or more, '?'
-> exactly one) are allowed. Escape character is
backslash. Omitting is equivalent to "*"
.
resourceType
Optional
If set, only requests for matching resource types will be intercepted.
requestStage
Optional
Stage at which to begin intercepting requests. Default is Request.
Fetch.RequestStage #
Stages of the request to handle. Request will intercept before the request is sent. Response will intercept after the response is received (but before response body is received).
Type: string
Allowed values: Request
, Response