Skip to main content

Browser Types

Playwright supports three browser engines out of the box:

Chromium

Google Chrome and Microsoft Edge

Firefox

Mozilla Firefox

WebKit

Apple Safari

Launching Browsers

Basic Launch

Launch Options

From server/browserType.ts:66, the launch() method validates options and manages the browser process lifecycle.

Browser Class

The Browser class (client/browser.ts:31) represents a running browser instance:

Browser Lifecycle

1

Launch

Browser process starts
2

Create Contexts

Multiple isolated sessions
3

Use Browser

Perform automation tasks
4

Close

Clean up resources

Browser Connection State

From client/browser.ts:147-194:

Browser Properties

Version Information

Browser Type

Multiple Contexts Pattern

Browsers can host multiple independent contexts, which is much more efficient than launching multiple browsers:
Always close browsers to prevent resource leaks. Unclosed browsers continue running in the background.

Persistent Context

Launch a browser with persistent storage (user data directory):
From server/browserType.ts:74:

Remote Browser Connection

Connect to a browser running on another machine:

Browser Server

Start a browser server for remote connections:

CDP Session (Chromium Only)

Access Chrome DevTools Protocol directly:
From client/browser.ts:151:

Error Handling

Browser Process Management

Playwright automatically manages browser processes:
  1. Process Launch - Starts browser with appropriate flags
  2. Connection Setup - Establishes WebSocket or pipe communication
  3. Protocol Initialization - Sets up CDP/Juggler/Inspector protocol
  4. Context Management - Tracks all browser contexts
  5. Cleanup - Terminates browser process on close
From server/browserType.ts, the browser launch flow includes:
  • Option validation
  • Executable path resolution
  • Process spawning
  • Connection establishment
  • Protocol handshake

Best Practices

Launch once, create multiple contexts. Contexts are lightweight.
Use try-finally or async disposal to ensure cleanup.
Listen for disconnection events.

Browser Arguments

Customize browser behavior with command-line arguments:
Disabling security features is dangerous. Only use in controlled test environments.

Next Steps

Browser Contexts

Learn about isolated browser sessions

Pages and Frames

Working with tabs and iframes

Test Isolation

Ensuring test independence