*** title: Playwright Browser description: Complete Browser method reference for the Playwright driver. ------------------------------------------------------------------------- All `Browser` methods available when using the **Playwright** driver. Access via `runtime.browser` after launching a Playwright runtime. Every method below is a remote call. The SDK translates it into a structured step sent to a single endpoint: ``` POST /v1/workspaces/{workspaceId}/execute ``` ```json { "runtime": "my-browser", "steps": [ { "call": "browser.goto", "args": ["https://example.com"] } ] } ``` The `call` field maps directly to the method name. `args` is a JSON array of the method's arguments. You can batch multiple steps in one request. ## State Checks ### isConnected() Indicates that the browser is connected. Note: This is async in the remote SDK, unlike the native Playwright API. ```ts await runtime.browser.isConnected(); ``` **Returns** `boolean` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-is-connected) *** ## 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. ```ts await runtime.browser.contexts(); ``` **Returns** `RemotePlaywrightBrowserContext[]` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-contexts) *** ### newContext(options?) 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(). ```ts await runtime.browser.newContext(); ``` | Parameter | Type | Required | Description | | --------- | ----------------------------- | -------- | ----------- | | `options` | `PlaywrightNewContextOptions` | No | — | **Returns** `RemotePlaywrightBrowserContext` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-new-context) *** ### newPage(options?) 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. ```ts await runtime.browser.newPage(); ``` | Parameter | Type | Required | Description | | --------- | -------------------------- | -------- | ----------- | | `options` | `PlaywrightNewPageOptions` | No | — | **Returns** `RemotePlaywrightPage` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-new-page) *** ### close(options?) 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. ```ts await runtime.browser.close(); ``` | Parameter | Type | Required | Description | | --------- | --------------------- | -------- | ----------- | | `options` | `{ reason?: string }` | No | — | [Upstream docs](https://playwright.dev/docs/api/class-browser#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. ```ts await runtime.browser.browserType(); ``` **Returns** `'chromium' \| 'firefox' \| 'webkit'` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-browser-type) *** ### version() Returns the browser version. Note: This is async in the remote SDK, unlike the native Playwright API. ```ts await runtime.browser.version(); ``` **Returns** `string` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-version) *** ### newBrowserCDPSession() Returns the newly created browser session. CDP Sessions are only supported on Chromium-based browsers. ```ts await runtime.browser.newBrowserCDPSession(); ``` **Returns** `{ sessionId: string }` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-new-browser-cdp-session) *** ### startTracing(page?, options?) Starts Chromium Tracing. This is a Chromium-only API. Only one trace can be active at a time per browser. ```ts await runtime.browser.startTracing(); ``` | Parameter | Type | Required | Description | | --------- | ------------------------------- | -------- | ------------------------------------------ | | `page` | `HasHandleId` | No | Optional page to capture screenshots from. | | `options` | `PlaywrightStartTracingOptions` | No | Tracing options. | [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-start-tracing) *** ### stopTracing() Stops Chromium Tracing and returns the trace data. This is a Chromium-only API. Returns the trace data as a Buffer. ```ts await runtime.browser.stopTracing(); ``` **Returns** `Buffer` [Upstream docs](https://playwright.dev/docs/api/class-browser#browser-stop-tracing) ***