BrowsingContext

Represents the contains under BrowsingContext module commands. Described in https://w3c.github.io/webdriver-bidi/#module-browsingContext Each browsing context command requires a browsing context id. Hence, this class represent browsing context lifecycle.

Constructor

new BrowsingContext()

Members

id

Methods

(async) activate() → {Promise.<void>}

Activates and focuses the top-level browsing context.

Throws:

If there is an error while activating the browsing context.

Type
Error
Returns:

A promise that resolves when the browsing context is activated.

Type: 
Promise.<void>

(async) back() → {Promise.<void>}

Navigates the browsing context to the previous page in the history.

Returns:

A promise that resolves when the navigation is complete.

Type: 
Promise.<void>

(async) captureElementScreenshot(sharedId, handleopt) → {Promise.<string>}

Captures a screenshot of a specific element within the browsing context.

Parameters:
NameTypeAttributesDescription
sharedIdstring

The shared ID of the element to capture.

handlestring<optional>

The handle of the element to capture (optional).

Returns:

A promise that resolves to the base64-encoded screenshot data.

Type: 
Promise.<string>

(async) captureScreenshot(captureScreenshotParametersopt) → {Promise.<string>}

Captures a screenshot of the browsing context.

Parameters:
NameTypeAttributesDescription
captureScreenshotParametersCaptureScreenshotParameters | undefined<optional>

Optional parameters for capturing the screenshot.

Throws:
  • If the provided captureScreenshotParameters is not an instance of CaptureScreenshotParameters.
Type
InvalidArgumentError
Returns:
  • A promise that resolves to the base64-encoded string representation of the captured screenshot.
Type: 
Promise.<string>

(async) close() → {Promise.<void>}

Closes the browsing context

Returns:
Type: 
Promise.<void>

(async) create()

Creates a browsing context for the given type with the given parameters

(async) forward() → {Promise.<void>}

Moves the browsing context forward by one step in the history.

Returns:

A promise that resolves when the browsing context has moved forward.

Type: 
Promise.<void>

(async) getTopLevelContexts() → {Promise.<Array.<BrowsingContextInfo>>}

Returns:

A Promise that resolves to an array of BrowsingContextInfo objects representing the top-level browsing contexts.

Type: 
Promise.<Array.<BrowsingContextInfo>>

(async) getTree(maxDepth)

Parameters:
NameTypeDescription
maxDepth

the max depth of the descendents of browsing context tree

Returns:

BrowsingContextInfo object

(async) handleUserPrompt(acceptopt, userTextopt)

Handles a user prompt in the browsing context.

Parameters:
NameTypeAttributesDescription
acceptboolean<optional>

Optional. Indicates whether to accept or dismiss the prompt.

userTextstring<optional>

Optional. The text to enter.

Throws:

If an error occurs while handling the user prompt.

Type
Error

(async) locateNode(locator, sandboxopt, serializationOptionsopt, startNodesopt) → {Promise.<RemoteValue>}

Locates a single node in the browsing context.

Parameters:
NameTypeAttributesDescription
locatorLocator

The locator used to find the node.

sandboxstring<optional>

The sandbox of the node (optional).

serializationOptionsSerializationOptions<optional>

The serialization options for the node (optional).

startNodesArray<optional>

The starting nodes for the search (optional).

Returns:
  • A promise that resolves to the located node.
Type: 
Promise.<RemoteValue>

(async) locateNodes(locator, maxNodeCountopt, sandboxopt, serializationOptionsopt, startNodesopt) → {Promise.<Array.<RemoteValue>>}

Locates nodes in the browsing context.

Parameters:
NameTypeAttributesDescription
locatorLocator

The locator object used to locate the nodes.

maxNodeCountnumber<optional>

The maximum number of nodes to locate (optional).

sandboxstring<optional>

The sandbox name for locating nodes (optional).

serializationOptionsSerializationOptions<optional>

The serialization options for locating nodes (optional).

startNodesArray.<ReferenceValue><optional>

The array of start nodes for locating nodes (optional).

Throws:
    • If the locator is not an instance of Locator.
    Type
    Error
    • If the serializationOptions is provided but not an instance of SerializationOptions.
    Type
    Error
    • If the startNodes is provided but not an array of ReferenceValue objects.
    Type
    Error
    • If any of the startNodes is not an instance of ReferenceValue.
    Type
    Error
Returns:
  • A promise that resolves to the arrays of located nodes.
Type: 
Promise.<Array.<RemoteValue>>
Parameters:
NameTypeDescription
url

the url to navigate to

readinessState

type of readiness state: "none" / "interactive" / "complete"

Returns:

NavigateResult object

(async) printPage(options)

Prints PDF of the webpage

Parameters:
NameTypeDescription
options

print options given by the user

Returns:

PrintResult object

(async) reload(ignoreCacheopt, readinessStateopt) → {Promise.<NavigateResult>}

Reloads the current browsing context.

Parameters:
NameTypeAttributesDescription
ignoreCacheboolean<optional>

Whether to ignore the cache when reloading.

readinessStatestring<optional>

The readiness state to wait for before returning. Valid readiness states are 'none', 'interactive', and 'complete'.

Throws:
  • If an invalid readiness state is provided.
Type
Error
Returns:
  • A promise that resolves to the result of the reload operation.
Type: 
Promise.<NavigateResult>

(async) setViewport(width, height, devicePixelRatioopt)

Sets the viewport size and device pixel ratio for the browsing context.

Parameters:
NameTypeAttributesDescription
widthnumber

The width of the viewport.

heightnumber

The height of the viewport.

devicePixelRationumber<optional>

The device pixel ratio (optional)

Throws:

If an error occurs while setting the viewport.

Type
Error

(async) traverseHistory(delta) → {Promise.<void>}

Traverses the browsing context history by a given delta.

Parameters:
NameTypeDescription
deltanumber

The delta value to traverse the history. A positive value moves forward, while a negative value moves backward.

Returns:
  • A promise that resolves when the history traversal is complete.
Type: 
Promise.<void>