Home Reference Source
public class | source

Browser

Extends:

eventemitter3~EventEmitter → Browser

See:

Static Method Summary

Static Public Methods
public static

async connect(browserWSEndpoint: string, initOpts: BrowserInitOptions): Browser

public static

async create(connection: Chrome | CRIConnection | Object, initOpts: BrowserInitOptions): Browser

Constructor Summary

Public Constructor
public

constructor(connection: Chrome | CRIConnection, initOpts: BrowserInitOptions)

Member Summary

Private Members
private
private

_closeCallback: * | dummyCloseCB

private
private
private
private
private
private
private
private
private

Method Summary

Public Methods
public

Returns an array of all open browser contexts.

public

async close(): Promise<void>

Closes all of its pages (if any were opened) and the Browser object itself is considered to be disposed and cannot be used anymore

public

closeTarget(targetId: string, throwOnError: boolean): Promise<boolean>

Closes the target specified by the targetId.

since chrome-remote-interface-extra
public

Creates a new incognito browser context.

public

Returns the default browser context.

public

Disconnect from the browser After calling disconnect, the Browser object is considered disposed and cannot be used anymore

public

Get a Chrome histogram by name.

since chrome-remote-interface-extra
public

Get Chrome histograms.

since chrome-remote-interface-extra
public

Returns the target associated with the supplied target id if we know about it

since chrome-remote-interface-extra
public

Get position and size of the browser window.

since chrome-remote-interface-extra
public

getWindowForTarget(targetId: string): Promise<{bounds: WindowBounds, windowId: number}>

Get the browser window that contains the target.

since chrome-remote-interface-extra
public

async grantPermissions(origin: string, permissions: Array<string>, browserContextId: string): Promise<void>

Grant specific permissions to the given origin and reject all others.

public

Returns all browser contexts created with Target.createBrowserContext method.

since chrome-remote-interface-extra
public

Retrieves a list of available targets

since chrome-remote-interface-extra
public

async newPage(): Promise<Page>

Promise which resolves to a new Page object.

public

async pages(): Promise<Array<Page>>

An array of all pages inside the Browser.

public
public

async resetPermissions(browserContextId: string): Promise<void>

Reset all permission management for all origins.

public

async setWindowBounds(windowId: number, bounds: WindowBounds): Promise<void>

Set position and/or size of the browser window.

since chrome-remote-interface-extra
public

Returns the target associated with the browser

public

Returns all known targets

public
public
public
public

async version(): Promise<string>

public

versionInfo(): Promise<{protocolversion: string, product: string, revision: string, userAgent: string, jsVersion: string}>

Returns version information

since chrome-remote-interface-extra
public

async waitForTarget(predicate: function(target: Target): boolean, options: {timeout?: number}): Promise<Target>

This searches for a target in all browser contexts

public
Private Methods
private

async _createPageInContext(contextId: string): Promise<Page>

private

async _disposeContext(contextId: string)

private

async _targetCreated(event: Object)

private

async _targetDestroyed(event: {targetId: string})

private

Static Public Methods

public static async connect(browserWSEndpoint: string, initOpts: BrowserInitOptions): Browser source

Params:

NameTypeAttributeDescription
browserWSEndpoint string
initOpts BrowserInitOptions
  • optional
  • default: {}

Return:

Browser

public static async create(connection: Chrome | CRIConnection | Object, initOpts: BrowserInitOptions): Browser source

Params:

NameTypeAttributeDescription
connection Chrome | CRIConnection | Object
initOpts BrowserInitOptions
  • optional
  • default: {}

Return:

Browser

Public Constructors

public constructor(connection: Chrome | CRIConnection, initOpts: BrowserInitOptions) source

Params:

NameTypeAttributeDescription
connection Chrome | CRIConnection
  • nullable: false
initOpts BrowserInitOptions

Private Members

private _additionalDomains: EnabledExtras source

private _closeCallback: * | dummyCloseCB source

private _connection: Chrome | CRIConnection source

private _contexts: Map<string, BrowserContext> source

private _defaultContext: BrowserContext source

private _defaultViewport: Object source

private _ignoreHTTPSErrors: boolean source

private _process: Object source

private _screenshotTaskQueue: TaskQueue source

private _targets: Map<string, Target> source

private _webPermissionToProtocol: Map<string, string> source

Public Methods

public browserContexts(): Array<BrowserContext> source

Returns an array of all open browser contexts. In a newly created browser, this will return a single instance of BrowserContext

public async close(): Promise<void> source

Closes all of its pages (if any were opened) and the Browser object itself is considered to be disposed and cannot be used anymore

Return:

Promise<void>

public closeTarget(targetId: string, throwOnError: boolean): 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. Returns T/F to indicate if the command was successful

Params:

NameTypeAttributeDescription
targetId string

The id of the target to be closed

throwOnError boolean
  • optional

If true and the command was un-successful the caught error is thrown

Return:

Promise<boolean>

See:

public async createIncognitoBrowserContext(): Promise<BrowserContext> source

Creates a new incognito browser context. This won't share cookies/cache with other browser contexts

public defaultBrowserContext(): BrowserContext source

Returns the default browser context. The default browser context can not be closed

Return:

BrowserContext (nullable: false)

public disconnect() source

Disconnect from the browser After calling disconnect, the Browser object is considered disposed and cannot be used anymore

public getHistogram(name: string, delta: boolean): Promise<CDPHistogram> since chrome-remote-interface-extra source

Get a Chrome histogram by name. EXPERIMENTAL

Params:

NameTypeAttributeDescription
name string

Requested histogram name

delta boolean
  • optional

If true, retrieve delta since last call

See:

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:

NameTypeAttributeDescription
options BrowserHistogramQuery
  • optional

See:

public getTargetById(targetId: string): Target since chrome-remote-interface-extra source

Returns the target associated with the supplied target id if we know about it

Params:

NameTypeAttributeDescription
targetId string

Return:

Target (nullable: true)

public getWindowBounds(windowId: number): Promise<WindowBounds> since chrome-remote-interface-extra source

Get position and size of the browser window. EXPERIMENTAL

Params:

NameTypeAttributeDescription
windowId number

See:

public getWindowForTarget(targetId: string): Promise<{bounds: WindowBounds, windowId: number}> since chrome-remote-interface-extra source

Get the browser window that contains the target. EXPERIMENTAL

Params:

NameTypeAttributeDescription
targetId string
  • optional

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.

Return:

Promise<{bounds: WindowBounds, windowId: number}>

See:

public async grantPermissions(origin: string, permissions: Array<string>, browserContextId: string): Promise<void> source

Grant specific permissions to the given origin and reject all others. EXPERIMENTAL

Params:

NameTypeAttributeDescription
origin string

The origin these permissions will be granted for

permissions Array<string>

Array of permission overrides

browserContextId string
  • optional

BrowserContext to override permissions. When omitted, default browser context is used

Return:

Promise<void>

See:

public async listBrowserContexts(): Promise<Array<string>> since chrome-remote-interface-extra source

Returns all browser contexts created with Target.createBrowserContext method. EXPERIMENTAL

Return:

Promise<Array<string>>

An array of browser context ids

See:

public async listTargets(): Promise<Array<CDPTargetInfo>> since chrome-remote-interface-extra source

Retrieves a list of available targets

See:

public async newPage(): Promise<Page> source

Promise which resolves to a new Page object. The Page is created in a default browser context

Return:

Promise<Page>

public async pages(): Promise<Array<Page>> source

An array of all pages inside the Browser. In case of multiple browser contexts, the method will return an array with all the pages in all browser contexts

Return:

Promise<Array<Page>>

public process(): Object source

Return:

Object (nullable: true)

public async resetPermissions(browserContextId: string): Promise<void> source

Reset all permission management for all origins. EXPERIMENTAL

Params:

NameTypeAttributeDescription
browserContextId string
  • optional

BrowserContext to reset permissions. When omitted, default browser context is used.

Return:

Promise<void>

See:

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:

NameTypeAttributeDescription
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.

Return:

Promise<void>

See:

public target(): Target source

Returns the target associated with the browser

Return:

Target (nullable: false)

public targets(): Array<Target> source

Returns all known targets

Return:

Array<Target>

public toJSON(): Object source

Return:

Object

public toString(): string source

Return:

string

public async userAgent(): Promise<string> source

Return:

Promise<string>

public async version(): Promise<string> source

Return:

Promise<string>

public versionInfo(): Promise<{protocolversion: string, product: string, revision: string, userAgent: string, jsVersion: string}> since chrome-remote-interface-extra source

Returns version information

Return:

Promise<{protocolversion: string, product: string, revision: string, userAgent: string, jsVersion: string}>

See:

public async waitForTarget(predicate: function(target: Target): boolean, options: {timeout?: number}): Promise<Target> source

This searches for a target in all browser contexts

Params:

NameTypeAttributeDescription
predicate function(target: Target): boolean
options {timeout?: number}
  • optional
  • default: {}

Return:

Promise<Target>

Example:

// finding a target for a page opened via window.open
await page.evaluate(() => window.open('https://www.example.com/'))
const newWindowTarget = await browser.waitForTarget(target => target.url() === 'https://www.example.com/')

public wsEndpoint(): string source

Return:

string

Private Methods

private async _createPageInContext(contextId: string): Promise<Page> source

Params:

NameTypeAttributeDescription
contextId string
  • nullable: true

Return:

Promise<Page>

private async _disposeContext(contextId: string) source

Params:

NameTypeAttributeDescription
contextId string
  • nullable: true

private async _targetCreated(event: Object) source

Params:

NameTypeAttributeDescription
event Object
  • nullable: false

private async _targetDestroyed(event: {targetId: string}) source

Params:

NameTypeAttributeDescription
event {targetId: string}

private _targetInfoChanged(event: Object) source

Params:

NameTypeAttributeDescription
event Object
  • nullable: false