Skip to main content
Browser represents a browser instance that can contain multiple isolated browser contexts.

Inheritance

Extends: ChannelOwner Implements: EventEmitter

Events

  • disconnected: Emitted when browser disconnects

Methods

browserType

Returns the browser type that was used to launch this browser.
Returns: BrowserType - The browser type (chromium, firefox, or webkit)

newContext

Creates a new browser context.
BrowserContextOptions
Context configuration options
  • viewport (object | null): Viewport size
  • userAgent (string): User agent string
  • locale (string): Locale (e.g., ‘en-US’)
  • timezoneId (string): Timezone (e.g., ‘America/New_York’)
  • permissions (string[]): Granted permissions
  • geolocation (object): Geolocation
  • colorScheme (‘light’ | ‘dark’ | ‘no-preference’): Color scheme
  • extraHTTPHeaders (object): Extra HTTP headers
  • offline (boolean): Emulate network offline
  • httpCredentials (object): HTTP credentials
  • deviceScaleFactor (number): Device scale factor
  • isMobile (boolean): Whether to emulate mobile device
  • hasTouch (boolean): Whether to support touch events
  • storageState (string | object): Storage state to initialize context with
Returns: Promise<BrowserContext> - New browser context

contexts

Returns all open browser contexts.
Returns: BrowserContext[] - Array of all browser contexts

newPage

Creates a new page in a new context.
BrowserContextOptions
Context options (same as newContext)
Returns: Promise<Page> - New page in a new context Note: The context will be closed when the page is closed

version

Returns browser version.
Returns: string - Browser version string

isConnected

Indicates whether browser is connected.
Returns: boolean - True if browser is connected

close

Closes the browser and all its contexts.
object
Close options
  • reason (string): Optional reason for closing
Returns: Promise<void>

newBrowserCDPSession

Creates a new Chrome DevTools Protocol session.
Returns: Promise<CDPSession> - CDP session Note: Only available for Chromium

startTracing

Starts tracing.
Page
Page to trace (all pages if not specified)
object
Tracing options
  • path (string): File path to save trace to
  • screenshots (boolean): Capture screenshots
  • categories (string[]): Tracing categories
Returns: Promise<void> Note: Only available for Chromium

stopTracing

Stops tracing and returns trace data.
Returns: Promise<Buffer> - Trace data Note: Only available for Chromium

Usage Examples

Basic Browser Usage

Multiple Contexts

Quick Page Creation

Browser Events

CDP Session (Chromium)