Skip to main content
Module

x/puppeteer/mod.ts>ExecutionContext#evaluate

A port of puppeteer running on Deno
Latest
method ExecutionContext.prototype.evaluate
Re-export
import { ExecutionContext } from "https://deno.land/x/puppeteer@16.2.0/mod.ts";

Evaluates the given function.

Examples

Example 1

const executionContext = await page.mainFrame().executionContext();
const result = await executionContext.evaluate(() => Promise.resolve(8 * 7))* ;
console.log(result); // prints "56"

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

console.log(await executionContext.evaluate('1 + 2')); // prints "3"

Handles can also be passed as args. They resolve to their referenced object:

const oneHandle = await executionContext.evaluateHandle(() => 1);
const twoHandle = await executionContext.evaluateHandle(() => 2);
const result = await executionContext.evaluate(
  (a, b) => a + b,
  oneHandle,
  twoHandle
);
await oneHandle.dispose();
await twoHandle.dispose();
console.log(result); // prints '3'.

Type Parameters

Params extends unknown[]
optional
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>

Parameters

pageFunction: Func | string
  • The function to evaluate.
...args: Params
  • Additional arguments to pass into the function.

Returns

Promise<Awaited<ReturnType<Func>>>

The result of evaluating the function. If the result is an object, a vanilla object containing the serializable properties of the result is returned.