mokr.network.manager.base

Classes

NetworkManager

The base event emitter class. All other event emitters inherit from

Module Contents

class mokr.network.manager.base.NetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable])

Bases: pyee.EventEmitter

The base event emitter class. All other event emitters inherit from this class.

Most events are registered with an emitter via the on and once methods, and fired with the emit method. However, pyee event emitters have two special events:

  • new_listener: Fires whenever a new listener is created. Listeners for this event do not fire upon their own creation.

  • error: When emitted raises an Exception by default, behavior can be overridden by attaching callback to the event.

    For example:

```py @ee.on(‘error’) def on_error(message):

logging.err(message)

ee.emit(‘error’, Exception(‘something blew up’)) ```

All callbacks are handled in a synchronous, blocking manner. As in node.js, raised exceptions are not automatically handled for you—you must catch your own exceptions, and treat them accordingly.

credentials
user_agent = ''
user_agent_metadata = ''
classmethod create(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, ignore_https_errors: bool, interception_callback_chain: list[Callable]) NetworkManager
Async:

Async constructor for this class. Necessary to run some asyncronous post-initialisation tasks.

Parameters:
  • page (Page) – Parent mokr.browser.Page.

  • client (DevtoolsConnection) – A mokr.connection.DevtoolsConnection spawned by the parent mokr.browser.Page.

  • frame_manager (FrameManager) – A mokr.frame.FrameManager spawned by the parent mokr.browser.Page.

  • ignore_https_errors (bool) – Ignore site security errors. Inherited from parent mokr.browser.Page.

  • interception_callback_chain (list[Callable]) – A list of callables for use with “request” event interception. This list is shared by the parent mokr.browser.Page and all newly created mokr.network.Request objects in this manager.

Returns:

New NetworkManager with applied configurations.

Return type:

NetworkManager

abstract set_extra_http_headers() None
Async:

abstract set_request_interception() None
Async:

abstract set_credentials() None
Async:

async emulate_network_conditions(latency: int | None = 0, download: int | None = -1, upload: int | None = -1) None

Emulate the given network conditions. If network conditions unset, will set them to the default (disable all throttling and no latency).

Parameters:
  • latency (int, optional) – Minimum latency in milliseconds from request sent to response headers received. Defaults to None (0).

  • download (int, optional) – Maximum download throughput (bytes/sec). Defaults to None (-1, disabled).

  • upload (int, optional) – Minimum download throughput (bytes/sec). Defaults to None (-1, disabled).

async set_offline_mode(choice: bool) None

Enable or diable offline mode. Disabled by default.

Parameters:

enabled (bool) – False to disable, True to enable.

async set_request_cache(enabled: bool) None

Enable or disable request caching. Request caching caches requests in the browser, not mokr.network.Request objects.

Does not check if request caching was enabled already by parent mokr.browser.Page.

Parameters:

enabled (bool, optional) – True to enable, False to disable. Defaults to True.

async set_user_agent(user_agent: str, user_agent_metadata: str | None = None) None

Update the user agent to be sent with every request.

Parameters:
  • user_agent (str) – User agent string.

  • user_agent_metadata (str | None, optional) – Experimental, used to specify user agent client hints to emulate.