mokr.network.manager.base ========================= .. py:module:: mokr.network.manager.base Classes ------- .. autoapisummary:: mokr.network.manager.base.NetworkManager Module Contents --------------- .. py:class:: NetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable]) Bases: :py:obj:`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. .. py:attribute:: credentials .. py:attribute:: user_agent :value: '' .. py:attribute:: user_agent_metadata :value: '' .. py:method:: 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 :classmethod: :async: Async constructor for this class. Necessary to run some asyncronous post-initialisation tasks. :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: A `mokr.frame.FrameManager` spawned by the parent `mokr.browser.Page`. :type frame_manager: FrameManager :param ignore_https_errors: Ignore site security errors. Inherited from parent `mokr.browser.Page`. :type ignore_https_errors: bool :param interception_callback_chain: 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. :type interception_callback_chain: list[Callable] :returns: New `NetworkManager` with applied configurations. :rtype: NetworkManager .. py:method:: set_extra_http_headers() -> None :abstractmethod: :async: .. py:method:: set_request_interception() -> None :abstractmethod: :async: .. py:method:: set_credentials() -> None :abstractmethod: :async: .. py:method:: emulate_network_conditions(latency: int | None = 0, download: int | None = -1, upload: int | None = -1) -> None :async: Emulate the given network conditions. If network conditions unset, will set them to the default (disable all throttling and no latency). :param latency: Minimum latency in milliseconds from request sent to response headers received. Defaults to None (0). :type latency: int, optional :param download: Maximum download throughput (bytes/sec). Defaults to None (-1, disabled). :type download: int, optional :param upload: Minimum download throughput (bytes/sec). Defaults to None (-1, disabled). :type upload: int, optional .. py:method:: set_offline_mode(choice: bool) -> None :async: Enable or diable offline mode. Disabled by default. :param enabled: False to disable, True to enable. :type enabled: bool .. py:method:: set_request_cache(enabled: bool) -> None :async: 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`. :param enabled: True to enable, False to disable. Defaults to True. :type enabled: bool, optional .. py:method:: set_user_agent(user_agent: str, user_agent_metadata: str | None = None) -> None :async: Update the user agent to be sent with every request. :param user_agent: User agent string. :type user_agent: str :param user_agent_metadata: Experimental, used to specify user agent client hints to emulate. :type user_agent_metadata: str | None, optional