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 WkConnection

From Leeroopedia
Revision as of 11:38, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_WkConnection.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Implementation Page

Overview

WKConnection manages the WebSocket-based connection between Playwright and the WebKit browser process, dispatching protocol messages to sessions and handling page proxy multiplexing.

Description

The WKConnection class manages the protocol communication layer for WebKit automation. Unlike Firefox's session-based multiplexing, WebKit uses page proxy IDs to route messages to the correct page. The connection maintains a browser-level session and dispatches incoming messages based on pageProxyId fields.

The companion WKSession class handles individual protocol sessions, providing typed send() methods and event dispatching. A special kPageProxyMessageReceived symbol event unifies page proxy lifecycle management.

Usage

Created internally by the WebKit browser type when launching or connecting to a WebKit browser.

Code Reference

Source Location

packages/playwright-core/src/server/webkit/wkConnection.ts (173 lines)

Class Signature

export class WKConnection {
  readonly browserSession: WKSession;
  constructor(transport: ConnectionTransport, onDisconnect: () => void, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector)
  rawSend(message: any): void
  close(): void
}

export class WKSession extends EventEmitter {
  readonly sessionId: string;
  send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>
  dispatchMessage(message: any): void
  dispose(): void
}

Import

import { WKConnection, WKSession, kBrowserCloseMessageId, kPageProxyMessageReceived } from './server/webkit/wkConnection';

I/O Contract

Inputs

  • transport: ConnectionTransport -- WebSocket or pipe transport
  • onDisconnect: () => void -- disconnect callback
  • protocolLogger and browserLogsCollector for logging

Outputs

  • Dispatches protocol events to WKSession instances
  • Emits kPageProxyMessageReceived for page proxy messages

Constants

  • kBrowserCloseMessageId = -9999 -- special close message ID
  • kPageProxyMessageReceived -- symbol for unified page proxy events

Related Pages

Page Connections

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