Skip to main content

Browser

A Browser is created via browserType.launch(). An example of using a Browser to create a Page:

const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.

(async () => {
const browser = await firefox.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
})();

Methods​

bind​

Added in: v1.59 browser.bind

Binds the browser to a named pipe or web socket, making it available for other clients to connect to.

Usage

await browser.bind(title);
await browser.bind(title, options);

Arguments

  • title string#

    Title of the browser server, used for identification.

  • options Object (optional)

    • host string (optional)#

      Host to bind the web socket server to. When specified, a web socket server is created instead of a named pipe.

    • metadata Object<string, Object> (optional)#

      Additional metadata to associate with the browser server.

    • port number (optional)#

      Port to bind the web socket server to. When specified, a web socket server is created instead of a named pipe. Use 0 to let the OS pick an available port.

    • workspaceDir string (optional)#

      Working directory associated with this browser server.

Returns


browserType​

Added in: v1.23 browser.browserType

Get the browser type (chromium, firefox or webkit) that the browser belongs to.

Usage

browser.browserType();

Returns


close​

Added before v1.9 browser.close

In case this browser is obtained using browserType.launch(), closes the browser and all of its pages (if any were opened).

In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the browser server.

note

This is similar to force-quitting the browser. To close pages gracefully and ensure you receive page close events, call browserContext.close() on any BrowserContext instances you explicitly created earlier using browser.newContext() before calling browser.close().

The Browser object itself is considered to be disposed and cannot be used anymore.

Usage