Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/pptr/mod.ts>JSHandle

Headless Chrome Deno API
Latest
class JSHandle
Re-export
import { JSHandle } from "https://deno.land/x/pptr@1.2.0/mod.ts";

Represents an in-page JavaScript object. JSHandles can be created with the Page.evaluateHandle | page.evaluateHandle method.

Examples

Example 1

const windowHandle = await page.evaluateHandle(() => window);

JSHandle prevents the referenced JavaScript object from being garbage-collected unless the handle is JSHandle.dispose | 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

new
JSHandle()

Properties

_client: CDPSession
_disposed: boolean

Methods

Returns either null or the object handle itself, if the object handle is an instance of ElementHandle.

dispose(): Promise<void>

Stops referencing the element handle, and resolves when the object handle is successfully disposed of.

evaluate<T extends EvaluateFn>(pageFunction: T | string, ...args: SerializableOrJSHandle[]): Promise<UnwrapPromiseLike<EvaluateFnReturnType<T>>>

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<HandleType extends JSHandle = JSHandle>(pageFunction: EvaluateHandleFn, ...args: SerializableOrJSHandle[]): Promise<HandleType>

This method passes this handle as the first argument to pageFunction.

Returns the execution context the handle belongs to.

getProperties(): Promise<Map<string, JSHandle>>

The method returns a map with property names as keys and JSHandle instances for the property values.

getProperty(propertyName: string): Promise<JSHandle | null>

Fetches a single property from the referenced object.

jsonValue(): Promise<Record<string, unknown>>

Returns a JSON representation of the object.

toString(): string

Returns a string representation of the JSHandle.