Skip to main content
JSHandle represents an in-page JavaScript object. JSHandles can be created with the page.evaluateHandle() method.
JSHandle prevents the referenced JavaScript object from being garbage collected unless the handle is disposed. JSHandles are automatically disposed when their origin frame gets navigated or the parent context gets destroyed. JSHandle instances can be used as arguments for page.evaluate().

Methods

evaluate

Evaluates a function in the browser context with this handle as the first argument.
function
required
Function to be evaluated in the page context
any
Optional argument to pass to the function
Returns: Promise<R> - Promise that resolves to the return value of the function

evaluateHandle

Evaluates a function in the browser context with this handle as the first argument, returns a JSHandle.
function
required
Function to be evaluated
any
Optional argument to pass to the function
Returns: Promise<JSHandle> - Promise that resolves to a JSHandle

getProperty

Fetches a single property from the referenced object.
string
required
Name of the property to get
Returns: Promise<JSHandle> - Promise that resolves to a JSHandle of the property value

getProperties

Returns a map with property names as keys and JSHandle instances for property values. Returns: Promise<Map<string, JSHandle>> - Map of property names to JSHandles

jsonValue

Returns a JSON representation of the object. If the object has a toJSON function, it will not be called. Returns: Promise<T> - JSON representation of the object
The method will throw an error if the referenced object is not stringifiable. It will also throw if the object has circular references.

asElement

Returns either null or the object handle itself if the object is an instance of Node. Returns: ElementHandle | null - ElementHandle pointing to the referenced object or null

dispose

Stops referencing the element handle and disposes it. Returns: Promise<void>

Examples

Working with object properties

Passing JSHandles to evaluate

Working with arrays