WebWorker
Namespace: PuppeteerSharp
public abstract class WebWorkerThe Worker class represents a WebWorker (<a href=“https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API">https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API</a>). The events WorkerCreated and WorkerDestroyed are emitted on the page object to signal the worker lifecycle.
Inheritance: object
Derived: CdpWebWorker
Example
page.WorkerCreated += (sender, e) => Console.WriteLine('Worker created: ' + e.Worker.Url);page.WorkerDestroyed += (sender, e) => Console.WriteLine('Worker destroyed: ' + e.Worker.Url);for (var worker of page.Workers){ Console.WriteLine(' ' + worker.Url);}Properties
Section titled “Properties”Client
Section titled “Client”public abstract ICDPSession Client { get; }The CDP session client the WebWorker belongs to.
Value: ICDPSession
public string Url { get; }Gets the Worker URL.
Value: string — Worker URL.
Events
Section titled “Events”Console
Section titled “Console”public event EventHandler<ConsoleEventArgs> ConsoleFired when the worker calls a console API method.
Value: EventHandler<ConsoleEventArgs>
Methods
Section titled “Methods”CloseAsync()
Section titled “CloseAsync()”public abstract Task CloseAsync()Closes the worker.
Returns: Task — A Task that completes when the worker is closed.
EvaluateExpressionAsync<T>(string)
Section titled “EvaluateExpressionAsync<T>(string)”public virtual Task<T> EvaluateExpressionAsync<T>(string script)Executes a script in browser context.
Type parameters
| Name | Description |
|---|---|
T |
The type to deserialize the result to. |
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | Script to be evaluated in browser context. |
Returns: Task<T> — Task which resolves to script return value.
If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.
EvaluateExpressionHandleAsync(string)
Section titled “EvaluateExpressionHandleAsync(string)”public virtual Task<IJSHandle> EvaluateExpressionHandleAsync(string script)Executes a script in browser context.
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | Script to be evaluated in browser context. |
Returns: Task<IJSHandle> — Task which resolves to script return value.
If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.
EvaluateFunctionAsync(string, params object[])
Section titled “EvaluateFunctionAsync(string, params object[])”public virtual Task EvaluateFunctionAsync(string script, params object[] args)Executes a function in browser context.
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | Script to be evaluated in browser context. |
args |
object[] | Arguments to pass to script. |
Returns: Task — Task which resolves to script return value.
If the script, returns a Promise, then the method would wait for the promise to resolve and return its value. IJSHandle instances can be passed as arguments.
EvaluateFunctionAsync<T>(string, params object[])
Section titled “EvaluateFunctionAsync<T>(string, params object[])”public virtual Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)Executes a function in the context.
Type parameters
| Name | Description |
|---|---|
T |
The type to deserialize the result to. |
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | Script to be evaluated in browser context. |
args |
object[] | Arguments to pass to script. |
Returns: Task<T> — Task which resolves to script return value.
If the script, returns a Promise, then the method would wait for the promise to resolve and return its value. IJSHandle instances can be passed as arguments.
WaitForFunctionAsync(string, WaitForFunctionOptions, params object[])
Section titled “WaitForFunctionAsync(string, WaitForFunctionOptions, params object[])”public virtual Task<IJSHandle> WaitForFunctionAsync(string script, WaitForFunctionOptions options = null, params object[] args)Waits for the provided function, <code class=“paramref”>script</code>, to return a truthy value when evaluated in the worker’s context.
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | Function to be evaluated in the worker context until it returns a truthy value. |
options |
WaitForFunctionOptions | Options for configuring waiting behavior. |
args |
object[] | Arguments to pass to <code class=“paramref”>script</code>. |
Returns: Task<IJSHandle> — A Task that resolves to a IJSHandle of the truthy value returned by the function.
Made with love by Dario Kondratiuk