Implementation:Microsoft Playwright WkPage
| Knowledge Sources | |
|---|---|
| Domains | Page Automation, WebKit Engine |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for WebKit page-level automation via the WebKit Inspection Protocol provided by the Playwright library.
Description
The `WKPage` class implements the `PageDelegate` interface for WebKit browsers using the WebKit Inspection Protocol. It is the largest page delegate implementation, managing complex WebKit-specific features including provisional pages (`WKProvisionalPage`) for cross-origin navigations, frame sessions (`WKFrame`) with target-based multiplexing, network request interception (`WKInterceptableRequest`), workers (`WKWorkers`), and the dual-session architecture (page proxy session and page session). The class handles JavaScript evaluation via `WKExecutionContext`, input dispatching via WebKit-specific raw implementations, dialog events, console messages, screenshot capture (with special handling for JPEG using `jpegjs` and PNG), and WebKit's unique animation synchronization through style sheet toggling. It supports conditional frame sessions based on WebKit revision.
Usage
Use this class as the WebKit Inspection Protocol backend for page operations. It is created by `WKBrowserContext` when a new page proxy target appears and provides the bridge between Playwright's abstract page model and WebKit protocol commands.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/webkit/wkPage.ts
Signature
export class WKPage implements PageDelegate {
readonly rawMouse: RawMouseImpl;
readonly rawKeyboard: RawKeyboardImpl;
readonly rawTouchscreen: RawTouchscreenImpl;
_session: WKSession;
readonly _page: Page;
private readonly _pageProxySession: WKSession;
private _provisionalPage: WKProvisionalPage | null;
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null);
}
Import
import { WKPage } from '../server/webkit/wkPage';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| browserContext | WKBrowserContext | Yes | Browser context this page belongs to |
| pageProxySession | WKSession | Yes | Page proxy session for browser-level page management |
| opener | WKPage or null | Yes | The page that opened this page, if any |
Outputs
| Name | Type | Description |
|---|---|---|
| _page | Page | The Playwright Page instance backed by this delegate |
| screenshots | Buffer | Screenshot data captured via WebKit protocol (PNG/JPEG) |
Usage Examples
// Created internally by WKBrowser when a page proxy target appears
const wkPage = new WKPage(browserContext, pageProxySession, openerPage);
// Used via the Page abstraction
const page = wkPage._page;
await page.goto('https://example.com');
await page.screenshot({ path: 'webkit-screenshot.png' });
// WebKit-specific: provisional page handling for cross-origin navigations
// is managed automatically by WKPage