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 BidiNetworkManager

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

Overview

Concrete tool for managing network requests via the WebDriver BiDi protocol provided by the Playwright library.

Description

The `BidiNetworkManager` class handles network event processing and request interception for browsers communicating over the WebDriver BiDi protocol. It listens to BiDi network events (`network.beforeRequestSent`, `network.responseStarted`, `network.responseCompleted`, `network.fetchError`, `network.authRequired`) and translates them into Playwright's internal `network.Request` and `network.Response` objects. The class supports request interception for route handling, HTTP authentication with credentials, and tracks in-flight requests. It manages the lifecycle of network intercepts by toggling protocol-level interception when user interception is enabled or disabled.

Usage

Use this class internally when the BiDi browser backend needs to track, intercept, or modify network requests passing through the browser. It is instantiated by `BidiPage` and provides the network layer for BiDi-based browser automation.

Code Reference

Source Location

  • Repository: Microsoft_Playwright
  • File: packages/playwright-core/src/server/bidi/bidiNetworkManager.ts

Signature

export class BidiNetworkManager {
  private readonly _session: BidiSession;
  private readonly _requests: Map<string, BidiRequest>;
  private readonly _page: Page;
  private _userRequestInterceptionEnabled: boolean;
  private _protocolRequestInterceptionEnabled: boolean;
  private _credentials: types.Credentials | undefined;

  constructor(bidiSession: BidiSession, page: Page);
  dispose(): void;
  async setRequestInterception(value: boolean): Promise<void>;
  async authenticate(credentials: types.Credentials | undefined): Promise<void>;
}

Import

import { BidiNetworkManager } from '../server/bidi/bidiNetworkManager';

I/O Contract

Inputs

Name Type Required Description
bidiSession BidiSession Yes BiDi session for sending/receiving protocol messages
page Page Yes The page instance this network manager is associated with
value boolean Yes Whether to enable or disable request interception
credentials types.Credentials No HTTP authentication credentials (username/password)

Outputs

Name Type Description
network.Request network.Request Playwright request object emitted for each network request
network.Response network.Response Playwright response object emitted for each network response

Usage Examples

// Internal usage within BidiPage
const networkManager = new BidiNetworkManager(bidiSession, page);

// Enable request interception
await networkManager.setRequestInterception(true);

// Set HTTP authentication credentials
await networkManager.authenticate({ username: 'user', password: 'pass' });

// Clean up
networkManager.dispose();

Related Pages

Page Connections

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