import { ExecutionContext } from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
Evaluates the given function.
Unlike ExecutionContext.evaluate | evaluate, this method returns a handle to the result of the function.
This method may be better suited if the object cannot be serialized (e.g.
Map
) and requires further manipulation.
Examples
Example 1
Example 1
const context = await page.mainFrame().executionContext();
const handle: JSHandle<typeof globalThis> = await context.evaluateHandle(
() => Promise.resolve(self)
);
A string can also be passed in instead of a function.
A string can also be passed in instead of a function.
const handle: JSHandle<number> = await context.evaluateHandle('1 + 2');
Handles can also be passed as args
. They resolve to their referenced object:
Handles can also be passed as args
. They resolve to their referenced object:
const bodyHandle: ElementHandle<HTMLBodyany> =
await context.evaluateHandle(() => {
return document.body;
});
const stringHandle: JSHandle<string> = await context.evaluateHandle(
body => body.innerHTML,
body
);
console.log(await stringHandle.jsonValue()); // prints body's innerHTML
// Always dispose your garbage! :)
await bodyHandle.dispose();
await stringHandle.dispose();