mokr.network.fetch

Classes

FetchDomain

Client to handle sending manual fetch requests.

Module Contents

class mokr.network.fetch.FetchDomain(page: mokr.browser.page.Page)

Bases: pyee.EventEmitter

Client to handle sending manual fetch requests.

Note that sending fetch requests from this class will temporarily enable request interception globally. However, these fetch requests won’t be caught by the request interception chain, however “response” and “requestfinished” events will still be caught.

For Firefox this is not applicable. Fetch requests in Firefox are built manually from the response data. Unlike standard Firefox request responses, the response body is available for FetchDomain responses.

Chrome requests take advantage of the existing fetch system in its mokr.network.NetworkManager while Firefox cannot; Chrome could do the same as Firefox does here and build the objects directly but some features would be lost like redirect chain.

Parameters:

page (Page) – Parent mokr.browser.Page this was spawned from.

async fetch(url: str | None = None, timeout: int = None, request: mokr.network.request.Request | None = None, body: str | None = None, browsing_topics: bool | None = None, cache: mokr.constants.HTTP_CACHE_TYPES | None = None, credentials: Literal['omit', 'same-origin', 'include'] | None = None, headers: dict | None = None, method: mokr.constants.HTTP_METHODS = 'GET', mode: Literal['cors', 'no-cors', 'same-origin'] = None, priority: Literal['high', 'low', 'auto'] | None = None, redirect: Literal['follow', 'error', 'manual'] | None = None, referrer: str | None = None, referrer_policy: mokr.constants.REFERRER_POLICIES | None = None) mokr.network.response.Response

Send a fetch request.

Note that fetch is sensitive to the current site’s CORS settings. Additionally, trying to send a fetch request before the DOM loads can hang forever.

Parameters:
  • url (str | None, optional) – The url to request. Ignored if request is given. Defaults to None.

  • timeout (int, optional) – Time in milliseconds to wait. Defaults to None.

  • request (Request | None, optional) – A request object to pull url, method, and headers from. Defaults to None.

  • body (str | None, optional) – Body to add to the request. Defaults to None.

  • browsing_topics (bool | None, optional) – If True, selected topics will be sent in a Sec-Browsing-Topics header with the associated request. Defaults to None.

  • cache (HTTP_CACHE_TYPES) – How the request should interact with the HTTP cache. One of: “default”, “no-store”, “reload”, “no-cache”, “force-cache”, or “only-if-cache”. Defaults to None.

  • credentials (Literal[str] | None, optional) – How to handle credentials. One of “omit”, “same-origin”, or “include”. Defaults to None.

  • headers (dict | None, optional) – Headers to pass with the request. Defaults to None.

  • method (HTTP_METHODS, optional) – HTTP method. Defaults to “GET”.

  • mode (Literal["cors", "no-cors", "same-origin"], optional) – CORS mode to use. Defaults to None.

  • priority (Literal["high", "low", "auto"] | None, optional) – Priority of request relative to others. Defaults to None.

  • redirect (Literal["follow", "error", "manual"] | None, optional) – How to handle redirects. Defaults to None (“follow”).

  • referrer (str | None, optional) – Request referrer. Defaults to None.

  • referrer_policy (REFERRER_POLICIES) – The referrer policy to use. One of “no-referrer”, “no-referrer-when-downgrade”, “same-origin”, “origin”, “strict-origin”, “origin-when-cross-origin”, “strict-origin-when-cross-origin”, or “unsafe-url”. Defaults to None (“strict-origin-when-cross-origin”).

Raises:
  • ValueError – Raised if neither url nor request given.

  • NetworkError – Raised if no response found when request resolves.

Returns:

Last response recieved after all redirects, if any.

Return type:

Response