mokr.network.manager.base
Module Contents
Classes
The base event emitter class. All other event emitters inherit from |
- 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.EventEmitterThe base event emitter class. All other event emitters inherit from this class.
Most events are registered with an emitter via the
onandoncemethods, and fired with theemitmethod. 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.
- async 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 constructor for this class. Necessary to run some asyncronous post-initialisation tasks.
- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.browser.Page.frame_manager (FrameManager) – A
mokr.frame.FrameManagerspawned by the parentmokr.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.Pageand all newly createdmokr.network.Requestobjects in this manager.
- Returns:
New
NetworkManagerwith applied configurations.- Return type:
- abstract async set_extra_http_headers() None
- abstract async set_request_interception() None
- abstract async set_credentials() None
- 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.Requestobjects.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.