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 Browser

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

Overview

Concrete tool for defining the abstract base class for all browser implementations on the server side provided by the Playwright library.

Description

The `Browser` abstract class extends `SdkObject` and serves as the base for all browser engine implementations (Chromium, Firefox, WebKit). It defines the `BrowserOptions` type containing launch configuration (name, channel, artifact directories, browser process, proxy settings, protocol logger, etc.) and the `BrowserProcess` interface for managing the underlying browser process. The class provides abstract methods for context management (`newContext`, `contexts`, `isConnected`), version information (`version`), and lifecycle control. It emits `Context` and `Disconnected` events, handles download management with `Artifact` instances, and coordinates browser context creation with `validateBrowserContextOptions`.

Usage

Use Server Browser as the base class when implementing a new browser engine backend, or when working with browser instances generically across Chromium, Firefox, and WebKit.

Code Reference

Source Location

Signature

export interface BrowserProcess {
  onclose?: ((exitCode: number | null, signal: string | null) => void);
  process?: ChildProcess;
  kill(): Promise<void>;
  close(): Promise<void>;
}

export type BrowserOptions = {
  name: string;
  isChromium: boolean;
  channel?: string;
  artifactsDir: string;
  downloadsPath: string;
  tracesDir: string;
  headful?: boolean;
  persistent?: types.BrowserContextOptions;
  browserProcess: BrowserProcess;
  // ... additional options
};

export abstract class Browser extends SdkObject {
  static Events: { Context: string; Disconnected: string };
  readonly options: BrowserOptions;
  abstract newContext(options: types.BrowserContextOptions): Promise<BrowserContext>;
  abstract contexts(): BrowserContext[];
  abstract isConnected(): boolean;
  abstract version(): string;
}

Import

import { Browser } from '../server/browser';
import type { BrowserOptions, BrowserProcess } from '../server/browser';

I/O Contract

Inputs

Name Type Required Description
parent SdkObject Yes Parent SDK object for instrumentation hierarchy
options BrowserOptions Yes Full browser configuration including process, paths, and logging

Outputs

Name Type Description
context BrowserContext Newly created browser context
contexts BrowserContext[] All active browser contexts
version string Browser version string

Usage Examples

import { Browser } from '../server/browser';

// Browser is abstract; use via subclasses like CRBrowser, BidiBrowser, WKBrowser
const context = await browser.newContext({
  viewport: { width: 1280, height: 720 },
  userAgent: 'custom-agent',
});
const contexts = browser.contexts();
console.log('Browser version:', browser.version());

Related Pages

Page Connections

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