2022-07-05 13:41:43 +00:00
---
sidebar_label: JSHandle
---
# JSHandle class
2022-08-11 09:45:35 +00:00
Represents a reference to a JavaScript object. Instances can be created using [Page.evaluateHandle() ](./puppeteer.page.evaluatehandle.md ).
Handles prevent the referenced JavaScript object from being garbage-collected unless the handle is purposely [disposed ](./puppeteer.jshandle.dispose.md ). JSHandles are auto-disposed when their associated frame is navigated away or the parent context gets destroyed.
Handles can be used as arguments for any evaluation function such as [Page.$eval() ](./puppeteer.page._eval.md ), [Page.evaluate() ](./puppeteer.page.evaluate.md ), and [Page.evaluateHandle() ](./puppeteer.page.evaluatehandle.md ). They are resolved to their referenced object.
2022-07-05 13:41:43 +00:00
2022-10-24 07:07:05 +00:00
#### Signature:
2022-07-05 13:41:43 +00:00
```typescript
2023-09-15 15:07:05 +00:00
export declare abstract class JSHandle< T = unknown >
2022-07-05 13:41:43 +00:00
```
## Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `JSHandle` class.
## Example
```ts
const windowHandle = await page.evaluateHandle(() => window);
```
2022-07-06 07:05:37 +00:00
## Properties
2024-03-20 15:03:14 +00:00
< table > < thead > < tr > < th >
Property
< / th > < th >
Modifiers
< / th > < th >
Type
< / th > < th >
Description
< / th > < / tr > < / thead >
< tbody > < tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "_" > \_</ span >
2024-03-20 15:03:14 +00:00
< / td > < td >
`optional`
< / td > < td >
T
< / td > < td >
Used for nominally typing [JSHandle ](./puppeteer.jshandle.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "move" > move< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
() => this
< / td > < td >
< / td > < / tr >
< / tbody > < / table >
2022-07-05 13:41:43 +00:00
## Methods
2024-03-20 15:03:14 +00:00
< table > < thead > < tr > < th >
Method
< / th > < th >
Modifiers
< / th > < th >
Description
< / th > < / tr > < / thead >
< tbody > < tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "aselement" > [asElement()](./puppeteer.jshandle.aselement.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Either `null` or the handle itself if the handle is an instance of [ElementHandle ](./puppeteer.elementhandle.md ).
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "dispose" > [dispose()](./puppeteer.jshandle.dispose.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Releases the object referenced by the handle for garbage collection.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "evaluate" > [evaluate(pageFunction, args)](./puppeteer.jshandle.evaluate.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Evaluates the given function with the current handle as its first argument.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "evaluatehandle" > [evaluateHandle(pageFunction, args)](./puppeteer.jshandle.evaluatehandle.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Evaluates the given function with the current handle as its first argument.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "getproperties" > [getProperties()](./puppeteer.jshandle.getproperties.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Gets a map of handles representing the properties of the current handle.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "getproperty" > [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Fetches a single property from the referenced object.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "getproperty" > [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "jsonvalue" > [jsonValue()](./puppeteer.jshandle.jsonvalue.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
A vanilla object representing the serializable portions of the referenced object.
2024-04-29 12:50:39 +00:00
**Remarks:**
If the object has a `toJSON` function, it **will not** be called.
2024-03-20 15:03:14 +00:00
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "remoteobject" > [remoteObject()](./puppeteer.jshandle.remoteobject.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Provides access to the [Protocol.Runtime.RemoteObject ](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject ) backing this handle.
< / td > < / tr >
< tr > < td >
2024-04-11 11:01:13 +00:00
< span id = "tostring" > [toString()](./puppeteer.jshandle.tostring.md)< / span >
2024-03-20 15:03:14 +00:00
< / td > < td >
< / td > < td >
Returns a string representation of the JSHandle.
2024-04-29 12:50:39 +00:00
**Remarks:**
Useful during debugging.
2024-03-20 15:03:14 +00:00
< / td > < / tr >
< / tbody > < / table >