Skip to main content
Browser methods for the Playwright driver.

State Checks

isConnected

Indicates that the browser is connected.
Note: This is async in the remote SDK, unlike the native Playwright API.
Upstream docs
result
boolean
Return value
await browser.isConnected();

Lifecycle

contexts

Returns an array of all open browser contexts.
In a newly created browser, this will return zero browser contexts. Note: This is async in the remote SDK, unlike the native Playwright API.
Upstream docs
result
RemotePlaywrightBrowserContext[]
Return value
await browser.contexts();

newContext

Creates a new browser context. It will not share cookies/cache with other browser contexts.
If directly using this method to create BrowserContexts, it is best practice to explicitly close the returned context via browserContext.close() when your code is done with the BrowserContext, and before calling browser.close().
Upstream docs
options
PlaywrightNewContextOptions
result
RemotePlaywrightBrowserContext
Return value
await browser.newContext();

newPage

Creates a new page in a new browser context. Closing this page will close the context as well.
This is a convenience API that should only be used for single-page scenarios and short snippets. Production code and testing frameworks should explicitly create browser.newContext() followed by browserContext.newPage() to control their exact life times.
Upstream docs
options
PlaywrightNewPageOptions
result
RemotePlaywrightPage
Return value
await browser.newPage();

close

Closes the browser and all of its pages (if any were opened).
The Browser object itself is considered to be disposed and cannot be used anymore. This is similar to force-quitting the browser.
Upstream docs
options
{ reason?: string }
await browser.close();

Other

browserType

Get the browser type name (chromium, firefox, or webkit) that was used to launch this browser.
Note: Returns the name string. This is async in the remote SDK, unlike the native Playwright API.
Upstream docs
result
'chromium' | 'firefox' | 'webkit'
Return value
await browser.browserType();

version

Returns the browser version.
Note: This is async in the remote SDK, unlike the native Playwright API.
Upstream docs
result
string
Return value
await browser.version();

newBrowserCDPSession

Returns the newly created browser session.
CDP Sessions are only supported on Chromium-based browsers.
Upstream docs
result
{ sessionId: string }
Return value
await browser.newBrowserCDPSession();

startTracing

Starts Chromium Tracing.
This is a Chromium-only API. Only one trace can be active at a time per browser.
Upstream docs
page
RemotePlaywrightPage
Optional page to capture screenshots from.
options
PlaywrightStartTracingOptions
Tracing options.
await browser.startTracing();

stopTracing

Stops Chromium Tracing and returns the trace data.
This is a Chromium-only API. Returns the trace data as a Buffer.
Upstream docs
result
Buffer
Return value
await browser.stopTracing();