Implementation:Microsoft Playwright SocksInterceptor
Overview
SocksInterceptor intercepts and proxies SOCKS connections over the Playwright WebSocket transport, enabling browser traffic to be routed through Playwright's SOCKS proxy infrastructure.
Description
The SocksInterceptor class bridges between the SOCKS proxy handler and a WebSocket transport connection. It uses a Proxy-based channel implementation to dynamically generate protocol method calls on the transport. The interceptor listens for SOCKS proxy events (connected, data, error, failed, end) and forwards them to the remote side, while also handling incoming socket requests and data from the remote.
This enables scenarios like browser context proxy configuration and network interception at the socket level.
Usage
Created internally when SOCKS-based proxy interception is configured for browser connections.
Code Reference
Source Location
packages/playwright-core/src/server/socksInterceptor.ts (88 lines)
Class Signature
export class SocksInterceptor {
constructor(transport: WebSocketTransport, pattern: string | undefined, redirectPortForTest: number | undefined)
cleanup(): void
interceptMessage(message: any): boolean
}
Import
import { SocksInterceptor } from './server/socksInterceptor';
I/O Contract
Inputs
transport: WebSocketTransport-- the WebSocket transport for protocol messagespattern: string-- URL pattern for matching interceptable connectionsredirectPortForTest: number-- optional port redirect for testing
Outputs
- Forwards SOCKS proxy events over the transport
- Returns
truefrominterceptMessageif the message was handled
Related Pages
- Microsoft_Playwright_WebSocketTransport -- Transport layer
- Microsoft_Playwright_NetworkUtils -- Network utilities