Implementation:Microsoft Playwright Chromium BrowserType
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Chromium Engine |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for launching and connecting to Chromium-based browsers provided by the Playwright library.
Description
The `Chromium` class extends the abstract `BrowserType` to provide Chromium-specific browser launch and connection logic. It manages Chromium command-line switches, DevTools integration via `CRDevTools`, and supports both CDP (Chrome DevTools Protocol) and BiDi (WebDriver Bidirectional) transports. The class handles Chromium-specific features like `connectOverCDP` for connecting to existing Chrome instances, constructs the appropriate launch arguments including GPU settings, font rendering, and sandbox configuration, and manages artifact folder cleanup. It delegates to `CRBrowser.connect` for establishing the protocol connection and supports a fallback to the BiDi protocol through the `_bidiChromium` reference.
Usage
Use this class to launch or connect to Chromium, Chrome, or Edge browsers. It is the entry point for all Chromium-based browser automation on the server side.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/chromium/chromium.ts
Signature
export class Chromium extends BrowserType {
private _devtools: CRDevTools | undefined;
private _bidiChromium: BrowserType;
constructor(parent: SdkObject, bidiChromium: BrowserType);
async connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<Browser>;
async connectOverCDP(metadata: CallMetadata, wsEndpoint: string, options: channels.BrowserTypeConnectOverCDPParams): Promise<Browser>;
}
Import
import { Chromium } from '../server/chromium/chromium';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| parent | SdkObject | Yes | Parent SDK object for instrumentation |
| bidiChromium | BrowserType | Yes | BiDi-based Chromium browser type for WebDriver BiDi fallback |
| transport | ConnectionTransport | Yes | Transport connection to the browser process |
| options | BrowserOptions | Yes | Browser launch configuration |
| wsEndpoint | string | Yes | WebSocket endpoint for CDP connection (connectOverCDP) |
Outputs
| Name | Type | Description |
|---|---|---|
| Browser | CRBrowser | Connected Chromium browser instance |
Usage Examples
const chromium = new Chromium(parentSdkObject, bidiChromiumType);
// Launch a new browser
const browser = await chromium.launch({
headless: true,
args: ['--disable-gpu'],
});
// Or connect to existing Chrome via CDP
const browser = await chromium.connectOverCDP(metadata, 'ws://localhost:9222/devtools/browser/...');