Skip to main content
Deno 2 is finally here 🎉️
Learn more
Latest
method ExecutionContext.prototype.evaluateHandle
import { ExecutionContext } from "https://deno.land/x/pptr@1.2.0/src/ExecutionContext.ts";

Examples

Example 1

const context = await page.mainFrame().executionContext();
const aHandle = await context.evaluateHandle(() => Promise.resolve(self));
aHandle; // Handle for the global object.

A string can also be passed in instead of a function.

// Handle for the '3' * object.
const aHandle = await context.evaluateHandle('1 + 2');

JSHandle instances can be passed as arguments to the executionContext.* evaluateHandle:

const aHandle = await context.evaluateHandle(() => document.body);
const resultHandle = await context.evaluateHandle(body => body.innerHTML, * aHandle);
console.log(await resultHandle.tsonValue()); // prints body's innerHTML
await aHandle.dispose();
await resultHandle.dispose();

Type Parameters

optional
HandleType extends JSHandle | ElementHandle = JSHandle

Parameters

pageFunction: EvaluateHandleFn

a function to be evaluated in the executionContext

argument to pass to the page function

Returns

Promise<HandleType>

A promise that resolves to the return value of the given function as an in-page object (a JSHandle).