Skip to main content
Module

x/puppeteer_plus/mod.ts>JSHandle

Deno port of puppeteer base on latest TypeScript source.
Go to Latest
class JSHandle
Re-export
import { JSHandle } from "https://deno.land/x/puppeteer_plus@0.14.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(
context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject,
)

Type Parameters

optional
T = unknown

Properties

readonly
_client: CDPSession
readonly
_context: ExecutionContext
readonly
_disposed: boolean
readonly
_remoteObject: Protocol.Runtime.RemoteObject
optional
[__JSHandleSymbol]: T

Used for nominally typing JSHandle.

Methods

asElement(): ElementHandle<Node> | null
dispose(): Promise<void>

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

evaluate<Params extends unknown[], Func extends EvaluateFunc<[this, ...Params]> = EvaluateFunc<[this, ...Params]>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>

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<Params extends unknown[], Func extends EvaluateFunc<[this, ...Params]> = EvaluateFunc<[this, ...Params]>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>

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

executionContext(): ExecutionContext

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<K extends keyof T>(propertyName: HandleOr<K>): Promise<HandleFor<T[K]>>

Fetches a single property from the referenced object.

getProperty(propertyName: string): Promise<JSHandle<unknown>>
jsonValue<T = unknown>(): Promise<T>
remoteObject(): Protocol.Runtime.RemoteObject

Provides access to Protocol.Runtime.RemoteObject backing this JSHandle.

toString(): string

Returns a string representation of the JSHandle.