Skip to main content
Version: Next

NavigationRequestInterceptor

One-shot page route that applies a custom method, headers, and payload to the main-frame navigation request.

Scoping the overrides to the navigation request is the point: applying headers page-wide via Page.set_extra_http_headers would leak sensitive values like Authorization to every subresource request the page makes, including cross-origin ones. The navigation request is matched by its role (a main-frame navigation) rather than by its URL, because the browser normalizes URLs (adds the root path, strips fragments), so a URL comparison can silently miss. Redirect hops bypass routing and inherit the overrides.

Custom headers are merged into the headers the browser would send on its own (e.g. User-Agent or fingerprint headers), with the custom ones winning.

Index

Methods

__init__

  • __init__(page, *, method, headers, payload): None
  • Parameters

    • page: Page
    • optionalkeyword-onlymethod: HttpMethod = 'GET'
    • optionalkeyword-onlyheaders: (HttpHeaders | dict[str, str]) | None = None
    • optionalkeyword-onlypayload: HttpPayload | None = None

    Returns None

register

  • async register(): None
  • Start routing the page's requests through this interceptor.

    Once the overrides are applied, the route's predicate stops matching, so any later request (subresources, XHRs, client-side navigations) skips the handler entirely.


    Returns None

Page Options