Skip to content

JSHandle

Namespace: PuppeteerSharp

public abstract class JSHandle : IJSHandle, IAsyncDisposable

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

Inheritance: object

Implements: IJSHandle, IAsyncDisposable

Derived: CdpJSHandle, ElementHandle

View source

public bool Disposed { get; protected set; }

Gets a value indicating whether this IJSHandle is disposed.

Value: bool — true if disposed; otherwise, false.

View source

protected bool CheckAndResetMoved()

Checks if the handle has been moved and should skip disposal. If moved, resets the flag and returns true.

Returns: bool — true if disposal should be skipped.

View source

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

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 pageFunction, params object[] args)

Executes a script in browser context.

Parameters

Name Type Description
pageFunction string Script to be evaluated in browser context.
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 virtual Task<Dictionary<string, IJSHandle>> GetPropertiesAsync()

Returns a Dictionary%602 with property names as keys and IJSHandle instances for the property values.

Returns: Task<Dictionary<string, IJSHandle>> — Task which resolves to a Dictionary%602.

Example

var handle = await page.EvaluateExpressionHandle("({window, document})");
var properties = await handle.GetPropertiesAsync();
var windowHandle = properties["window"];
var documentHandle = properties["document"];
await handle.DisposeAsync();

View source

public virtual Task<IJSHandle> GetPropertyAsync(string propertyName)

Fetches a single property from the referenced object.

Parameters

Name Type Description
propertyName string property to get.

Returns: Task<IJSHandle> — Task of IJSHandle.

View source

public Task<object> JsonValueAsync()

Returns a JSON representation of the object.

Returns: Task<object> — Task.

The method will return an empty JSON if the referenced object is not stringifiable. It will throw an error if the object has circular references.

View source

public abstract Task<T> JsonValueAsync<T>()

Returns a JSON representation of the object.

Type parameters

Name Description
T A strongly typed object to parse to.

Returns: Task<T> — Task.

The method will return an empty JSON if the referenced object is not stringifiable. It will throw an error if the object has circular references.

View source

public IJSHandle Move()

Prevents the handle from being disposed on the next DisposeAsync() call. This is useful when you want to keep the handle alive past an await using scope.

Returns: IJSHandle — The handle itself.

View source

Made with love by Dario Kondratiuk