Table of Contents

Class JSHandle

Namespace
PuppeteerSharp
Assembly
PuppeteerSharp.dll

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.

public abstract class JSHandle : IJSHandle, IAsyncDisposable
Inheritance
JSHandle
Implements
Derived
Extension Methods

Properties

Disposed

Gets a value indicating whether this IJSHandle is disposed.

public bool Disposed { get; protected set; }

Property Value

bool

true if disposed; otherwise, false.

RemoteObject

Gets the remote object.

public RemoteObject RemoteObject { get; }

Property Value

RemoteObject

The remote object.

Methods

DisposeAsync()

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

public abstract ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

EvaluateFunctionAsync(string, params object[])

Executes a function in browser context.

public Task<JToken> 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<JToken>

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

EvaluateFunctionHandleAsync(string, params object[])

Executes a script in browser context.

public Task<IJSHandle> EvaluateFunctionHandleAsync(string pageFunction, params object[] args)

Parameters

pageFunction string

Script to be evaluated in browser context.

args object[]

Function arguments.

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

GetPropertiesAsync()

Returns a Dictionary<TKey, TValue> with property names as keys and IJSHandle instances for the property values.

public virtual Task<Dictionary<string, IJSHandle>> GetPropertiesAsync()

Returns

Task<Dictionary<string, IJSHandle>>

Task which resolves to a Dictionary<TKey, TValue>.

Examples

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

GetPropertyAsync(string)

Fetches a single property from the referenced object.

public virtual Task<IJSHandle> GetPropertyAsync(string propertyName)

Parameters

propertyName string

property to get.

Returns

Task<IJSHandle>

Task of IJSHandle.

JsonValueAsync()

Returns a JSON representation of the object.

public Task<object> JsonValueAsync()

Returns

Task<object>

Task.

Remarks

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.

JsonValueAsync<T>()

Returns a JSON representation of the object.

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

Returns

Task<T>

Task.

Type Parameters

T

A strongly typed object to parse to.

Remarks

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.