Implementation:Microsoft Playwright BrowserServerLauncher
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Server Infrastructure |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for launching browser instances as remote WebSocket servers provided by the Playwright library.
Description
BrowserServerLauncherImpl implements the BrowserServerLauncher interface and is responsible for launching a browser process, starting a PlaywrightServer WebSocket endpoint, and returning a BrowserServer object that exposes methods to access the underlying process, the WebSocket endpoint, and lifecycle controls (close/kill). It supports Chromium, Firefox, and WebKit browsers. The launcher validates launch parameters, handles both regular and persistent context launches, and sets up protocol logging when a logger is provided. It also includes helper functions toProtocolLogger for adapting the client logger to the server protocol logger, and envObjectToArray for converting environment variable objects to the array format expected by the server.
Usage
Use BrowserServerLauncherImpl when you need to launch a browser as a standalone server process that remote clients can connect to via WebSocket. This is the server-side counterpart to browserType.launchServer() and is typically used in distributed testing or remote browser scenarios.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File:
packages/playwright-core/src/browserServerImpl.ts
Signature
export class BrowserServerLauncherImpl implements BrowserServerLauncher {
private _browserName: 'chromium' | 'firefox' | 'webkit';
constructor(browserName: 'chromium' | 'firefox' | 'webkit');
async launchServer(options?: LaunchServerOptions & {
_sharedBrowser?: boolean;
_userDataDir?: string;
}): Promise<BrowserServer>;
}
Import
import { BrowserServerLauncherImpl } from 'playwright-core/src/browserServerImpl';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| browserName | 'firefox' \| 'webkit' | Yes | The browser engine to launch (constructor parameter) |
| options | LaunchServerOptions & { _sharedBrowser?: boolean; _userDataDir?: string } |
No | Server launch options including port, host, wsPath, environment variables, logger, timeout, and internal flags for shared browser mode and user data directory |
Outputs
| Name | Type | Description |
|---|---|---|
| BrowserServer | BrowserServer |
An EventEmitter-based object with process(), wsEndpoint(), close(), and kill() methods, plus a 'close' event
|
Usage Examples
const launcher = new BrowserServerLauncherImpl('chromium');
const server = await launcher.launchServer({
port: 3000,
wsPath: '/browser',
});
console.log(server.wsEndpoint()); // ws://localhost:3000/browser
server.on('close', (exitCode, signal) => {
console.log('Browser server closed', exitCode, signal);
});
// Later: shut down
await server.close();