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 Server Page

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

Overview

Concrete tool for the server-side Page abstraction provided by the Playwright library.

Description

The `Page` class (extending `SdkObject`) is the central server-side abstraction for a browser page/tab. It defines the `PageDelegate` interface that all browser-specific implementations (CRPage, FFPage, WKPage, BidiPage) must implement, and orchestrates the page's components: `FrameManager` for frame management, `Keyboard`/`Mouse`/`Touchscreen` for input, `Screenshotter` for screenshots, and `Screencast` for screen recording. The class manages emulated media (color scheme, reduced motion, forced colors), viewport settings, extra HTTP headers, offline mode, request interception, file chooser handling, page bindings, locator handlers, and the page lifecycle. It emits events for console messages, dialogs, downloads, page errors, workers, file choosers, popups, and navigation. The `PageBinding` and `InitScript` classes manage page-level bindings and initialization scripts.

Usage

Use this class as the core page abstraction in the Playwright server. All page operations are routed through this class, which delegates browser-specific work to the `PageDelegate` interface.

Code Reference

Source Location

Signature

export interface PageDelegate {
  readonly rawMouse: input.RawMouse;
  readonly rawKeyboard: input.RawKeyboard;
  readonly rawTouchscreen: input.RawTouchscreen;
  reload(): Promise<void>;
  goBack(): Promise<boolean>;
  goForward(): Promise<boolean>;
  addInitScript(initScript: InitScript): Promise<void>;
  navigateFrame(frame: frames.Frame, url: string, referrer: string | undefined): Promise<frames.GotoResult>;
  takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer>;
  closePage(runBeforeUnload: boolean): Promise<void>;
}

export class Page extends SdkObject<PageEventMap> {
  readonly keyboard: input.Keyboard;
  readonly mouse: input.Mouse;
  readonly touchscreen: input.Touchscreen;
  readonly _frameManager: frames.FrameManager;
  readonly _browserContext: BrowserContext;

  constructor(delegate: PageDelegate, browserContext: BrowserContext);
  mainFrame(): frames.Frame;
  frames(): frames.Frame[];
  async reload(progress: Progress, options?: types.NavigateOptions): Promise<network.Response | null>;
  async screenshot(progress: Progress, options: ScreenshotOptions): Promise<Buffer>;
  async close(options?: { runBeforeUnload?: boolean, reason?: string }): Promise<void>;
}

export class PageBinding { constructor(name: string, playwrightFunction: FunctionWithSource, needsHandle: boolean); }
export class InitScript { constructor(source: string, worldName?: string); }

Import

import { Page, PageDelegate, PageBinding, InitScript } from '../server/page';

I/O Contract

Inputs

Name Type Required Description
delegate PageDelegate Yes Browser-specific page implementation
browserContext BrowserContext Yes Browser context this page belongs to
progress Progress Yes Progress tracker for timeout and cancellation
options various No Method-specific options (viewport, media, etc.)

Outputs

Name Type Description
mainFrame Frame The main frame of the page
frames Frame[] All frames in the page
screenshot Buffer Page screenshot data
Response network.Response or null Navigation response
events PageEventMap Console, dialog, download, error, worker events

Usage Examples

// Created by BrowserContext
const page = new Page(pageDelegate, browserContext);

// Navigation
const response = await page.mainFrame().goto(progress, 'https://example.com', {});

// Input
await page.keyboard.type(progress, 'Hello');
await page.mouse.click(progress, 100, 200);

// Screenshot
const buffer = await page.screenshot(progress, { type: 'png', fullPage: true });

// Close
await page.close({ runBeforeUnload: false });

Related Pages

Page Connections

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