Implementation:Microsoft Playwright WkInterceptableRequest
Overview
WKInterceptableRequest wraps WebKit network requests with interception capabilities, enabling request modification, fulfillment, and abort functionality for route handling.
Description
The WKInterceptableRequest class bridges between WebKit's Network domain events and Playwright's network.Request and network.Route abstractions. It processes requestWillBeSent events, creates Playwright Request objects with proper resource types, and provides methods for request interception including:
abort-- cancels the request with a mapped error reasonfulfill-- provides a custom responsecontinue-- continues with optionally modified parameters
The module includes an errorReasons mapping that translates Playwright's error reason strings to WebKit's ResourceErrorType values.
Usage
Created internally by the WebKit page network event handlers.
Code Reference
Source Location
packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts (188 lines)
Class Signature
export class WKInterceptableRequest {
readonly request: network.Request;
constructor(session: WKSession, frame: frames.Frame, event: Protocol.Network.requestWillBeSentPayload, redirectedFrom: WKInterceptableRequest | null, documentId: string | undefined)
async abort(errorCode: string): Promise<void>
async fulfill(response: types.NormalizedFulfillResponse): Promise<void>
async continue(overrides: types.NormalizedContinueOverrides): Promise<void>
}
Import
import { WKInterceptableRequest } from './server/webkit/wkInterceptableRequest';
I/O Contract
Inputs
session: WKSession-- WebKit protocol sessionframe: Frame-- the frame that originated the requestevent-- WebKitrequestWillBeSentprotocol eventredirectedFrom-- the request this was redirected from, if any
Outputs
- Creates
network.Requestobjects with resource type, headers, and post data - Sends interception commands (
Network.interceptRequestWithResponse, etc.) via the session
Related Pages
- Microsoft_Playwright_WkConnection -- WebKit session for protocol commands
- Microsoft_Playwright_FfNetworkManager -- Firefox network management equivalent
- Microsoft_Playwright_NetworkUtils -- Network utility functions