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 WkBrowser

From Leeroopedia
Knowledge Sources
Domains Browser Automation, WebKit Engine
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for WebKit browser management via the WebKit Inspection Protocol provided by the Playwright library.

Description

The `WKBrowser` class extends the abstract `Browser` base class to implement WebKit-specific browser management using the WebKit Inspection Protocol. It manages a `WKConnection` and `WKSession` for protocol communication, maintains maps of browser contexts (`WKBrowserContext`) and pages (`WKPage`), and handles WebKit-specific features including page proxy sessions, provisional pages (for navigation), default user agent configuration, and download management. The class handles WebKit's unique architecture where page proxy messages are received at the browser level and routed to the appropriate `WKPage`. The `WKBrowserContext` inner class implements context operations for geolocation, permissions, clear cache, and sets default user agent to match Safari's version string.

Usage

Use this class as the WebKit-specific browser implementation. It is instantiated by the WebKit browser type class when launching or connecting to a WebKit browser.

Code Reference

Source Location

Signature

export class WKBrowser extends Browser {
  private readonly _connection: WKConnection;
  readonly _browserSession: WKSession;
  readonly _contexts: Map<string, WKBrowserContext>;
  readonly _wkPages: Map<string, WKPage>;

  static async connect(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions): Promise<WKBrowser>;
  constructor(parent: SdkObject, transport: ConnectionTransport, options: BrowserOptions);
}

export class WKBrowserContext extends BrowserContext {
  readonly _browser: WKBrowser;
  readonly _browserContextId: string | undefined;
}

Import

import { WKBrowser, WKBrowserContext } from '../server/webkit/wkBrowser';

I/O Contract

Inputs

Name Type Required Description
parent SdkObject Yes Parent SDK object for instrumentation
transport ConnectionTransport Yes Transport connection to the WebKit process
options BrowserOptions Yes Browser launch options including persistent context settings

Outputs

Name Type Description
WKBrowser WKBrowser Connected WebKit browser instance
WKBrowserContext WKBrowserContext Isolated WebKit browser context
WKPage WKPage WebKit page within a context

Usage Examples

import { WKBrowser } from 'playwright-core/lib/server/webkit/wkBrowser';

const browser = await WKBrowser.connect(parent, wsTransport, {
  persistent: undefined,
  headful: true,
});

const context = await browser.newContext({
  userAgent: 'Custom Safari Agent',
});
const page = await context.newPage();
await page.goto('https://example.com');

Related Pages

Page Connections

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