Fetch Commands
Fetch commands provide network request handling and interception capabilities using the Fetch API domain.
The fetch commands module enables network request management, including request modification, response interception, and authentication handling.
pydoll.commands.fetch_commands
FetchCommands
This class encapsulates the fetch commands of the Chrome DevTools Protocol (CDP).
CDP's Fetch domain allows interception and modification of network requests at the application layer. This enables developers to examine, modify, and control network traffic, which is particularly useful for testing, debugging, and advanced automation scenarios.
The commands defined in this class provide functionality for: - Enabling and disabling fetch request interception - Continuing, fulfilling, or failing intercepted requests - Handling authentication challenges - Retrieving and modifying response bodies - Processing response data as streams
continue_request
staticmethod
continue_request(request_id, url=None, method=None, post_data=None, headers=None, intercept_response=None)
Creates a command to continue a paused fetch request.
This command allows the browser to resume a fetch operation that has been intercepted. You can modify the fetch request URL, method, headers, and body before continuing.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to continue.
TYPE:
|
url
|
The new URL for the fetch request. Defaults to None.
TYPE:
|
method
|
The HTTP method to use (e.g., 'GET', 'POST'). Defaults to None.
TYPE:
|
post_data
|
The body data to send with the fetch request. Defaults to None.
TYPE:
|
headers
|
A list of HTTP headers to include in the fetch request. Defaults to None.
TYPE:
|
intercept_response
|
Indicates if the response should be intercepted. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContinueRequestCommand
|
Command[Response]: A command for continuing the fetch request. |
continue_request_with_auth
staticmethod
continue_request_with_auth(request_id, auth_challenge_response, proxy_username=None, proxy_password=None)
Creates a command to continue a paused fetch request with authentication.
This command is used when the fetch operation requires authentication. It provides the necessary credentials to continue the request.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to continue.
TYPE:
|
auth_challenge_response
|
The authentication challenge response type. |
proxy_username
|
The username for proxy authentication. Defaults to None.
TYPE:
|
proxy_password
|
The password for proxy authentication. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContinueWithAuthCommand
|
Command[Response]: A command for continuing the fetch request with authentication. |
disable
staticmethod
Creates a command to disable fetch interception.
This command stops the browser from intercepting fetch requests.
| RETURNS | DESCRIPTION |
|---|---|
DisableCommand
|
Command[Response]: A command for disabling fetch interception. |
enable
staticmethod
Creates a command to enable fetch interception.
This command allows the browser to start intercepting fetch requests. You can specify whether to handle authentication challenges and the types of resources to intercept.
| PARAMETER | DESCRIPTION |
|---|---|
handle_auth_requests
|
Indicates if authentication requests should be handled.
TYPE:
|
url_pattern
|
Pattern to match URLs for interception. Defaults to '*'.
TYPE:
|
resource_type
|
The type of resource to intercept. Defaults to None.
TYPE:
|
request_stage
|
The stage of the request to intercept. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EnableCommand
|
Command[Response]: A command for enabling fetch interception. |
fail_request
staticmethod
Creates a command to simulate a failure in a fetch request.
This command allows you to simulate a failure for a specific fetch operation, providing a reason for the failure.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to fail.
TYPE:
|
error_reason
|
The reason for the failure.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FailRequestCommand
|
Command[Response]: A command for failing the fetch request. |
fulfill_request
staticmethod
Creates a command to fulfill a fetch request with a custom response.
This command allows you to provide a custom response for a fetch operation, including the HTTP status code, headers, and body content.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to fulfill.
TYPE:
|
response_code
|
The HTTP status code to return.
TYPE:
|
response_headers
|
A list of response headers. Defaults to None.
TYPE:
|
body
|
The body content of the response. Defaults to None.
TYPE:
|
response_phrase
|
The response phrase (e.g., 'OK', 'Not Found'). Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FulfillRequestCommand
|
Command[Response]: A command for fulfilling the fetch request. |
get_response_body
staticmethod
Creates a command to retrieve the response body of a fetch request.
This command allows you to access the body of a completed fetch operation, which can be useful for analyzing the response data.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to retrieve the body from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GetResponseBodyCommand
|
Command[GetResponseBodyResponse]: A command for getting the response body. |
continue_response
staticmethod
Creates a command to continue a fetch response for an intercepted request.
This command allows the browser to continue the response flow for a specific fetch request, including customizing the HTTP status code, headers, and response phrase.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to continue the response for.
TYPE:
|
response_code
|
The HTTP status code to send. Defaults to None.
TYPE:
|
response_headers
|
A list of response headers. Defaults to None.
TYPE:
|
response_phrase
|
The response phrase (e.g., 'OK'). Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContinueResponseCommand
|
Command[Response]: A command for continuing the fetch response. |
take_response_body_as_stream
staticmethod
Creates a command to take the response body as a stream.
This command allows you to receive the response body as a stream which can be useful for handling large responses.
| PARAMETER | DESCRIPTION |
|---|---|
request_id
|
The ID of the fetch request to take the response body stream from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TakeResponseBodyAsStreamCommand
|
Command[TakeResponseBodyAsStreamResponse]: A command for taking the response body as a stream. |