Network¶
Network domain allows tracking network activities of the page. It exposes information about http, file, data and other requests and responses, their headers, bodies, timing, etc.
Types¶
Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.
-
class
cdp.network.
ResourceType
¶ Resource type as it was perceived by the rendering engine.
-
CSP_VIOLATION_REPORT
= 'CSPViolationReport'¶
-
DOCUMENT
= 'Document'¶
-
EVENT_SOURCE
= 'EventSource'¶
-
FETCH
= 'Fetch'¶
-
FONT
= 'Font'¶
-
IMAGE
= 'Image'¶
-
MANIFEST
= 'Manifest'¶
-
MEDIA
= 'Media'¶
-
OTHER
= 'Other'¶
-
PING
= 'Ping'¶
-
SCRIPT
= 'Script'¶
-
SIGNED_EXCHANGE
= 'SignedExchange'¶
-
STYLESHEET
= 'Stylesheet'¶
-
TEXT_TRACK
= 'TextTrack'¶
-
WEB_SOCKET
= 'WebSocket'¶
-
XHR
= 'XHR'¶
-
-
class
cdp.network.
LoaderId
¶ Unique loader identifier.
-
class
cdp.network.
RequestId
¶ Unique request identifier.
-
class
cdp.network.
InterceptionId
¶ Unique intercepted request identifier.
-
class
cdp.network.
ErrorReason
¶ Network level fetch failure reason.
-
ABORTED
= 'Aborted'¶
-
ACCESS_DENIED
= 'AccessDenied'¶
-
ADDRESS_UNREACHABLE
= 'AddressUnreachable'¶
-
BLOCKED_BY_CLIENT
= 'BlockedByClient'¶
-
BLOCKED_BY_RESPONSE
= 'BlockedByResponse'¶
-
CONNECTION_ABORTED
= 'ConnectionAborted'¶
-
CONNECTION_CLOSED
= 'ConnectionClosed'¶
-
CONNECTION_FAILED
= 'ConnectionFailed'¶
-
CONNECTION_REFUSED
= 'ConnectionRefused'¶
-
CONNECTION_RESET
= 'ConnectionReset'¶
-
FAILED
= 'Failed'¶
-
INTERNET_DISCONNECTED
= 'InternetDisconnected'¶
-
NAME_NOT_RESOLVED
= 'NameNotResolved'¶
-
TIMED_OUT
= 'TimedOut'¶
-
-
class
cdp.network.
TimeSinceEpoch
¶ UTC time in seconds, counted from January 1, 1970.
-
class
cdp.network.
MonotonicTime
¶ Monotonically increasing time in seconds since an arbitrary point in the past.
-
class
cdp.network.
Headers
¶ Request / response headers as keys / values of JSON object.
-
class
cdp.network.
ConnectionType
¶ The underlying connection technology that the browser is supposedly using.
-
BLUETOOTH
= 'bluetooth'¶
-
CELLULAR2G
= 'cellular2g'¶
-
CELLULAR3G
= 'cellular3g'¶
-
CELLULAR4G
= 'cellular4g'¶
-
ETHERNET
= 'ethernet'¶
-
NONE
= 'none'¶
-
OTHER
= 'other'¶
-
WIFI
= 'wifi'¶
-
WIMAX
= 'wimax'¶
-
-
class
cdp.network.
CookieSameSite
¶ Represents the cookie’s ‘SameSite’ status: https://tools.ietf.org/html/draft-west-first-party-cookies
-
EXTENDED
= 'Extended'¶
-
LAX
= 'Lax'¶
-
NONE
= 'None'¶
-
STRICT
= 'Strict'¶
-
-
class
cdp.network.
ResourceTiming
(request_time, proxy_start, proxy_end, dns_start, dns_end, connect_start, connect_end, ssl_start, ssl_end, worker_start, worker_ready, send_start, send_end, push_start, push_end, receive_headers_end)¶ Timing information for the request.
-
connect_end
= None¶ Connected to the remote host.
-
connect_start
= None¶ Started connecting to the remote host.
-
dns_end
= None¶ Finished DNS address resolve.
-
dns_start
= None¶ Started DNS address resolve.
-
proxy_end
= None¶ Finished resolving proxy.
-
proxy_start
= None¶ Started resolving proxy.
-
push_end
= None¶ Time the server finished pushing request.
-
push_start
= None¶ Time the server started pushing request.
-
receive_headers_end
= None¶ Finished receiving response headers.
-
request_time
= None¶ Timing’s requestTime is a baseline in seconds, while the other numbers are ticks in milliseconds relatively to this requestTime.
-
send_end
= None¶ Finished sending request.
-
send_start
= None¶ Started sending request.
-
ssl_end
= None¶ Finished SSL handshake.
-
ssl_start
= None¶ Started SSL handshake.
-
worker_ready
= None¶ Finished Starting ServiceWorker.
-
worker_start
= None¶ Started running ServiceWorker.
-
-
class
cdp.network.
ResourcePriority
¶ Loading priority of a resource request.
-
HIGH
= 'High'¶
-
LOW
= 'Low'¶
-
MEDIUM
= 'Medium'¶
-
VERY_HIGH
= 'VeryHigh'¶
-
VERY_LOW
= 'VeryLow'¶
-
-
class
cdp.network.
Request
(url, method, headers, initial_priority, referrer_policy, url_fragment=None, post_data=None, has_post_data=None, mixed_content_type=None, is_link_preload=None)¶ HTTP request data.
-
has_post_data
= None¶ True when the request has POST data. Note that postData might still be omitted when this flag is true when the data is too long.
-
headers
= None¶ HTTP request headers.
-
initial_priority
= None¶ Priority of the resource request at the time request is sent.
-
is_link_preload
= None¶ Whether is loaded via link preload.
-
method
= None¶ HTTP request method.
-
mixed_content_type
= None¶ The mixed content type of the request.
-
post_data
= None¶ HTTP POST request data.
-
referrer_policy
= None¶ The referrer policy of the request, as defined in https://www.w3.org/TR/referrer-policy/
-
url
= None¶ Request URL (without fragment).
-
url_fragment
= None¶ Fragment of the requested URL starting with hash, if present.
-
-
class
cdp.network.
SignedCertificateTimestamp
(status, origin, log_description, log_id, timestamp, hash_algorithm, signature_algorithm, signature_data)¶ Details of a signed certificate timestamp (SCT).
-
hash_algorithm
= None¶ Hash algorithm.
-
log_description
= None¶ Log name / description.
-
log_id
= None¶ Log ID.
-
origin
= None¶ Origin.
-
signature_algorithm
= None¶ Signature algorithm.
-
signature_data
= None¶ Signature data.
-
status
= None¶ Validation status.
-
timestamp
= None¶ Issuance date.
-
-
class
cdp.network.
SecurityDetails
(protocol, key_exchange, cipher, certificate_id, subject_name, san_list, issuer, valid_from, valid_to, signed_certificate_timestamp_list, certificate_transparency_compliance, key_exchange_group=None, mac=None)¶ Security details about a request.
-
certificate_id
= None¶ Certificate ID value.
-
certificate_transparency_compliance
= None¶ Whether the request complied with Certificate Transparency policy
-
cipher
= None¶ Cipher name.
-
issuer
= None¶ Name of the issuing CA.
-
key_exchange
= None¶ Key Exchange used by the connection, or the empty string if not applicable.
-
key_exchange_group
= None¶ (EC)DH group used by the connection, if applicable.
-
mac
= None¶ TLS MAC. Note that AEAD ciphers do not have separate MACs.
-
protocol
= None¶ Protocol name (e.g. “TLS 1.2” or “QUIC”).
-
san_list
= None¶ Subject Alternative Name (SAN) DNS names and IP addresses.
-
signed_certificate_timestamp_list
= None¶ List of signed certificate timestamps (SCTs).
-
subject_name
= None¶ Certificate subject name.
-
valid_from
= None¶ Certificate valid from date.
-
valid_to
= None¶ Certificate valid to (expiration) date
-
-
class
cdp.network.
CertificateTransparencyCompliance
¶ Whether the request complied with Certificate Transparency policy.
-
COMPLIANT
= 'compliant'¶
-
NOT_COMPLIANT
= 'not-compliant'¶
-
UNKNOWN
= 'unknown'¶
-
-
class
cdp.network.
BlockedReason
¶ The reason why request was blocked.
-
COLLAPSED_BY_CLIENT
= 'collapsed-by-client'¶
-
CONTENT_TYPE
= 'content-type'¶
-
CSP
= 'csp'¶
-
INSPECTOR
= 'inspector'¶
-
MIXED_CONTENT
= 'mixed-content'¶
-
ORIGIN
= 'origin'¶
-
OTHER
= 'other'¶
-
SUBRESOURCE_FILTER
= 'subresource-filter'¶
-
-
class
cdp.network.
Response
(url, status, status_text, headers, mime_type, connection_reused, connection_id, encoded_data_length, security_state, headers_text=None, request_headers=None, request_headers_text=None, remote_ip_address=None, remote_port=None, from_disk_cache=None, from_service_worker=None, from_prefetch_cache=None, timing=None, protocol=None, security_details=None)¶ HTTP response data.
-
connection_id
= None¶ Physical connection id that was actually used for this request.
-
connection_reused
= None¶ Specifies whether physical connection was actually reused for this request.
-
encoded_data_length
= None¶ Total number of bytes received for this request so far.
-
from_disk_cache
= None¶ Specifies that the request was served from the disk cache.
-
from_prefetch_cache
= None¶ Specifies that the request was served from the prefetch cache.
-
from_service_worker
= None¶ Specifies that the request was served from the ServiceWorker.
-
headers
= None¶ HTTP response headers.
-
headers_text
= None¶ HTTP response headers text.
-
mime_type
= None¶ Resource mimeType as determined by the browser.
-
protocol
= None¶ Protocol used to fetch this request.
-
remote_ip_address
= None¶ Remote IP address.
-
remote_port
= None¶ Remote port.
-
request_headers
= None¶ Refined HTTP request headers that were actually transmitted over the network.
-
request_headers_text
= None¶ HTTP request headers text.
-
security_details
= None¶ Security details for the request.
-
security_state
= None¶ Security state of the request resource.
-
status
= None¶ HTTP response status code.
-
status_text
= None¶ HTTP response status text.
-
timing
= None¶ Timing information for the given request.
-
url
= None¶ Response URL. This URL can be different from CachedResource.url in case of redirect.
-
-
class
cdp.network.
WebSocketRequest
(headers)¶ WebSocket request data.
-
headers
= None¶ HTTP request headers.
-
-
class
cdp.network.
WebSocketResponse
(status, status_text, headers, headers_text=None, request_headers=None, request_headers_text=None)¶ WebSocket response data.
-
headers
= None¶ HTTP response headers.
-
headers_text
= None¶ HTTP response headers text.
-
request_headers
= None¶ HTTP request headers.
-
request_headers_text
= None¶ HTTP request headers text.
-
status
= None¶ HTTP response status code.
-
status_text
= None¶ HTTP response status text.
-
-
class
cdp.network.
WebSocketFrame
(opcode, mask, payload_data)¶ WebSocket message data. This represents an entire WebSocket message, not just a fragmented frame as the name suggests.
-
mask
= None¶ WebSocket message mask.
-
opcode
= None¶ WebSocket message opcode.
-
payload_data
= None¶ WebSocket message payload data. If the opcode is 1, this is a text message and payloadData is a UTF-8 string. If the opcode isn’t 1, then payloadData is a base64 encoded string representing binary data.
-
-
class
cdp.network.
CachedResource
(url, type_, body_size, response=None)¶ Information about the cached resource.
-
body_size
= None¶ Cached response body size.
-
response
= None¶ Cached response data.
-
type_
= None¶ Type of this resource.
-
url
= None¶ Resource URL. This is the url of the original network request.
-
-
class
cdp.network.
Initiator
(type_, stack=None, url=None, line_number=None)¶ Information about the request initiator.
-
line_number
= None¶ Initiator line number, set for Parser type or for Script type (when script is importing module) (0-based).
-
stack
= None¶ Initiator JavaScript stack trace, set for Script only.
-
type_
= None¶ Type of this initiator.
-
url
= None¶ Initiator URL, set for Parser type or for Script type (when script is importing module) or for SignedExchange type.
-
-
class
cdp.network.
Cookie
(name, value, domain, path, expires, size, http_only, secure, session, same_site=None)¶ Cookie object
-
domain
= None¶ Cookie domain.
-
expires
= None¶ Cookie expiration date as the number of seconds since the UNIX epoch.
-
http_only
= None¶ True if cookie is http-only.
-
name
= None¶ Cookie name.
-
path
= None¶ Cookie path.
-
same_site
= None¶ Cookie SameSite type.
-
secure
= None¶ True if cookie is secure.
-
session
= None¶ True in case of session cookie.
-
size
= None¶ Cookie size.
-
value
= None¶ Cookie value.
-
-
class
cdp.network.
SetCookieBlockedReason
¶ Types of reasons why a cookie may not be stored from a response.
-
INVALID_DOMAIN
= 'InvalidDomain'¶
-
INVALID_PREFIX
= 'InvalidPrefix'¶
-
OVERWRITE_SECURE
= 'OverwriteSecure'¶
-
SAME_SITE_EXTENDED
= 'SameSiteExtended'¶
-
SAME_SITE_LAX
= 'SameSiteLax'¶
-
SAME_SITE_NONE_INSECURE
= 'SameSiteNoneInsecure'¶
-
SAME_SITE_STRICT
= 'SameSiteStrict'¶
-
SAME_SITE_UNSPECIFIED_TREATED_AS_LAX
= 'SameSiteUnspecifiedTreatedAsLax'¶
-
SCHEME_NOT_SUPPORTED
= 'SchemeNotSupported'¶
-
SECURE_ONLY
= 'SecureOnly'¶
-
SYNTAX_ERROR
= 'SyntaxError'¶
-
UNKNOWN_ERROR
= 'UnknownError'¶
-
USER_PREFERENCES
= 'UserPreferences'¶
-
-
class
cdp.network.
CookieBlockedReason
¶ Types of reasons why a cookie may not be sent with a request.
-
DOMAIN_MISMATCH
= 'DomainMismatch'¶
-
NOT_ON_PATH
= 'NotOnPath'¶
-
SAME_SITE_EXTENDED
= 'SameSiteExtended'¶
-
SAME_SITE_LAX
= 'SameSiteLax'¶
-
SAME_SITE_NONE_INSECURE
= 'SameSiteNoneInsecure'¶
-
SAME_SITE_STRICT
= 'SameSiteStrict'¶
-
SAME_SITE_UNSPECIFIED_TREATED_AS_LAX
= 'SameSiteUnspecifiedTreatedAsLax'¶
-
SECURE_ONLY
= 'SecureOnly'¶
-
UNKNOWN_ERROR
= 'UnknownError'¶
-
USER_PREFERENCES
= 'UserPreferences'¶
-
-
class
cdp.network.
BlockedSetCookieWithReason
(blocked_reason, cookie_line, cookie=None)¶ A cookie which was not stored from a response with the corresponding reason.
-
blocked_reason
= None¶ The reason this cookie was blocked.
The cookie object which represents the cookie which was not stored. It is optional because sometimes complete cookie information is not available, such as in the case of parsing errors.
The string representing this individual cookie as it would appear in the header. This is not the entire “cookie” or “set-cookie” header which could have multiple cookies.
-
-
class
cdp.network.
BlockedCookieWithReason
(blocked_reason, cookie)¶ A cookie with was not sent with a request with the corresponding reason.
-
blocked_reason
= None¶ The reason the cookie was blocked.
The cookie object representing the cookie which was not sent.
-
-
class
cdp.network.
CookieParam
(name, value, url=None, domain=None, path=None, secure=None, http_only=None, same_site=None, expires=None)¶ Cookie parameter object
-
domain
= None¶ Cookie domain.
-
expires
= None¶ Cookie expiration date, session cookie if not set
-
http_only
= None¶ True if cookie is http-only.
-
name
= None¶ Cookie name.
-
path
= None¶ Cookie path.
-
same_site
= None¶ Cookie SameSite type.
-
secure
= None¶ True if cookie is secure.
-
url
= None¶ The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie.
-
value
= None¶ Cookie value.
-
-
class
cdp.network.
AuthChallenge
(origin, scheme, realm, source=None)¶ Authorization challenge for HTTP status code 401 or 407.
-
origin
= None¶ Origin of the challenger.
-
realm
= None¶ The realm of the challenge. May be empty.
-
scheme
= None¶ The authentication scheme used, such as basic or digest
-
source
= None¶ Source of the authentication challenge.
-
-
class
cdp.network.
AuthChallengeResponse
(response, username=None, password=None)¶ Response to an AuthChallenge.
-
password
= None¶ The password to provide, possibly empty. Should only be set if response is ProvideCredentials.
-
response
= None¶ 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.
-
username
= None¶ The username to provide, possibly empty. Should only be set if response is ProvideCredentials.
-
-
class
cdp.network.
InterceptionStage
¶ Stages of the interception to begin intercepting. Request will intercept before the request is sent. Response will intercept after the response is received.
-
HEADERS_RECEIVED
= 'HeadersReceived'¶
-
REQUEST
= 'Request'¶
-
-
class
cdp.network.
RequestPattern
(url_pattern=None, resource_type=None, interception_stage=None)¶ Request pattern for interception.
-
interception_stage
= None¶ Stage at wich to begin intercepting requests. Default is Request.
-
resource_type
= None¶ If set, only requests for matching resource types will be intercepted.
-
url_pattern
= None¶ Wildcards (‘*’ -> zero or more, ‘?’ -> exactly one) are allowed. Escape character is backslash. Omitting is equivalent to “*”.
-
-
class
cdp.network.
SignedExchangeSignature
(label, signature, integrity, validity_url, date, expires, cert_url=None, cert_sha256=None, certificates=None)¶ Information about a signed exchange signature. https://wicg.github.io/webpackage/draft-yasskin-httpbis-origin-signed-exchanges-impl.html#rfc.section.3.1
-
cert_sha256
= None¶ The hex string of signed exchange signature cert sha256.
-
cert_url
= None¶ Signed exchange signature cert Url.
-
certificates
= None¶ The encoded certificates.
-
date
= None¶ Signed exchange signature date.
-
expires
= None¶ Signed exchange signature expires.
-
integrity
= None¶ Signed exchange signature integrity.
-
label
= None¶ Signed exchange signature label.
-
signature
= None¶ The hex string of signed exchange signature.
-
validity_url
= None¶ Signed exchange signature validity Url.
-
-
class
cdp.network.
SignedExchangeHeader
(request_url, response_code, response_headers, signatures, header_integrity)¶ Information about a signed exchange header. https://wicg.github.io/webpackage/draft-yasskin-httpbis-origin-signed-exchanges-impl.html#cbor-representation
-
header_integrity
= None¶ Signed exchange header integrity hash in the form of “sha256-<base64-hash-value>”.
-
request_url
= None¶ Signed exchange request URL.
-
response_code
= None¶ Signed exchange response code.
-
response_headers
= None¶ Signed exchange response headers.
-
signatures
= None¶ Signed exchange response signature.
-
-
class
cdp.network.
SignedExchangeErrorField
¶ Field type for a signed exchange related error.
-
SIGNATURE_CERT_SHA256
= 'signatureCertSha256'¶
-
SIGNATURE_CERT_URL
= 'signatureCertUrl'¶
-
SIGNATURE_INTEGRITY
= 'signatureIntegrity'¶
-
SIGNATURE_SIG
= 'signatureSig'¶
-
SIGNATURE_TIMESTAMPS
= 'signatureTimestamps'¶
-
SIGNATURE_VALIDITY_URL
= 'signatureValidityUrl'¶
-
-
class
cdp.network.
SignedExchangeError
(message, signature_index=None, error_field=None)¶ Information about a signed exchange response.
-
error_field
= None¶ The field which caused the error.
-
message
= None¶ Error message.
-
signature_index
= None¶ The index of the signature which caused the error.
-
-
class
cdp.network.
SignedExchangeInfo
(outer_response, header=None, security_details=None, errors=None)¶ Information about a signed exchange response.
-
errors
= None¶ Errors occurred while handling the signed exchagne.
-
header
= None¶ Information about the signed exchange header.
-
outer_response
= None¶ The outer response of signed HTTP exchange which was received from network.
-
security_details
= None¶ Security details for the signed exchange header.
-
Commands¶
Each command is a generator function. The return
type Generator[x, y, z]
indicates that the generator
yields arguments of type x
, it must be resumed with
an argument of type y
, and it returns type z
. In
this library, types x
and y
are the same for all
commands, and z
is the return type you should pay attention
to. For more information, see
Getting Started: Commands.
-
cdp.network.
can_clear_browser_cache
()¶ Tells whether clearing browser cache is supported.
Deprecated since version 1.3.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],bool
]Returns: True if browser cache can be cleared. Deprecated since version 1.3.
Tells whether clearing browser cookies is supported.
Deprecated since version 1.3.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],bool
]Returns: True if browser cookies can be cleared. Deprecated since version 1.3.
-
cdp.network.
can_emulate_network_conditions
()¶ Tells whether emulation of network conditions is supported.
Deprecated since version 1.3.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],bool
]Returns: True if emulation of network conditions is supported. Deprecated since version 1.3.
-
cdp.network.
clear_browser_cache
()¶ Clears browser cache.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
Clears browser cookies.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
continue_intercepted_request
(interception_id, error_reason=None, raw_response=None, url=None, method=None, post_data=None, headers=None, auth_challenge_response=None)¶ Response to Network.requestIntercepted which either modifies the request to continue with any modifications, or blocks it, or completes it with the provided response bytes. If a network fetch occurs as a result which encounters a redirect an additional Network.requestIntercepted event will be sent with the same InterceptionId. Deprecated, use Fetch.continueRequest, Fetch.fulfillRequest and Fetch.failRequest instead.
Deprecated since version 1.3.
EXPERIMENTAL
Parameters: - interception_id (
InterceptionId
) – - error_reason (
Optional
[ErrorReason
]) – (Optional) If set this causes the request to fail with the given reason. Passing`Aborted``
for requests marked with``isNavigationRequest`
also cancels the navigation. Must not be set in response to an authChallenge. - raw_response (
Optional
[str
]) – (Optional) If set the requests completes using with the provided base64 encoded raw response, including HTTP status line and headers etc… Must not be set in response to an authChallenge. - url (
Optional
[str
]) – (Optional) If set the request url will be modified in a way that’s not observable by page. Must not be set in response to an authChallenge. - method (
Optional
[str
]) – (Optional) If set this allows the request method to be overridden. Must not be set in response to an authChallenge. - post_data (
Optional
[str
]) – (Optional) If set this allows postData to be set. Must not be set in response to an authChallenge. - headers (
Optional
[Headers
]) – (Optional) If set this allows the request headers to be changed. Must not be set in response to an authChallenge. - auth_challenge_response (
Optional
[AuthChallengeResponse
]) – (Optional) Response to a requestIntercepted with an authChallenge. Must not be set otherwise.
Deprecated since version 1.3.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- interception_id (
Deletes browser cookies with matching name and url or domain/path pair.
Parameters: - name (
str
) – Name of the cookies to remove. - url (
Optional
[str
]) – (Optional) If specified, deletes all the cookies with the given name where domain and path match provided URL. - domain (
Optional
[str
]) – (Optional) If specified, deletes only cookies with the exact domain. - path (
Optional
[str
]) – (Optional) If specified, deletes only cookies with the exact path.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- name (
-
cdp.network.
disable
()¶ Disables network tracking, prevents network events from being sent to the client.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
emulate_network_conditions
(offline, latency, download_throughput, upload_throughput, connection_type=None)¶ Activates emulation of network conditions.
Parameters: - offline (
bool
) – True to emulate internet disconnection. - latency (
float
) – Minimum latency from request sent to response headers received (ms). - download_throughput (
float
) – Maximal aggregated download throughput (bytes/sec). -1 disables download throttling. - upload_throughput (
float
) – Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling. - connection_type (
Optional
[ConnectionType
]) – (Optional) Connection type if known.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- offline (
-
cdp.network.
enable
(max_total_buffer_size=None, max_resource_buffer_size=None, max_post_data_size=None)¶ Enables network tracking, network events will now be delivered to the client.
Parameters: - max_total_buffer_size (
Optional
[int
]) – (EXPERIMENTAL) (Optional) Buffer size in bytes to use when preserving network payloads (XHRs, etc). - max_resource_buffer_size (
Optional
[int
]) – (EXPERIMENTAL) (Optional) Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc). - max_post_data_size (
Optional
[int
]) – (Optional) Longest post body size (in bytes) that would be included in requestWillBeSent notification
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- max_total_buffer_size (
Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the
cookies
field.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],List
[Cookie
]]Returns: Array of cookie objects.
-
cdp.network.
get_certificate
(origin)¶ Returns the DER-encoded certificate.
EXPERIMENTAL
Parameters: origin ( str
) – Origin to get certificate for.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],List
[str
]]Returns:
Returns all browser cookies for the current URL. Depending on the backend support, will return detailed cookie information in the
cookies
field.Parameters: urls ( Optional
[List
[str
]]) – (Optional) The list of URLs for which applicable cookies will be fetchedReturn type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],List
[Cookie
]]Returns: Array of cookie objects.
-
cdp.network.
get_request_post_data
(request_id)¶ Returns post data sent with the request. Returns an error when no data was sent with the request.
Parameters: request_id ( RequestId
) – Identifier of the network request to get content for.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],str
]Returns: Request body string, omitting files from multipart requests
-
cdp.network.
get_response_body
(request_id)¶ Returns content served for the given request.
Parameters: request_id ( RequestId
) – Identifier of the network request to get content for.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],Tuple
[str
,bool
]]Returns: A tuple with the following items: - body - Response body.
- base64Encoded - True, if content was sent as base64.
-
cdp.network.
get_response_body_for_interception
(interception_id)¶ Returns content served for the given currently intercepted request.
EXPERIMENTAL
Parameters: interception_id ( InterceptionId
) – Identifier for the intercepted request to get body for.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],Tuple
[str
,bool
]]Returns: A tuple with the following items: - body - Response body.
- base64Encoded - True, if content was sent as base64.
-
cdp.network.
replay_xhr
(request_id)¶ This method sends a new XMLHttpRequest which is identical to the original one. The following parameters should be identical: method, url, async, request body, extra headers, withCredentials attribute, user, password.
EXPERIMENTAL
Parameters: request_id ( RequestId
) – Identifier of XHR to replay.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
search_in_response_body
(request_id, query, case_sensitive=None, is_regex=None)¶ Searches for given string in response content.
EXPERIMENTAL
Parameters: - request_id (
RequestId
) – Identifier of the network response to search. - query (
str
) – String to search for. - case_sensitive (
Optional
[bool
]) – (Optional) If true, search is case sensitive. - is_regex (
Optional
[bool
]) – (Optional) If true, treats string parameter as regex.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],List
[SearchMatch
]]Returns: List of search matches.
- request_id (
-
cdp.network.
set_blocked_ur_ls
(urls)¶ Blocks URLs from loading.
EXPERIMENTAL
Parameters: urls ( List
[str
]) – URL patterns to block. Wildcards (‘*’) are allowed.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
set_bypass_service_worker
(bypass)¶ Toggles ignoring of service worker for each request.
EXPERIMENTAL
Parameters: bypass ( bool
) – Bypass service worker and load from network.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
set_cache_disabled
(cache_disabled)¶ Toggles ignoring cache for each request. If
true
, cache will not be used.Parameters: cache_disabled ( bool
) – Cache disabled state.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
Parameters: - name (
str
) – Cookie name. - value (
str
) – Cookie value. - url (
Optional
[str
]) – (Optional) The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie. - domain (
Optional
[str
]) – (Optional) Cookie domain. - path (
Optional
[str
]) – (Optional) Cookie path. - secure (
Optional
[bool
]) – (Optional) True if cookie is secure. - http_only (
Optional
[bool
]) – (Optional) True if cookie is http-only. - same_site (
Optional
[CookieSameSite
]) – (Optional) Cookie SameSite type. - expires (
Optional
[TimeSinceEpoch
]) – (Optional) Cookie expiration date, session cookie if not set
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],bool
]Returns: True if successfully set cookie.
- name (
Sets given cookies.
Parameters: cookies ( List
[CookieParam
]) – Cookies to be set.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
set_data_size_limits_for_test
(max_total_size, max_resource_size)¶ For testing.
EXPERIMENTAL
Parameters: - max_total_size (
int
) – Maximum total buffer size. - max_resource_size (
int
) – Maximum per-resource size.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- max_total_size (
-
cdp.network.
set_extra_http_headers
(headers)¶ Specifies whether to always send extra HTTP headers with the requests from this page.
Parameters: headers ( Headers
) – Map with extra HTTP headers.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
set_request_interception
(patterns)¶ Sets the requests to intercept that match the provided patterns and optionally resource types. Deprecated, please use Fetch.enable instead.
Deprecated since version 1.3.
EXPERIMENTAL
Parameters: patterns ( List
[RequestPattern
]) – Requests matching any of these patterns will be forwarded and wait for the corresponding continueInterceptedRequest call.Deprecated since version 1.3.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.network.
set_user_agent_override
(user_agent, accept_language=None, platform=None)¶ Allows overriding user agent with the given string.
Parameters: - user_agent (
str
) – User agent to use. - accept_language (
Optional
[str
]) – (Optional) Browser langugage to emulate. - platform (
Optional
[str
]) – (Optional) The platform navigator.platform should return.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- user_agent (
-
cdp.network.
take_response_body_for_interception_as_stream
(interception_id)¶ Returns a handle to the stream representing the response body. Note that after this command, the intercepted request can’t be continued as is – you either need to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified.
EXPERIMENTAL
Parameters: interception_id ( InterceptionId
) –Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],StreamHandle
]Returns:
Events¶
Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.
-
class
cdp.network.
DataReceived
(request_id, timestamp, data_length, encoded_data_length)¶ Fired when data chunk was received over the network.
-
data_length
= None¶ Data chunk length.
-
encoded_data_length
= None¶ Actual bytes received (might be less than dataLength for compressed encodings).
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
EventSourceMessageReceived
(request_id, timestamp, event_name, event_id, data)¶ Fired when EventSource message is received.
-
data
= None¶ Message content.
-
event_id
= None¶ Message identifier.
-
event_name
= None¶ Message type.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
LoadingFailed
(request_id, timestamp, type_, error_text, canceled, blocked_reason)¶ Fired when HTTP request has failed to load.
-
blocked_reason
= None¶ The reason why loading was blocked, if any.
-
canceled
= None¶ True if loading was canceled.
-
error_text
= None¶ User friendly error message.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
type_
= None¶ Resource type.
-
-
class
cdp.network.
LoadingFinished
(request_id, timestamp, encoded_data_length, should_report_corb_blocking)¶ Fired when HTTP request has finished loading.
-
encoded_data_length
= None¶ Total number of bytes received for this request.
-
request_id
= None¶ Request identifier.
-
should_report_corb_blocking
= None¶ Set when 1) response was blocked by Cross-Origin Read Blocking and also 2) this needs to be reported to the DevTools console.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
RequestIntercepted
(interception_id, request, frame_id, resource_type, is_navigation_request, is_download, redirect_url, auth_challenge, response_error_reason, response_status_code, response_headers, request_id)¶ EXPERIMENTAL
Details of an intercepted HTTP request, which must be either allowed, blocked, modified or mocked. Deprecated, use Fetch.requestPaused instead.
Deprecated since version 1.3.
-
auth_challenge
= None¶ Details of the Authorization Challenge encountered. If this is set then continueInterceptedRequest must contain an authChallengeResponse.
-
frame_id
= None¶ The id of the frame that initiated the request.
-
interception_id
= None¶ Each request the page makes will have a unique id, however if any redirects are encountered while processing that fetch, they will be reported with the same id as the original fetch. Likewise if HTTP authentication is needed then the same fetch id will be used.
-
is_download
= None¶ Set if the request is a navigation that will result in a download. Only present after response is received from the server (i.e. HeadersReceived stage).
Whether this is a navigation request, which can abort the navigation completely.
-
redirect_url
= None¶ Redirect location, only sent if a redirect was intercepted.
-
request_id
= None¶ If the intercepted request had a corresponding requestWillBeSent event fired for it, then this requestId will be the same as the requestId present in the requestWillBeSent event.
-
resource_type
= None¶ How the requested resource will be used.
-
response_error_reason
= None¶ Response error if intercepted at response stage or if redirect occurred while intercepting request.
-
response_headers
= None¶ Response headers if intercepted at the response stage or if redirect occurred while intercepting request or auth retry occurred.
-
response_status_code
= None¶ Response code if intercepted at response stage or if redirect occurred while intercepting request or auth retry occurred.
-
-
class
cdp.network.
RequestServedFromCache
(request_id)¶ Fired if request ended up loading from cache.
-
request_id
= None¶ Request identifier.
-
-
class
cdp.network.
RequestWillBeSent
(request_id, loader_id, document_url, request, timestamp, wall_time, initiator, redirect_response, type_, frame_id, has_user_gesture)¶ Fired when page is about to send HTTP request.
-
document_url
= None¶ URL of the document this request is loaded for.
-
frame_id
= None¶ Frame identifier.
-
has_user_gesture
= None¶ Whether the request is initiated by a user gesture. Defaults to false.
-
initiator
= None¶ Request initiator.
-
loader_id
= None¶ Loader identifier. Empty string if the request is fetched from worker.
-
redirect_response
= None¶ Redirect response data.
-
request
= None¶ Request data.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
type_
= None¶ Type of this resource.
-
wall_time
= None¶ Timestamp.
-
-
class
cdp.network.
ResourceChangedPriority
(request_id, new_priority, timestamp)¶ EXPERIMENTAL
Fired when resource loading priority is changed
-
new_priority
= None¶ New priority
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
SignedExchangeReceived
(request_id, info)¶ EXPERIMENTAL
Fired when a signed exchange was received over the network
-
info
= None¶ Information about the signed exchange response.
-
request_id
= None¶ Request identifier.
-
-
class
cdp.network.
ResponseReceived
(request_id, loader_id, timestamp, type_, response, frame_id)¶ Fired when HTTP response is available.
-
frame_id
= None¶ Frame identifier.
-
loader_id
= None¶ Loader identifier. Empty string if the request is fetched from worker.
-
request_id
= None¶ Request identifier.
-
response
= None¶ Response data.
-
timestamp
= None¶ Timestamp.
-
type_
= None¶ Resource type.
-
-
class
cdp.network.
WebSocketClosed
(request_id, timestamp)¶ Fired when WebSocket is closed.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
WebSocketCreated
(request_id, url, initiator)¶ Fired upon WebSocket creation.
-
initiator
= None¶ Request initiator.
-
request_id
= None¶ Request identifier.
-
url
= None¶ WebSocket request URL.
-
-
class
cdp.network.
WebSocketFrameError
(request_id, timestamp, error_message)¶ Fired when WebSocket message error occurs.
-
error_message
= None¶ WebSocket error message.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
WebSocketFrameReceived
(request_id, timestamp, response)¶ Fired when WebSocket message is received.
-
request_id
= None¶ Request identifier.
-
response
= None¶ WebSocket response data.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
WebSocketFrameSent
(request_id, timestamp, response)¶ Fired when WebSocket message is sent.
-
request_id
= None¶ Request identifier.
-
response
= None¶ WebSocket response data.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
WebSocketHandshakeResponseReceived
(request_id, timestamp, response)¶ Fired when WebSocket handshake response becomes available.
-
request_id
= None¶ Request identifier.
-
response
= None¶ WebSocket response data.
-
timestamp
= None¶ Timestamp.
-
-
class
cdp.network.
WebSocketWillSendHandshakeRequest
(request_id, timestamp, wall_time, request)¶ Fired when WebSocket is about to initiate handshake.
-
request
= None¶ WebSocket request data.
-
request_id
= None¶ Request identifier.
-
timestamp
= None¶ Timestamp.
-
wall_time
= None¶ UTC Timestamp.
-
-
class
cdp.network.
RequestWillBeSentExtraInfo
(request_id, blocked_cookies, headers)¶ EXPERIMENTAL
Fired when additional information about a requestWillBeSent event is available from the network stack. Not every requestWillBeSent event will have an additional requestWillBeSentExtraInfo fired for it, and there is no guarantee whether requestWillBeSent or requestWillBeSentExtraInfo will be fired first for the same request.
A list of cookies which will not be sent with this request along with corresponding reasons for blocking.
-
headers
= None¶ Raw request headers as they will be sent over the wire.
-
request_id
= None¶ Request identifier. Used to match this information to an existing requestWillBeSent event.
-
class
cdp.network.
ResponseReceivedExtraInfo
(request_id, blocked_cookies, headers, headers_text)¶ EXPERIMENTAL
Fired when additional information about a responseReceived event is available from the network stack. Not every responseReceived event will have an additional responseReceivedExtraInfo for it, and responseReceivedExtraInfo may be fired before or after responseReceived.
A list of cookies which were not stored from the response along with the corresponding reasons for blocking. The cookies here may not be valid due to syntax errors, which are represented by the invalid cookie line string instead of a proper cookie.
-
headers
= None¶ Raw response headers as they were received over the wire.
-
headers_text
= None¶ Raw response header text as it was received over the wire. The raw text may not always be available, such as in the case of HTTP/2 or QUIC.
-
request_id
= None¶ Request identifier. Used to match this information to another responseReceived event.