ScriptManager

Represents class to run events and commands of Script module. Described in https://w3c.github.io/webdriver-bidi/#module-script.

Constructor

new ScriptManager()

Methods

(async) addPreloadScript(functionDeclaration, argumentValueListopt, sandbox|nullopt) → {Promise.<number>}

Adds a preload script.

Parameters:
NameTypeAttributesDefaultDescription
functionDeclarationstring

The declaration of the function to be added as a preload script.

argumentValueListArray.<LocalValue><optional>
[]

The list of argument values to be passed to the preload script function.

sandbox|nullstring<optional>

The sandbox object to be used for the preload script.

Returns:
  • A promise that resolves to the added preload script ID.
Type: 
Promise.<number>

(async) callFunctionInBrowsingContext(realmId, functionDeclaration, awaitPromise, argumentValueList|nullopt, thisParameter|nullopt, resultOwnership|nullopt) → {Promise.<(EvaluateResultSuccess|EvaluateResultException)>}

Calls a function in the specified browsing context.

Parameters:
NameTypeAttributesDescription
realmIdstring

The ID of the browsing context.

functionDeclarationstring

The function to call.

awaitPromiseboolean

Whether to await the promise returned by the function.

argumentValueList|nullArray.<LocalValue><optional>

The list of argument values to pass to the function.

thisParameter|nullObject<optional>

The value of 'this' parameter for the function.

resultOwnership|nullResultOwnership<optional>

The ownership of the result.

Returns:
  • A promise that resolves to the evaluation result or exception.
Type: 
Promise.<(EvaluateResultSuccess|EvaluateResultException)>

(async) callFunctionInRealm(realmId, functionDeclaration, awaitPromise, argumentValueList|nullopt, thisParameter|nullopt, resultOwnership|nullopt) → {Promise.<(EvaluateResultSuccess|EvaluateResultException)>}

Calls a function in the specified realm.

Parameters:
NameTypeAttributesDescription
realmIdstring

The ID of the realm.

functionDeclarationstring

The function to call.

awaitPromiseboolean

Whether to await the promise returned by the function.

argumentValueList|nullArray.<LocalValue><optional>

The list of argument values to pass to the function.

thisParameter|nullObject<optional>

The value of 'this' parameter for the function.

resultOwnership|nullResultOwnership<optional>

The ownership of the result.

Returns:
  • A promise that resolves to the evaluation result or exception.
Type: 
Promise.<(EvaluateResultSuccess|EvaluateResultException)>

(async) disownBrowsingContextScript(browsingContextId, handles, sandboxopt) → {Promise.<void>}

Disowns the handles in the specified browsing context.

Parameters:
NameTypeAttributesDefaultDescription
browsingContextIdstring

The ID of the browsing context.

handlesArray.<string>

The handles to disown to allow garbage collection.

sandboxString | null<optional>
null

The sandbox name.

Returns:
  • A promise that resolves when the command is sent.
Type: 
Promise.<void>

(async) disownRealmScript(realmId, handles) → {Promise.<void>}

Disowns the handles in the specified realm.

Parameters:
NameTypeDescription
realmIdstring

The ID of the realm.

handlesArray.<string>

The handles to disown to allow garbage collection.

Returns:
  • A promise that resolves when the command is sent.
Type: 
Promise.<void>

(async) evaluateFunctionInBrowsingContext(realmId, expression, awaitPromise, resultOwnership) → {Promise.<(EvaluateResultSuccess|EvaluateResultException)>}

Evaluates a function in the browsing context.

Parameters:
NameTypeDescription
realmIdstring

The ID of the browsing context.

expressionstring

The expression to function to evaluate.

awaitPromiseboolean

Whether to await the promise.

resultOwnershipResultOwnership | null

The ownership of the result.

Returns:
  • A promise that resolves to the evaluation result or exception.
Type: 
Promise.<(EvaluateResultSuccess|EvaluateResultException)>

(async) evaluateFunctionInRealm(realmId, expression, awaitPromise, resultOwnership) → {Promise.<(EvaluateResultSuccess|EvaluateResultException)>}

Evaluates a function in the specified realm.

Parameters:
NameTypeDefaultDescription
realmIdstring

The ID of the realm.

expressionstring

The expression to function to evaluate.

awaitPromiseboolean

Whether to await the promise.

resultOwnershipResultOwnership | nullnull

The ownership of the result.

Returns:
  • A promise that resolves to the evaluation result or exception.
Type: 
Promise.<(EvaluateResultSuccess|EvaluateResultException)>

(async) getAllRealms() → {Promise.<Array.<RealmInfo>>}

Retrieves all realms.

Returns:
  • A promise that resolves to an array of RealmInfo objects.
Type: 
Promise.<Array.<RealmInfo>>

(async) getRealmsByType(type) → {Promise.<Array.<RealmInfo>>}

Retrieves the realms by type.

Parameters:
NameTypeDescription
typeType

The type of realms to retrieve.

Returns:
  • A promise that resolves to an array of RealmInfo objects.
Type: 
Promise.<Array.<RealmInfo>>

(async) getRealmsInBrowsingContext(browsingContext) → {Promise.<Array.<RealmInfo>>}

Retrieves the realms in the specified browsing context.

Parameters:
NameTypeDescription
browsingContextstring

The browsing context ID.

Returns:
  • A promise that resolves to an array of RealmInfo objects.
Type: 
Promise.<Array.<RealmInfo>>

(async) getRealmsInBrowsingContextByType(browsingContext, type) → {Promise.<Array.<RealmInfo>>}

Retrieves the realms in a browsing context based on the specified type.

Parameters:
NameTypeDescription
browsingContextstring

The browsing context ID.

typestring

The type of realms to retrieve.

Returns:
  • A promise that resolves to an array of RealmInfo objects.
Type: 
Promise.<Array.<RealmInfo>>

(async) onMessage(callback) → {Promise.<void>}

Subscribes to the 'script.message' event and handles the callback function when a message is received.

Parameters:
NameTypeDescription
callbackfunction

The callback function to be executed when a message is received.

Returns:
  • A promise that resolves when the subscription is successful.
Type: 
Promise.<void>

(async) onRealmCreated(callback) → {Promise.<void>}

Subscribes to the 'script.realmCreated' event and handles it with the provided callback.

Parameters:
NameTypeDescription
callbackfunction

The callback function to handle the 'script.realmCreated' event.

Returns:
  • A promise that resolves when the subscription is successful.
Type: 
Promise.<void>

(async) onRealmDestroyed(callback) → {Promise.<void>}

Subscribes to the 'script.realmDestroyed' event and handles it with the provided callback function.

Parameters:
NameTypeDescription
callbackfunction

The callback function to be executed when the 'script.realmDestroyed' event occurs.

Returns:
  • A promise that resolves when the subscription is successful.
Type: 
Promise.<void>

(async) removePreloadScript(script) → {Promise.<any>}

Removes a preload script.

Parameters:
NameTypeDescription
scriptstring

The ID for the script to be removed.

Throws:
  • If an error occurs during the removal process.
Type
WebDriverError
Returns:
  • A promise that resolves with the result of the removal.
Type: 
Promise.<any>