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 CrBrowser

From Leeroopedia
Knowledge Sources
Domains Browser Automation, Chrome DevTools Protocol
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for Chromium browser management via CDP provided by the Playwright library.

Description

The `CRBrowser` class extends the abstract `Browser` base class to implement Chromium-specific browser management using the Chrome DevTools Protocol (CDP). It manages a `CRConnection` for protocol communication and maintains maps of browser contexts (`CRBrowserContext`), pages (`CRPage`), and service workers (`CRServiceWorker`). The class handles target discovery and attachment, tracing recording, CDP session management (including client-accessible CDP sessions), version detection, and browser-level operations like new context creation, cookie management, and PDF generation support. The `CRBrowserContext` inner class implements context-specific CDP operations for permissions, geolocation, network conditions, and caching.

Usage

Use this class as the Chromium-specific browser implementation for CDP-based automation. It is instantiated by the `Chromium` browser type class when launching or connecting to a Chromium browser.

Code Reference

Source Location

Signature

export class CRBrowser extends Browser {
  readonly _connection: CRConnection;
  _session: CRSession;
  readonly _contexts: Map<string, CRBrowserContext>;
  _crPages: Map<string, CRPage>;
  _serviceWorkers: Map<string, CRServiceWorker>;
  _devtools?: CRDevTools;

  static async connect(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions, devtools?: CRDevTools): Promise<CRBrowser>;
}

export class CRBrowserContext extends BrowserContext {
  readonly _browser: CRBrowser;
  readonly _browserContextId: string | undefined;
}

Import

import { CRBrowser, CRBrowserContext } from '../server/chromium/crBrowser';

I/O Contract

Inputs

Name Type Required Description
parent SdkObject Yes Parent SDK object for instrumentation hierarchy
transport ConnectionTransport Yes WebSocket or pipe transport to the Chromium process
options BrowserOptions Yes Browser configuration including persistent context, proxy, etc.
devtools CRDevTools No Optional DevTools integration instance

Outputs

Name Type Description
CRBrowser CRBrowser Connected Chromium browser with CDP session established
CRBrowserContext CRBrowserContext Isolated Chromium browser context
CDPSession CDPSession Client-accessible CDP session for direct protocol access

Usage Examples

import { CRBrowser } from 'playwright-core/lib/server/chromium/crBrowser';

const browser = await CRBrowser.connect(parent, wsTransport, browserOptions);

// Create a new isolated context
const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });
const page = await context.newPage();

// Access CDP session directly
const cdpSession = await browser.newBrowserCDPSession();
await cdpSession.send('Performance.enable');

Related Pages

Page Connections

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