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 NetworkDispatchers

From Leeroopedia
Revision as of 11:37, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_NetworkDispatchers.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Dispatcher, Network
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for exposing server-side network objects (Request, Response, Route, WebSocket, APIRequestContext) over the Playwright RPC protocol provided by the Playwright library.

Description

The `networkDispatchers` module defines multiple dispatcher classes for network-related objects. `RequestDispatcher` exposes `Request` objects with their URL, method, headers, post data, timing, and service worker information. `ResponseDispatcher` exposes `Response` objects with status, headers, and body retrieval. `RouteDispatcher` handles request interception with `fulfill`, `continue_`, and `abort` methods. `WebSocketDispatcher` exposes WebSocket connections with frame sent/received/close events. `APIRequestContextDispatcher` exposes the global API request context for `fetch`-style HTTP operations. Each dispatcher uses static factory methods for creation and reuse.

Usage

Use NetworkDispatchers when the protocol layer needs to expose network requests, responses, routes, and WebSocket connections to Playwright clients for network interception and monitoring.

Code Reference

Source Location

  • Repository: Microsoft_Playwright
  • File: packages/playwright-core/src/server/dispatchers/networkDispatchers.ts

Signature

export class RequestDispatcher extends Dispatcher<Request, channels.RequestChannel, BrowserContextDispatcher | PageDispatcher | FrameDispatcher> implements channels.RequestChannel {
  _type_Request: boolean;
  static from(scope: BrowserContextDispatcher, request: Request): RequestDispatcher;
  async response(params: channels.RequestResponseParams, progress: Progress): Promise<channels.RequestResponseResult>;
}

export class ResponseDispatcher extends Dispatcher<Response, channels.ResponseChannel, BrowserContextDispatcher | RequestDispatcher> implements channels.ResponseChannel {
  _type_Response: boolean;
  static from(scope: BrowserContextDispatcher, response: Response): ResponseDispatcher;
  async body(params: channels.ResponseBodyParams, progress: Progress): Promise<channels.ResponseBodyResult>;
}

export class RouteDispatcher extends Dispatcher<Route, channels.RouteChannel, BrowserContextDispatcher> implements channels.RouteChannel {
  _type_Route: boolean;
  async abort(params: channels.RouteAbortParams, progress: Progress): Promise<void>;
  async fulfill(params: channels.RouteFulfillParams, progress: Progress): Promise<void>;
  async continue_(params: channels.RouteContinueParams, progress: Progress): Promise<void>;
}

export class WebSocketDispatcher extends Dispatcher<WebSocket, channels.WebSocketChannel, PageDispatcher> implements channels.WebSocketChannel {}

export class APIRequestContextDispatcher extends Dispatcher<APIRequestContext, channels.APIRequestContextChannel, RootDispatcher | BrowserContextDispatcher> implements channels.APIRequestContextChannel {}

Import

import { RequestDispatcher, ResponseDispatcher, RouteDispatcher, WebSocketDispatcher, APIRequestContextDispatcher } from '../server/dispatchers/networkDispatchers';

I/O Contract

Inputs

Name Type Required Description
scope BrowserContextDispatcher Yes Parent dispatcher scope
request Request Yes Server-side request object
response Response Yes Server-side response object
route Route Yes Server-side route for interception

Outputs

Name Type Description
response ResponseDispatcher Dispatcher for the request's response
body Buffer Response body content
(events) frameSent, frameReceived, close WebSocket events

Usage Examples

import { RequestDispatcher, RouteDispatcher } from '../server/dispatchers/networkDispatchers';

const requestDispatcher = RequestDispatcher.from(contextScope, request);
const { response } = await requestDispatcher.response({}, progress);

// Route interception
await routeDispatcher.fulfill({ status: 200, body: 'mocked', headers: [] }, progress);
await routeDispatcher.abort({ errorCode: 'blockedbyclient' }, progress);

Related Pages

Page Connections

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