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.59Binds 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 of the browser server, used for identification.
-
optionsObject (optional)-
Host to bind the web socket server to. When specified, a web socket server is created instead of a named pipe.
-
metadataObject<string, Object> (optional)#Additional metadata to associate with the browser server.
-
Port to bind the web socket server to. When specified, a web socket server is created instead of a named pipe. Use
0to let the OS pick an available port. -
workspaceDirstring (optional)#Working directory associated with this browser server.
-
Returns
browserType
Added in: v1.23Get the browser type (chromium, firefox or webkit) that the browser belongs to.
Usage
browser.browserType();
Returns
close
Added before v1.9In 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.
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