Skip to content

ExecutionContext

Namespace: PuppeteerSharp

public sealed class ExecutionContext : IExecutionContext, IDisposable, IAsyncDisposable, IPuppeteerUtilWrapper

The class represents a context for JavaScript execution. Examples of JavaScript contexts are: Each Frame has a separate IExecutionContext All kind of web workers have their own contexts.

Inheritance: object

Implements: IExecutionContext, IDisposable, IAsyncDisposable, IPuppeteerUtilWrapper

View source

public static string EvaluationScriptUrl { get; set; }

Gets or sets the URL used to identify evaluation scripts. This can be changed to avoid bot detection by services that look for known automation markers.

Value: string

View source

public void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View source

public ValueTask DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Returns: ValueTask — A task that represents the asynchronous dispose operation.

View source

public Task<JsonElement?> EvaluateExpressionAsync(string script)

Executes a script in browser context.

Parameters

Name Type Description
script string Script to be evaluated in browser context.

Returns: Task<JsonElement?> — 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.

View source

public 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.

View source

public 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.

View source

EvaluateFunctionAsync(string, params object[])

Section titled “EvaluateFunctionAsync(string, params object[])”
public Task<JsonElement?> 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<JsonElement?> — 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.

View source

EvaluateFunctionAsync<T>(string, params object[])

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

Executes a function 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.
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.

View source

EvaluateFunctionHandleAsync(string, params object[])

Section titled “EvaluateFunctionHandleAsync(string, params object[])”
public Task<IJSHandle> EvaluateFunctionHandleAsync(string script, params object[] args)

Executes a script in browser context.

Parameters

Name Type Description
script string
args object[] Function arguments.

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. IJSHandle instances can be passed as arguments.

View source

public Task<IJSHandle> GetPuppeteerUtilAsync()

Gets the PuppeteerUtil handle.

Returns: Task<IJSHandle> — The PuppeteerUtil handle.

View source

Made with love by Dario Kondratiuk