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 BidiPage

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

Overview

Concrete tool for page-level automation via the WebDriver BiDi protocol provided by the Playwright library.

Description

The `BidiPage` class implements the `PageDelegate` interface for the WebDriver BiDi protocol. It manages a page's lifecycle including frame execution contexts, JavaScript evaluation (via `BidiExecutionContext`), input dispatching (mouse, keyboard, touchscreen via `RawKeyboardImpl`, `RawMouseImpl`, `RawTouchscreenImpl`), network management (via `BidiNetworkManager`), dialog handling, PDF generation (via `BidiPDF`), and init script injection. The class maintains realm-to-context mappings for both page and worker execution contexts, processes BiDi events for navigation, script evaluation, logging, and page lifecycle, and uses a utility world (`__playwright_utility_world__`) for isolated script execution.

Usage

Use this class as the BiDi protocol backend for page operations. It is created by `BidiBrowserContext` when a new page is opened and provides the bridge between Playwright's abstract page model and the BiDi protocol commands.

Code Reference

Source Location

Signature

export class BidiPage implements PageDelegate {
  readonly rawMouse: RawMouseImpl;
  readonly rawKeyboard: RawKeyboardImpl;
  readonly rawTouchscreen: RawTouchscreenImpl;
  readonly _page: Page;
  readonly _session: BidiSession;
  readonly _opener: BidiPage | null;
  readonly _realmToContext: Map<string, dom.FrameExecutionContext>;
  readonly _browserContext: BidiBrowserContext;
  readonly _networkManager: BidiNetworkManager;

  constructor(browserContext: BidiBrowserContext, bidiSession: BidiSession, opener: BidiPage | null);
}

Import

import { BidiPage } from '../server/bidi/bidiPage';

I/O Contract

Inputs

Name Type Required Description
browserContext BidiBrowserContext Yes The browser context this page belongs to
bidiSession BidiSession Yes BiDi session for protocol communication
opener BidiPage or null Yes The page that opened this page, if any

Outputs

Name Type Description
_page Page The Playwright Page instance backed by this delegate
screenshots Buffer Screenshot data captured from the page
PDF Buffer PDF data generated from the page

Usage Examples

// Created internally by BidiBrowserContext
const bidiPage = new BidiPage(browserContext, bidiSession, openerPage);

// The page delegate is used via the Page abstraction
const page = bidiPage._page;
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });

Related Pages

Page Connections

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