Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nikolay Vitkov <nvitkov@chromium.org>
4.3 KiB
sidebar_label |
---|
BrowserContext |
BrowserContext class
BrowserContext represents individual user contexts within a browser.
When a browser is launched, it has a single browser context by default. Others can be created using Browser.createBrowserContext(). Each context has isolated storage (cookies/localStorage/etc.)
BrowserContext emits various events which are documented in the BrowserContextEvent enum.
If a page opens another page, e.g. using window.open
, the popup will belong to the parent page's browser context.
Signature:
export declare abstract class BrowserContext extends EventEmitter<BrowserContextEvents>
Extends: EventEmitter<BrowserContextEvents>
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 BrowserContext
class.
Example
Creating a new browser context:
// Create a new browser context
const context = await browser.createBrowserContext();
// Create a new page inside context.
const page = await context.newPage();
// ... do stuff with page ...
await page.goto('https://example.com');
// Dispose context once it's no longer needed.
await context.close();
Properties
Property |
Modifiers |
Type |
Description |
---|---|---|---|
closed |
|
boolean |
Whether this browser context is closed. |
id |
|
string | undefined |
Identifier for this browser context. |
Methods
Method |
Modifiers |
Description |
---|---|---|
Gets the browser associated with this browser context. | ||
Clears all permission overrides for this browser context. | ||
Closes this browser context and all associated pages. | ||
Whether this browser context is incognito. In Chrome, the default browser context is the only non-incognito browser context. | ||
Creates a new page in this browser context. | ||
Grants this browser context the given | ||
Gets a list of all open pages inside this browser context. | ||
Gets all active targets inside this browser context. | ||
Waits until a target matching the given This will look all open browser contexts. |