Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright SocksInterceptor

From Leeroopedia

Template:Implementation Page

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 messages
  • pattern: string -- URL pattern for matching interceptable connections
  • redirectPortForTest: number -- optional port redirect for testing

Outputs

  • Forwards SOCKS proxy events over the transport
  • Returns true from interceptMessage if the message was handled

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment