Interface IJSHandle
- Namespace
- PuppeteerSharp
- Assembly
- PuppeteerSharp.dll
IJSHandle represents an in-page JavaScript object. JSHandles can be created with the EvaluateExpressionHandleAsync(string) and EvaluateFunctionHandleAsync(string, params object[]) methods.
public interface IJSHandle : IAsyncDisposable
- Extension Methods
Properties
Disposed
Gets a value indicating whether this IJSHandle is disposed.
bool Disposed { get; }
Property Value
- bool
true
if disposed; otherwise,false
.
RemoteObject
Gets the remote object.
RemoteObject RemoteObject { get; }
Property Value
- RemoteObject
The remote object.
Methods
EvaluateFunctionAsync(string, params object[])
Executes a function in browser context.
Task<JsonElement?> EvaluateFunctionAsync(string script, params object[] args)
Parameters
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 browser context.
Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)
Parameters
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.
Task<IJSHandle> EvaluateFunctionHandleAsync(string pageFunction, params object[] args)
Parameters
Returns
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.
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.
Task<IJSHandle> GetPropertyAsync(string propertyName)
Parameters
propertyName
stringproperty to get.
Returns
JsonValueAsync()
Returns a JSON representation of the object.
Task<object> JsonValueAsync()
Returns
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.
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.