Skip to main content
Version: 24.41.0

Realm.evaluateHandle() method

Evaluates a function in the realm's context and returns a JSHandle to the result.

If the function passed to realm.evaluateHandle returns a Promise, the method will wait for the promise to resolve and return its value.

JSHandle instances can be passed as arguments to the function.

Signature

class Realm {
abstract evaluateHandle<
Params extends unknown[],
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,
>(
pageFunction: Func | string,
...args: Params
): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
}

Parameters

Parameter

Type

Description

pageFunction

Func | string

A function to be evaluated in the realm.

args

Params

Arguments to be passed to the pageFunction.

Returns:

Promise<HandleFor<Awaited<ReturnType<Func>>>>

A promise that resolves to a JSHandle containing the result.

Example

const aHandle = await realm.evaluateHandle(() => document.body);
const resultHandle = await realm.evaluateHandle(
body => body.innerHTML,
aHandle,
);