Implementation:Microsoft Playwright PageDispatcher
| Knowledge Sources | |
|---|---|
| Domains | RPC Protocol, Page Automation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for exposing Page operations over the RPC protocol provided by the Playwright library.
Description
The `PageDispatcher` class bridges the server-side `Page` object to the client via the RPC dispatcher system. It implements the `channels.PageChannel` interface, handling all page-level operations including navigation, evaluation, element interaction, screenshots, PDF generation, network route interception, WebSocket interception, binding calls, init scripts, code coverage, locator handlers, and file chooser management. The class manages event subscriptions (console, dialog, download, request, response, worker, etc.), request interception patterns with URL matchers, and `PageAgent` dispatchers for additional agent-based interactions. It also includes `WorkerDispatcher` and `BindingCallDispatcher` as companion classes for workers and binding calls respectively.
Usage
Use this dispatcher when the Playwright server needs to expose page capabilities to remote clients. It is created automatically for each page within a `BrowserContextDispatcher`.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
Signature
export class PageDispatcher extends Dispatcher<Page, channels.PageChannel, BrowserContextDispatcher> implements channels.PageChannel {
_type_EventTarget: true;
_type_Page: true;
private _page: Page;
_subscriptions: Set<channels.PageUpdateSubscriptionParams['event']>;
constructor(parentScope: BrowserContextDispatcher, page: Page);
async goto(params: channels.PageGotoParams): Promise<channels.PageGotoResult>;
async screenshot(params: channels.PageScreenshotParams): Promise<channels.PageScreenshotResult>;
async evaluate(params: channels.PageEvaluateParams): Promise<channels.PageEvaluateResult>;
async close(params: channels.PageCloseParams): Promise<void>;
}
export class WorkerDispatcher extends Dispatcher<Worker, channels.WorkerChannel, PageDispatcher | BrowserContextDispatcher> {
constructor(scope: PageDispatcher | BrowserContextDispatcher, worker: Worker);
}
export class BindingCallDispatcher extends Dispatcher<SdkObject, channels.BindingCallChannel, PageDispatcher | BrowserContextDispatcher> {
constructor(scope: PageDispatcher | BrowserContextDispatcher, name: string, needsHandle: boolean, source: { context: BrowserContext, page: Page, frame: Frame }, args: any[]);
}
Import
import { PageDispatcher, WorkerDispatcher, BindingCallDispatcher } from '../server/dispatchers/pageDispatcher';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| parentScope | BrowserContextDispatcher | Yes | Parent context dispatcher |
| page | Page | Yes | Server-side Page object to expose |
| params | various channel params | Yes | Method-specific parameters from the client |
Outputs
| Name | Type | Description |
|---|---|---|
| FrameDispatcher | FrameDispatcher | Dispatchers for page frames |
| screenshots | Buffer | Screenshot data in requested format |
| evaluation results | any | Results from JavaScript evaluation |
| events | channel events | Console, dialog, download, worker, navigation events |
Usage Examples
// Created automatically when a page is opened in a context
const pageDispatcher = new PageDispatcher(contextDispatcher, serverPage);
// Client method calls are dispatched to the server
const gotoResult = await pageDispatcher.goto({ url: 'https://example.com', waitUntil: 'load' });
const screenshotResult = await pageDispatcher.screenshot({ type: 'png' });
const evalResult = await pageDispatcher.evaluate({ expression: 'document.title' });