Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Go to Latest
method ExecutionContext.prototype.evaluateHandle
import { ExecutionContext } from "https://deno.land/x/puppeteer@14.1.1/vendor/puppeteer-core/puppeteer/common/ExecutionContext.d.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.jsonValue()); // 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).