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 Client Playwright

From Leeroopedia
Knowledge Sources
Domains Browser Automation, API Entry Point
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for serving as the root entry point object for the Playwright client API provided by the Playwright library.

Description

The Playwright class extends ChannelOwner and represents the root object of the Playwright client API. It is constructed from a PlaywrightInitializer received from the server and provides access to all major Playwright capabilities:

  • Browser types: chromium, firefox, and webkit properties, each a BrowserType instance for launching or connecting to browsers.
  • Electron: _electron property for Electron application testing.
  • Android: _android property for Android device testing.
  • Selectors: selectors property for registering custom selector engines.
  • Request: request property for the APIRequest context factory.
  • Devices: devices property containing device descriptors for emulation.
  • Errors: errors property exposing TimeoutError for error type checking.

The class also supports instrumentation hooks via _defaultLaunchOptions, _defaultContextTimeout, and _defaultContextNavigationTimeout, and provides helper methods _allContexts() and _allPages() for iterating over all active contexts and pages.

Usage

The Playwright instance is the main entry point obtained via require('playwright') or the library's connection mechanism. All browser automation begins from this object.

Code Reference

Source Location

Signature

export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
  readonly _android: Android;
  readonly _electron: Electron;
  readonly chromium: BrowserType;
  readonly firefox: BrowserType;
  readonly webkit: BrowserType;
  readonly devices: any;
  selectors: Selectors;
  readonly request: APIRequest;
  readonly errors: { TimeoutError: typeof TimeoutError };

  _defaultLaunchOptions?: LaunchOptions;
  _defaultContextTimeout?: number;
  _defaultContextNavigationTimeout?: number;

  constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PlaywrightInitializer);

  static from(channel: channels.PlaywrightChannel): Playwright;
  _preLaunchedBrowser(): Browser;
  _allContexts(): BrowserContext[];
  _allPages(): Page[];
}

Import

import { Playwright } from 'playwright-core/src/client/playwright';

I/O Contract

Inputs

Name Type Required Description
parent ChannelOwner Yes The parent channel owner (root dispatcher)
type string Yes The object type name ('Playwright')
guid string Yes The unique protocol identifier
initializer PlaywrightInitializer Yes Server-provided initializer containing browser type channels, device descriptors, and pre-launched browser reference

Outputs

Name Type Description
chromium BrowserType BrowserType for launching Chromium browsers
firefox BrowserType BrowserType for launching Firefox browsers
webkit BrowserType BrowserType for launching WebKit browsers
devices object Device descriptors for emulation (e.g., 'iPhone 13', 'Pixel 5')
selectors Selectors Selectors manager for registering custom engines
request APIRequest Factory for creating API request contexts
errors { TimeoutError } Error class references for instanceof checks

Usage Examples

const { chromium, firefox, webkit, devices, selectors } = require('playwright');

// Launch a browser
const browser = await chromium.launch({ headless: true });

// Use device descriptors
const iPhone = devices['iPhone 13'];
const context = await browser.newContext({
  ...iPhone,
});

// Register custom selectors
await selectors.register('tag', createTagEngine);

// API request
const apiContext = await playwright.request.newContext();
const response = await apiContext.get('https://api.example.com/data');

Related Pages

Page Connections

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