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 CrConnection

From Leeroopedia
Knowledge Sources
Domains Chromium, CDP
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for managing the Chrome DevTools Protocol (CDP) connection and session multiplexing provided by the Playwright library.

Description

The `CRConnection` class extends `SdkObject` and manages the raw CDP transport to a Chromium browser. It maintains a `rootSession` for browser-level commands and a map of `CRSession` instances keyed by session ID for target-specific communication. `CRSession` handles sending typed CDP commands, receiving responses via callbacks, and dispatching events. The connection manages session creation/disposal, message routing, protocol logging, and disconnect handling. A special `kBrowserCloseMessageId` is used for the browser close command. Both classes emit events via Node.js `EventEmitter`.

Usage

Use CrConnection when Playwright communicates with Chromium-based browsers over the Chrome DevTools Protocol, managing multiple targets (pages, service workers, etc.) through session multiplexing.

Code Reference

Source Location

Signature

export const kBrowserCloseMessageId = -9999;

export class CRConnection extends SdkObject {
  readonly rootSession: CRSession;
  readonly _sessions: Map<string, CRSession>;
  constructor(parent: SdkObject, transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector);
}

export class CRSession extends SdkObject {
  readonly sessionId: string;
  async send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>;
}

Import

import { CRConnection, CRSession, kBrowserCloseMessageId } from '../server/chromium/crConnection';

I/O Contract

Inputs

Name Type Required Description
parent SdkObject Yes Parent SDK object
transport ConnectionTransport Yes The underlying message transport (WebSocket or pipe)
protocolLogger ProtocolLogger Yes Logger for CDP message tracing
browserLogsCollector RecentLogsCollector Yes Collector for browser stderr logs

Outputs

Name Type Description
rootSession CRSession The browser-level CDP session
response Protocol.CommandReturnValues[T] Typed response from a CDP command

Usage Examples

import { CRConnection } from '../server/chromium/crConnection';

const connection = new CRConnection(parentSdkObject, transport, logger, logsCollector);
const version = await connection.rootSession.send('Browser.getVersion');
console.log('Browser version:', version.product);

Related Pages

Page Connections

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