Table of Contents

Class WebWorker

Namespace
PuppeteerSharp
Assembly
PuppeteerSharp.dll

The Worker class represents a WebWorker (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). The events WorkerCreated and WorkerDestroyed are emitted on the page object to signal the worker lifecycle.

public abstract class WebWorker
Inheritance
WebWorker
Derived

Examples

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

Client

The CDP session client the WebWorker belongs to.

public abstract CDPSession Client { get; }

Property Value

CDPSession

Url

Gets the Worker URL.

public string Url { get; }

Property Value

string

Worker URL.

Methods

CloseAsync()

Closes the worker.

public abstract Task CloseAsync()

Returns

Task

A Task that completes when the worker is closed.

EvaluateExpressionAsync<T>(string)

Executes a script in browser context.

public Task<T> EvaluateExpressionAsync<T>(string script)

Parameters

script string

Script to be evaluated in browser context.

Returns

Task<T>

Task which resolves to script return value.

Type Parameters

T

The type to deserialize the result to.

Remarks

If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.

See Also

EvaluateExpressionHandleAsync(string)

Executes a script in browser context.

public Task<IJSHandle> EvaluateExpressionHandleAsync(string script)

Parameters

script string

Script to be evaluated in browser context.

Returns

Task<IJSHandle>

Task which resolves to script return value.

Remarks

If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.

See Also

EvaluateFunctionAsync(string, params object[])

Executes a function in browser context.

public Task<JsonElement?> EvaluateFunctionAsync(string script, params object[] args)

Parameters

script string

Script to be evaluated in browser context.

args object[]

Arguments to pass to script.

Returns

Task<JsonElement?>

Task which resolves to script return value.

Remarks

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[])

Executes a function in the context.

public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)

Parameters

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.

Type Parameters

T

The type to deserialize the result to.

Remarks

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.