import BrowserContext from 'chrome-remote-interface-extra/lib/browser/BrowserContext.js'
BrowserContext
Extends:
Constructor Summary
Public Constructor | ||
public |
constructor(connection: Chrome | CRIConnection, browser: Browser, contextId: string) |
Member Summary
Private Members | ||
private |
|
|
private |
_connection: Chrome | CRIConnection |
|
private |
|
Method Summary
Public Methods | ||
public |
The browser this browser context belongs to |
|
public |
async clearPermissionOverrides(): Promise<void> Reset all permissions overrides for this browser context |
|
public |
Closes the browser context. |
|
public |
closeTarget(targetId: string): Promise<boolean> Closes the target specified by the targetId. |
since chrome-remote-interface-extra |
public |
async exposeCDPOnTarget(targetId: string, bindingName: string): Promise<void> Inject object to the target's main frame that provides a communication channel with browser target. Injected object will be available as window[bindingName]. The object has the following API:
EXPERIMENTAL |
since chrome-remote-interface-extra |
public |
getHistogram(name: string, delta: boolean): Promise<CDPHistogram> Get a Chrome histogram by name. |
since chrome-remote-interface-extra |
public |
getHistograms(options: BrowserHistogramQuery): Promise<Array<CDPHistogram>> Get Chrome histograms. |
since chrome-remote-interface-extra |
public |
getWindowBounds(windowId: number): Promise<WindowBounds> Get position and size of the browser window. |
since chrome-remote-interface-extra |
public |
getWindowForTarget(targetId: string): Promise<{bounds: WindowBounds, windowId: number}>{bounds:> Get the browser window that contains the target. |
since chrome-remote-interface-extra |
public |
Returns whether BrowserContext is incognito. |
|
public |
Creates a new page in the browser context |
|
public |
async overridePermissions(origin: string, permissions: Array<string>) Grant specific permissions to the given origin and reject all others. |
|
public |
An array of all pages inside the browser context |
|
public |
async setWindowBounds(windowId: number, bounds: WindowBounds): Promise<void> Set position and/or size of the browser window. |
since chrome-remote-interface-extra |
public |
An array of all active targets inside the browser context |
|
public |
|
|
public |
waitForTarget(predicate: function(target: Target): boolean, options: {timeout?: number}): Promise<Target> This searches for a target in this specific browser context. |
Public Constructors
public constructor(connection: Chrome | CRIConnection, browser: Browser, contextId: string) source
Params:
Name | Type | Attribute | Description |
connection | Chrome | CRIConnection |
|
|
browser | Browser |
|
|
contextId | string |
|
Private Members
private _connection: Chrome | CRIConnection source
Public Methods
public async clearPermissionOverrides(): Promise<void> source
Reset all permissions overrides for this browser context
public async close(): Promise<void> source
Closes the browser context. All the targets that belong to the browser context will be closed.
public closeTarget(targetId: string): Promise<boolean> since chrome-remote-interface-extra source
Closes the target specified by the targetId. If the target is a page that gets closed too.
Params:
Name | Type | Attribute | Description |
targetId | string |
public async exposeCDPOnTarget(targetId: string, bindingName: string): Promise<void> since chrome-remote-interface-extra source
Inject object to the target's main frame that provides a communication channel with browser target.
Injected object will be available as window[bindingName].
The object has the following API:
- binding.send(json) - a method to send messages over the remote debugging protocol
- binding.onmessage = json => handleMessage(json) - a callback that will be called for the protocol notifications and command responses.
EXPERIMENTAL
public getHistogram(name: string, delta: boolean): Promise<CDPHistogram> since chrome-remote-interface-extra source
Get a Chrome histogram by name. EXPERIMENTAL
public getHistograms(options: BrowserHistogramQuery): Promise<Array<CDPHistogram>> since chrome-remote-interface-extra source
Get Chrome histograms. EXPERIMENTAL Optional options:
- query: Requested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms.
- delta: If true, retrieve delta since last call
Params:
Name | Type | Attribute | Description |
options | BrowserHistogramQuery |
|
public getWindowBounds(windowId: number): Promise<WindowBounds> since chrome-remote-interface-extra source
Get position and size of the browser window. EXPERIMENTAL
Params:
Name | Type | Attribute | Description |
windowId | number |
public getWindowForTarget(targetId: string): Promise<{bounds: WindowBounds, windowId: number}>{bounds:> since chrome-remote-interface-extra source
Get the browser window that contains the target. EXPERIMENTAL
Params:
Name | Type | Attribute | Description |
targetId | string |
|
Optional target id of the target to receive the window id and its bound for. If called as a part of the session, associated targetId is used. |
public isIncognito(): boolean source
Returns whether BrowserContext is incognito. The default browser context is the only non-incognito browser context
public async overridePermissions(origin: string, permissions: Array<string>) source
Grant specific permissions to the given origin and reject all others. EXPERIMENTAL
Example:
const context = browser.defaultBrowserContext();
context.overridePermissions('https://example.com', ['clipboard-read']);
// do stuff ..
context.clearPermissionOverrides();
public async setWindowBounds(windowId: number, bounds: WindowBounds): Promise<void> since chrome-remote-interface-extra source
Set position and/or size of the browser window. EXPERIMENTAL
Params:
Name | Type | Attribute | Description |
windowId | number | An browser window id |
|
bounds | WindowBounds | New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged. |
public waitForTarget(predicate: function(target: Target): boolean, options: {timeout?: number}): Promise<Target> source
This searches for a target in this specific browser context.
Example:
await page.evaluate(() => window.open('https://www.example.com/'))
const newWindowTarget = await browserContext.waitForTarget(target => target.url() === 'https://www.example.com/')