Table of Contents

Class ScriptModuleExtensions

Namespace
WebDriverBiDi.Script
Assembly
WebDriverBiDi.Extensions.dll

Provides extension methods for the Script module.

public static class ScriptModuleExtensions
Inheritance
ScriptModuleExtensions
Inherited Members

Methods

AddPreloadScriptAsync(ScriptModule, string, IEnumerable<ChannelValue>?, string?, TimeSpan?, CancellationToken)

Adds a preload script, which runs in each document before any of the document's own scripts.

public static Task<string> AddPreloadScriptAsync(this ScriptModule module, string functionDeclaration, IEnumerable<ChannelValue>? arguments = null, string? sandbox = null, TimeSpan? timeoutOverride = null, CancellationToken cancellationToken = default)

Parameters

module ScriptModule

The ScriptModule to extend.

functionDeclaration string

The declaration of the JavaScript function the preload script runs.

arguments IEnumerable<ChannelValue>

The channel arguments passed to the function, or null for none.

sandbox string

The name of the sandbox in which to run the function, or null to run it in the page.

timeoutOverride TimeSpan?

The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.

cancellationToken CancellationToken

A token that cancels waiting for the command's response.

Returns

Task<string>

The ID of the preload script, for RemovePreloadScriptAsync(ScriptModule, string, TimeSpan?, CancellationToken).

CallFunctionAsync(ScriptModule, string, string, IEnumerable<LocalValue>?, string?, TimeSpan?, CancellationToken)

Calls a JavaScript function in a browsing context, awaiting a returned promise, and returns its result.

public static Task<RemoteValue> CallFunctionAsync(this ScriptModule module, string browsingContextId, string functionDeclaration, IEnumerable<LocalValue>? arguments = null, string? sandbox = null, TimeSpan? timeoutOverride = null, CancellationToken cancellationToken = default)

Parameters

module ScriptModule

The ScriptModule to extend.

browsingContextId string

The ID of the browsing context.

functionDeclaration string

The declaration of the function, such as "() => document.title".

arguments IEnumerable<LocalValue>

The arguments passed to the function, or null for none.

sandbox string

The name of the sandbox in which to run the function, or null to run it in the page.

timeoutOverride TimeSpan?

The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.

cancellationToken CancellationToken

A token that cancels waiting for the command's response.

Returns

Task<RemoteValue>

The function's result.

Exceptions

ScriptException

Thrown when the function throws.

CallFunctionAsync<T>(ScriptModule, string, string, IEnumerable<LocalValue>?, string?, TimeSpan?, CancellationToken)

Calls a JavaScript function in a browsing context, awaiting a returned promise, and returns its result as a specific kind of value.

public static Task<T> CallFunctionAsync<T>(this ScriptModule module, string browsingContextId, string functionDeclaration, IEnumerable<LocalValue>? arguments = null, string? sandbox = null, TimeSpan? timeoutOverride = null, CancellationToken cancellationToken = default) where T : RemoteValue

Parameters

module ScriptModule

The ScriptModule to extend.

browsingContextId string

The ID of the browsing context.

functionDeclaration string

The declaration of the function, such as "() => document.title".

arguments IEnumerable<LocalValue>

The arguments passed to the function, or null for none.

sandbox string

The name of the sandbox in which to run the function, or null to run it in the page.

timeoutOverride TimeSpan?

The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.

cancellationToken CancellationToken

A token that cancels waiting for the command's response.

Returns

Task<T>

The function's result.

Type Parameters

T

The kind of value the function returns, such as StringRemoteValue.

Exceptions

ScriptException

Thrown when the function throws.

WebDriverBiDiException

Thrown when the result is not a T.

RemovePreloadScriptAsync(ScriptModule, string, TimeSpan?, CancellationToken)

Removes a preload script.

public static Task RemovePreloadScriptAsync(this ScriptModule module, string preloadScriptId, TimeSpan? timeoutOverride = null, CancellationToken cancellationToken = default)

Parameters

module ScriptModule

The ScriptModule to extend.

preloadScriptId string

The ID of the preload script.

timeoutOverride TimeSpan?

The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.

cancellationToken CancellationToken

A token that cancels waiting for the command's response.

Returns

Task

A task representing the asynchronous operation.