mokr.network.manager.chrome
Attributes
Classes
Class to handle requests in a given |
Module Contents
- mokr.network.manager.chrome.LOGGER
- class mokr.network.manager.chrome.ChromeNetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable])
Bases:
mokr.network.manager.base.NetworkManagerClass to handle requests in a given
mokr.browser.Page.This class relies on network events to be emitted, and stores events and even requests to handle the various possible chains of events.
The
interception_callback_chainthis class receives from the parentmokr.browser.Pageis shared with spawnedmokr.network.Requestobjects. While the request interception callback chain is run from theRequestobject, it is initiated during select events from this class.There are four possible orders that requests will be triggered and thus handled by
NetworkManager:_on_request_will_be_sent._on_request_will_be_sent,_on_request_paused._on_request_paused,_on_request_will_be_sent._on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_paused(see crbug.com/1196004).
There are a few different ways requests need to be handled due to this: - For
_on_requestwe need the event from_on_request_will_be_sentand optionally thefetch_request_id(event[“requestId”] also known as “interceptionId”) from_on_request_paused. - If request interception is disabled, call_on_requestonce per call to_on_request_will_be_sent. - If request interception is enabled, call_on_requestonce per call to_on_request_paused(once perfetch_request_id). - Events are stored via themokr.network.NetworkEventManagerto allow for subsequent events to call_on_request. - Chains of redirect requests have the samerequestIdas the original request. This means events can be received in multiple orders for different requests in the same redirect chain such as:_on_request_will_be_sent,_on_request_will_be_sent, …_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused, …
_on_request_will_be_sent,_on_request_paused,_on_request_paused,_on_request_will_be_sent, …
_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_paused, … (see crbug.com/1196004)
- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.browser.Page.frame_manager (FrameManager) – The
mokr.frame.FrameManagerfrom themokr.browser.Pagethat spawned this element.interception_callback_chain (list[Callable]) – A list of callbacks to be passed into new
mokr.network.Request`s that will be run during "request" event interception, by that object. Inherited from the parent `mokr.browser.Page.
- property extra_http_headers: dict[str, str]
Any extra HTTP headers assigned to this class. These are sent with every request this manager handles.
- forget_request(request: mokr.network.request.Request, events: bool) None
Drop a request from the
mokr.network.NetworkEventManagerand remove from attempted authentications listing, if relevant.Optionally forget all events tied to the remote request networkID, too.
- Parameters:
request (Request) –
mokr.request.Requestto forget.events (bool) – If True, drop all events stored for the request, too.
- get_in_flight_requests_count() int
Get the number of active requests (not resolved). Wraps
mokr.network.NetworkEventManager.get_in_flight_requests_count.- Returns:
Number of active requests.
- Return type:
int
- async set_credentials(credentials: dict[Literal['username', 'password'], str]) None
Set the credentials to use for HTTP authentication.
- Parameters:
credentials (dict[str, str]) – A dictionary with credentials, keyed as “username” and “password”.
- async set_extra_http_headers(extra_http_headers: dict[str, str]) None
Set extra headers to be sent with every request.
- Parameters:
extra_http_headers (dict[str, str]) – A dictionary of headers.
- Raises:
ValueError – Raised if any header value is not string.
- async set_request_interception(choice: bool) None
Disable or enabled request interception (enabled by default). See
mokr.browser.Page.onfor details on using the request interception callback chain.- Parameters:
choice (bool) – False to disable, True to enable.