fetch
AuthChallenge
dataclass
Authorization challenge for HTTP status code 401 or 407.
Source code in zendriver/cdp/fetch.py
origin: str
instance-attribute
realm: str
instance-attribute
scheme: str
instance-attribute
source: typing.Optional[str] = None
class-attribute
instance-attribute
__init__(origin, scheme, realm, source=None)
from_json(json)
classmethod
Source code in zendriver/cdp/fetch.py
AuthChallengeResponse
dataclass
Response to an AuthChallenge.
Source code in zendriver/cdp/fetch.py
password: typing.Optional[str] = None
class-attribute
instance-attribute
response: str
instance-attribute
username: typing.Optional[str] = None
class-attribute
instance-attribute
__init__(response, username=None, password=None)
from_json(json)
classmethod
Source code in zendriver/cdp/fetch.py
to_json()
Source code in zendriver/cdp/fetch.py
AuthRequired
dataclass
Issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.
Source code in zendriver/cdp/fetch.py
auth_challenge: AuthChallenge
instance-attribute
frame_id: page.FrameId
instance-attribute
request: network.Request
instance-attribute
request_id: RequestId
instance-attribute
resource_type: network.ResourceType
instance-attribute
__init__(request_id, request, frame_id, resource_type, auth_challenge)
from_json(json)
classmethod
Source code in zendriver/cdp/fetch.py
HeaderEntry
dataclass
Response HTTP header entry
Source code in zendriver/cdp/fetch.py
name: str
instance-attribute
value: str
instance-attribute
__init__(name, value)
from_json(json)
classmethod
RequestId
Bases: str
Unique request identifier. Note that this does not identify individual HTTP requests that are part of a network request.
Source code in zendriver/cdp/fetch.py
__repr__()
from_json(json)
classmethod
RequestPattern
dataclass
Source code in zendriver/cdp/fetch.py
request_stage: typing.Optional[RequestStage] = None
class-attribute
instance-attribute
resource_type: typing.Optional[network.ResourceType] = None
class-attribute
instance-attribute
url_pattern: typing.Optional[str] = None
class-attribute
instance-attribute
__init__(url_pattern=None, resource_type=None, request_stage=None)
from_json(json)
classmethod
Source code in zendriver/cdp/fetch.py
to_json()
Source code in zendriver/cdp/fetch.py
RequestPaused
dataclass
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.
Source code in zendriver/cdp/fetch.py
frame_id: page.FrameId
instance-attribute
network_id: typing.Optional[network.RequestId]
instance-attribute
redirected_request_id: typing.Optional[RequestId]
instance-attribute
request: network.Request
instance-attribute
request_id: RequestId
instance-attribute
resource_type: network.ResourceType
instance-attribute
response_error_reason: typing.Optional[network.ErrorReason]
instance-attribute
response_headers: typing.Optional[typing.List[HeaderEntry]]
instance-attribute
response_status_code: typing.Optional[int]
instance-attribute
response_status_text: typing.Optional[str]
instance-attribute
__init__(request_id, request, frame_id, resource_type, response_error_reason, response_status_code, response_status_text, response_headers, network_id, redirected_request_id)
from_json(json)
classmethod
Source code in zendriver/cdp/fetch.py
RequestStage
Bases: Enum
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).
Source code in zendriver/cdp/fetch.py
REQUEST = 'Request'
class-attribute
instance-attribute
RESPONSE = 'Response'
class-attribute
instance-attribute
from_json(json)
classmethod
continue_request(request_id, url=None, method=None, post_data=None, headers=None, intercept_response=None)
Continues the request, optionally modifying some of its parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
An id the client received in requestPaused event. |
required |
url
|
Optional[str]
|
(Optional) If set, the request url will be modified in a way that's not observable by page. |
None
|
method
|
Optional[str]
|
(Optional) If set, the request method is overridden. |
None
|
post_data
|
Optional[str]
|
(Optional) If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON) |
None
|
headers
|
Optional[List[HeaderEntry]]
|
(Optional) 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. |
None
|
intercept_response
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) If set, overrides response interception behavior for this request. |
None
|
Source code in zendriver/cdp/fetch.py
continue_response(request_id, response_code=None, response_phrase=None, response_headers=None, binary_response_headers=None)
Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
An id the client received in requestPaused event. |
required |
response_code
|
Optional[int]
|
(Optional) An HTTP response code. If absent, original response code will be used. |
None
|
response_phrase
|
Optional[str]
|
(Optional) A textual representation of responseCode. If absent, a standard phrase matching responseCode is used. |
None
|
response_headers
|
Optional[List[HeaderEntry]]
|
(Optional) Response headers. If absent, original response headers will be used. |
None
|
binary_response_headers
|
Optional[str]
|
(Optional) 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) |
None
|
Source code in zendriver/cdp/fetch.py
continue_with_auth(request_id, auth_challenge_response)
Continues a request supplying authChallengeResponse following authRequired event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
An id the client received in authRequired event. |
required |
auth_challenge_response
|
AuthChallengeResponse
|
Response to with an authChallenge. |
required |
Source code in zendriver/cdp/fetch.py
disable()
enable(patterns=None, handle_auth_requests=None)
Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patterns
|
Optional[List[RequestPattern]]
|
(Optional) 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. |
None
|
handle_auth_requests
|
Optional[bool]
|
(Optional) If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth. |
None
|
Source code in zendriver/cdp/fetch.py
fail_request(request_id, error_reason)
Causes the request to fail with specified reason.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
An id the client received in requestPaused event. |
required |
error_reason
|
ErrorReason
|
Causes the request to fail with the given reason. |
required |
Source code in zendriver/cdp/fetch.py
fulfill_request(request_id, response_code, response_headers=None, binary_response_headers=None, body=None, response_phrase=None)
Provides response to the request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
An id the client received in requestPaused event. |
required |
response_code
|
int
|
An HTTP response code. |
required |
response_headers
|
Optional[List[HeaderEntry]]
|
(Optional) Response headers. |
None
|
binary_response_headers
|
Optional[str]
|
(Optional) 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) |
None
|
body
|
Optional[str]
|
(Optional) 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) |
None
|
response_phrase
|
Optional[str]
|
(Optional) A textual representation of responseCode. If absent, a standard phrase matching responseCode is used. |
None
|
Source code in zendriver/cdp/fetch.py
get_response_body(request_id)
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:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
Identifier for the intercepted request to get body for. |
required |
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, Tuple[str, bool]]
|
A tuple with the following items: 0. body - Response body. 1. base64Encoded - True, if content was sent as base64. |
Source code in zendriver/cdp/fetch.py
take_response_body_as_stream(request_id)
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:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
RequestId
|
|
required |
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, StreamHandle]
|
|