NavigationRequestInterceptor
Index
Methods
__init__
Parameters
page: Page
optionalkeyword-onlymethod: HttpMethod = 'GET'
optionalkeyword-onlyheaders: (HttpHeaders | dict[str, str]) | None = None
optionalkeyword-onlypayload: HttpPayload | None = None
Returns None
register
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
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_headerswould leak sensitive values likeAuthorizationto 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-Agentor fingerprint headers), with the custom ones winning.