mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
3.2 KiB
3.2 KiB
JSHandle class
Represents an in-page JavaScript object. JSHandles can be created with the page.evaluateHandle method.
Signature:
export declare class JSHandle
Example
const windowHandle = await page.evaluateHandle(() => window);
JSHandle prevents the referenced JavaScript object from being garbage-collected unless the handle is disposed. JSHandles are auto- disposed when their origin frame gets navigated or the parent context gets destroyed.
JSHandle instances can be used as arguments for Page.$eval(), Page.evaluate(), and Page.evaluateHandle().
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(context, client, remoteObject) | Constructs a new instance of the JSHandle class |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| _client | CDPSession | ||
| _context | ExecutionContext | ||
| _disposed | boolean | ||
| _remoteObject | Protocol.Runtime.RemoteObject |
Methods
| Method | Modifiers | Description |
|---|---|---|
| asElement() | Returns either null or the object handle itself, if the object handle is an instance of ElementHandle. |
|
| dispose() | Stops referencing the element handle, and resolves when the object handle is successfully disposed of. | |
| evaluate(pageFunction, args) | This method passes this handle as the first argument to pageFunction. If pageFunction returns a Promise, then handle.evaluate would wait for the promise to resolve and return its value. |
|
| evaluateHandle(pageFunction, args) | This method passes this handle as the first argument to pageFunction. |
|
| executionContext() | Returns the execution context the handle belongs to. | |
| getProperties() | The method returns a map with property names as keys and JSHandle instances for the property values. | |
| getProperty(propertyName) | Fetches a single property from the referenced object. | |
| jsonValue() | Returns a JSON representation of the object. | |
| toString() | Returns a string representation of the JSHandle. |