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 BidiBrowser

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

Overview

Concrete tool for browser automation via the WebDriver BiDi protocol provided by the Playwright library.

Description

The `BidiBrowser` class extends the abstract `Browser` base class to implement browser control using the WebDriver BiDi (Bidirectional) protocol. It manages a `BidiConnection` and `BidiSession` for communicating with browsers that support the BiDi protocol (primarily Chromium and Firefox). The class handles session creation with capabilities negotiation (including proxy, insecure certs, and user prompt behavior), manages browser contexts (`BidiBrowserContext`), tracks pages via a map of browsing contexts to `BidiPage` instances, and implements browser lifecycle operations. The `BidiBrowserContext` inner class handles context-specific operations like cookie management, geolocation, and permissions.

Usage

Use this class when automating browsers through the WebDriver BiDi protocol, which provides a standardized, bidirectional communication channel for browser automation as an alternative to CDP (Chrome DevTools Protocol).

Code Reference

Source Location

Signature

export class BidiBrowser extends Browser {
  private readonly _connection: BidiConnection;
  readonly _browserSession: BidiSession;
  private _bidiSessionInfo!: bidi.Session.NewResult;
  readonly _contexts: Map<string, BidiBrowserContext>;
  readonly _bidiPages: Map<bidi.BrowsingContext.BrowsingContext, BidiPage>;

  static async connect(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions): Promise<BidiBrowser>;
  constructor(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions);
}

export class BidiBrowserContext extends BrowserContext {
  readonly _browser: BidiBrowser;
  constructor(browser: BidiBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions);
}

Import

import { BidiBrowser, BidiBrowserContext } from '../server/bidi/bidiBrowser';

I/O Contract

Inputs

Name Type Required Description
parent SdkObject Yes Parent SDK object for instrumentation
transport ConnectionTransport Yes WebSocket transport to the browser
options BrowserOptions Yes Browser launch options including persistent context settings and proxy config

Outputs

Name Type Description
BidiBrowser BidiBrowser Connected browser instance ready for automation
BidiBrowserContext BidiBrowserContext Browser context for isolated browsing sessions
BidiPage BidiPage Page instance within a browser context

Usage Examples

import { BidiBrowser } from 'playwright-core/lib/server/bidi/bidiBrowser';

// Connect to a browser using BiDi protocol
const browser = await BidiBrowser.connect(parentSdkObject, wsTransport, {
  persistent: undefined,
  headful: true,
  proxy: { server: 'http://proxy:8080' },
});

const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');

Related Pages

Page Connections

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