mokr.network.manager.chrome =========================== .. py:module:: mokr.network.manager.chrome Attributes ---------- .. autoapisummary:: mokr.network.manager.chrome.LOGGER Classes ------- .. autoapisummary:: mokr.network.manager.chrome.ChromeNetworkManager Module Contents --------------- .. py:data:: LOGGER .. py:class:: ChromeNetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable]) Bases: :py:obj:`mokr.network.manager.base.NetworkManager` Class 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_chain` this class receives from the parent `mokr.browser.Page` is shared with spawned `mokr.network.Request` objects. While the request interception callback chain is run from the `Request` object, 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_request` we need the event from `_on_request_will_be_sent` and optionally the `fetch_request_id` (event["requestId"] also known as "interceptionId") from `_on_request_paused`. - If request interception is disabled, call `_on_request` once per call to `_on_request_will_be_sent`. - If request interception is enabled, call `_on_request` once per call to `_on_request_paused` (once per `fetch_request_id`). - Events are stored via the `mokr.network.NetworkEventManager` to allow for subsequent events to call `_on_request`. - Chains of redirect requests have the same `requestId` as 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) :param page: Parent `mokr.browser.Page`. :type page: Page :param client: A `mokr.connection.DevtoolsConnection` spawned by the parent `mokr.browser.Page`. :type client: DevtoolsConnection :param frame_manager: The `mokr.frame.FrameManager` from the `mokr.browser.Page` that spawned this element. :type frame_manager: FrameManager :param interception_callback_chain: 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`. :type interception_callback_chain: list[Callable] .. py:property:: extra_http_headers :type: dict[str, str] Any extra HTTP headers assigned to this class. These are sent with every request this manager handles. .. py:method:: forget_request(request: mokr.network.request.Request, events: bool) -> None Drop a request from the `mokr.network.NetworkEventManager` and remove from attempted authentications listing, if relevant. Optionally forget all events tied to the remote request networkID, too. :param request: `mokr.request.Request` to forget. :type request: Request :param events: If True, drop all events stored for the request, too. :type events: bool .. py:method:: 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. :rtype: int .. py:method:: set_credentials(credentials: dict[Literal['username', 'password'], str]) -> None :async: Set the credentials to use for HTTP authentication. :param credentials: A dictionary with credentials, keyed as "username" and "password". :type credentials: dict[str, str] .. py:method:: set_extra_http_headers(extra_http_headers: dict[str, str]) -> None :async: Set extra headers to be sent with every request. :param extra_http_headers: A dictionary of headers. :type extra_http_headers: dict[str, str] :raises ValueError: Raised if any header value is not string. .. py:method:: set_request_interception(choice: bool) -> None :async: Disable or enabled request interception (enabled by default). See `mokr.browser.Page.on` for details on using the request interception callback chain. :param choice: False to disable, True to enable. :type choice: bool