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
moduleScriptModuleThe ScriptModule to extend.
functionDeclarationstringThe declaration of the JavaScript function the preload script runs.
argumentsIEnumerable<ChannelValue>The channel arguments passed to the function, or null for none.
sandboxstringThe name of the sandbox in which to run the function, or null to run it in the page.
timeoutOverrideTimeSpan?The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.
cancellationTokenCancellationTokenA 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
moduleScriptModuleThe ScriptModule to extend.
browsingContextIdstringThe ID of the browsing context.
functionDeclarationstringThe declaration of the function, such as "() => document.title".
argumentsIEnumerable<LocalValue>The arguments passed to the function, or null for none.
sandboxstringThe name of the sandbox in which to run the function, or null to run it in the page.
timeoutOverrideTimeSpan?The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.
cancellationTokenCancellationTokenA 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
moduleScriptModuleThe ScriptModule to extend.
browsingContextIdstringThe ID of the browsing context.
functionDeclarationstringThe declaration of the function, such as "() => document.title".
argumentsIEnumerable<LocalValue>The arguments passed to the function, or null for none.
sandboxstringThe name of the sandbox in which to run the function, or null to run it in the page.
timeoutOverrideTimeSpan?The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.
cancellationTokenCancellationTokenA token that cancels waiting for the command's response.
Returns
- Task<T>
The function's result.
Type Parameters
TThe 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
moduleScriptModuleThe ScriptModule to extend.
preloadScriptIdstringThe ID of the preload script.
timeoutOverrideTimeSpan?The timeout override to use for the command. If omitted, the value of DefaultCommandTimeout is used.
cancellationTokenCancellationTokenA token that cancels waiting for the command's response.
Returns
- Task
A task representing the asynchronous operation.