Implementation:Microsoft Playwright FrameDispatcher
| Knowledge Sources | |
|---|---|
| Domains | Dispatcher, Frame |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for exposing server-side Frame objects over the Playwright RPC protocol provided by the Playwright library.
Description
The `FrameDispatcher` class extends `Dispatcher` and implements `channels.FrameChannel` to bridge server-side `Frame` objects to remote clients. It dispatches navigation events (`navigated`, `loadstate`) and provides methods for frame interaction: `goto` for navigation, `evaluateExpression`/`evaluateExpressionHandle` for JavaScript evaluation, `waitForSelector` for DOM queries, `content`/`setContent` for HTML manipulation, `addScriptTag`/`addStyleTag` for resource injection, `click`/`dblclick`/`tap`/`fill`/`focus`/`hover`/`press`/`type` for input, `title` for metadata, `querySelector`/`querySelectorAll` for element queries, `waitForFunction`/`waitForNavigation` for async waiting, and `ariaSnapshot` for accessibility tree snapshots. Main frames use a separate GC bucket to stay alive independently.
Usage
Use FrameDispatcher when the protocol layer needs to expose page frames (main frame and iframes) to Playwright clients for navigation, evaluation, and interaction.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/dispatchers/frameDispatcher.ts
Signature
export class FrameDispatcher extends Dispatcher<Frame, channels.FrameChannel, BrowserContextDispatcher | PageDispatcher> implements channels.FrameChannel {
_type_Frame: boolean;
static from(scope: BrowserContextDispatcher, frame: Frame): FrameDispatcher;
static fromNullable(scope: BrowserContextDispatcher, frame: Frame | null): FrameDispatcher | undefined;
async goto(params: channels.FrameGotoParams, progress: Progress): Promise<channels.FrameGotoResult>;
async evaluateExpression(params: channels.FrameEvaluateExpressionParams, progress: Progress): Promise<channels.FrameEvaluateExpressionResult>;
async waitForSelector(params: channels.FrameWaitForSelectorParams, progress: Progress): Promise<channels.FrameWaitForSelectorResult>;
async click(params: channels.FrameClickParams, progress: Progress): Promise<void>;
async fill(params: channels.FrameFillParams, progress: Progress): Promise<void>;
async content(params: channels.FrameContentParams, progress: Progress): Promise<channels.FrameContentResult>;
async title(params: channels.FrameTitleParams, progress: Progress): Promise<channels.FrameTitleResult>;
// ... additional frame methods
}
Import
import { FrameDispatcher } from '../server/dispatchers/frameDispatcher';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| scope | BrowserContextDispatcher | Yes | Parent browser context dispatcher scope |
| frame | Frame | Yes | The server-side frame object to expose |
| params | various channel params | Yes | Method-specific parameters |
Outputs
| Name | Type | Description |
|---|---|---|
| response | ResponseDispatcher | Navigation response dispatcher |
| value | SerializedValue | Evaluation result |
| element | ElementHandleDispatcher | Queried element handle |
| (events) | navigated, loadstate | Frame navigation and lifecycle events |
Usage Examples
import { FrameDispatcher } from '../server/dispatchers/frameDispatcher';
const frameDispatcher = FrameDispatcher.from(contextScope, frame);
const { response } = await frameDispatcher.goto({ url: 'https://example.com' }, progress);
const { value } = await frameDispatcher.evaluateExpression({ expression: 'document.title', isFunction: false }, progress);