Implementation:Microsoft Playwright BrowserDispatcher
| Knowledge Sources | |
|---|---|
| Domains | Dispatcher, Browser |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for exposing server-side Browser objects over the Playwright RPC protocol provided by the Playwright library.
Description
The `BrowserDispatcher` class extends `Dispatcher` and implements `channels.BrowserChannel` to bridge server-side `Browser` instances to remote clients. It dispatches `context` events when new browser contexts are created and a `close` event on disconnection. The class supports options for `ignoreStopAndKill` (preventing browser closure) and `isolateContexts` (only exposing contexts created through this dispatcher). It provides `newContext` for creating browser contexts, `newBrowserCDPSession` for raw CDP access (Chromium only), `startTracing`/`stopTracing` for Chromium tracing, and `close`/`killForTests` for lifecycle management.
Usage
Use BrowserDispatcher when the protocol layer needs to expose a launched or connected browser instance to Playwright clients over the RPC channel.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/dispatchers/browserDispatcher.ts
Signature
export class BrowserDispatcher extends Dispatcher<Browser, channels.BrowserChannel, BrowserTypeDispatcher> implements channels.BrowserChannel {
_type_Browser: boolean;
constructor(scope: BrowserTypeDispatcher, browser: Browser, options?: BrowserDispatcherOptions);
_didClose(): void;
async newContext(params: channels.BrowserNewContextParams, progress: Progress): Promise<channels.BrowserNewContextResult>;
async close(params: channels.BrowserCloseParams, progress: Progress): Promise<void>;
async killForTests(params: channels.BrowserKillForTestsParams, progress: Progress): Promise<void>;
async newBrowserCDPSession(params: channels.BrowserNewBrowserCDPSessionParams, progress: Progress): Promise<channels.BrowserNewBrowserCDPSessionResult>;
async startTracing(params: channels.BrowserStartTracingParams, progress: Progress): Promise<channels.BrowserStartTracingResult>;
async stopTracing(params: channels.BrowserStopTracingParams, progress: Progress): Promise<channels.BrowserStopTracingResult>;
}
Import
import { BrowserDispatcher } from '../server/dispatchers/browserDispatcher';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| scope | BrowserTypeDispatcher | Yes | Parent browser type dispatcher scope |
| browser | Browser | Yes | The server-side browser instance to expose |
| options | BrowserDispatcherOptions | No | Options for ignoreStopAndKill and isolateContexts |
Outputs
| Name | Type | Description |
|---|---|---|
| context | BrowserContextDispatcher | Dispatcher for a newly created browser context |
| (events) | context, close | Events dispatched to the client |
Usage Examples
import { BrowserDispatcher } from '../server/dispatchers/browserDispatcher';
const browserDispatcher = new BrowserDispatcher(browserTypeScope, browser, { isolateContexts: true });
const { context } = await browserDispatcher.newContext({ viewport: { width: 1280, height: 720 } }, progress);