6.9 KiB
sidebar_label |
---|
Browser |
Browser class
Browser represents a browser instance that is either:
- connected to via Puppeteer.connect() or - launched by PuppeteerNode.launch().
Browser emits various events which are documented in the BrowserEvent enum.
Signature:
export declare abstract class Browser extends EventEmitter<BrowserEvents>
Extends: EventEmitter<BrowserEvents>
Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Browser
class.
Example 1
Using a Browser to create a Page:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
Example 2
Disconnecting from and reconnecting to a Browser:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
// Store the endpoint to be able to reconnect to the browser.
const browserWSEndpoint = browser.wsEndpoint();
// Disconnect puppeteer from the browser.
await browser.disconnect();
// Use the endpoint to reestablish a connection
const browser2 = await puppeteer.connect({browserWSEndpoint});
// Close the browser.
await browser2.close();
Properties
Property |
Modifiers |
Type |
Description |
---|---|---|---|
connected |
|
boolean |
Whether Puppeteer is connected to this browser. |
debugInfo |
|
Get debug information from Puppeteer. |
Methods
Method |
Modifiers |
Description |
---|---|---|
Gets a list of open browser contexts. In a newly-created browser, this will return a single instance of BrowserContext. | ||
Creates a new browser context. This won't share cookies/cache with other browser contexts. | ||
Gets the default browser context. | ||
Disconnects Puppeteer from this browser, but leaves the process running. | ||
|
Whether Puppeteer is connected to this browser. Deprecated: Use Browser.connected. | |
Creates a new page in the default browser context. | ||
Gets a list of all open pages inside this Browser. If there ar multiple browser contexts, this returns all pages in all browser contexts. | ||
Gets the associated ChildProcess. | ||
Gets the target associated with the default browser context). | ||
Gets all active targets. In case of multiple browser contexts, this returns all targets in all browser contexts. | ||
Gets this browser's original user agent. Pages can override the user agent with Page.setUserAgent(). | ||
Gets a string representing this browser's name and version. For headless browser, this is similar to The format of Browser.version() might change with future releases of browsers. | ||
Waits until a target matching the given This will look all open browser contexts. | ||
Gets the WebSocket URL to connect to this browser. This is usually used with Puppeteer.connect(). You can find the debugger URL ( See browser endpoint for more information. |