Skip to main content
Version: 25.3.0

Realm.evaluateHandle() 方法

🌐 Realm.evaluateHandle() method

在该字段的上下文中评估函数,并返回结果的 JSHandle

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

如果传递给 realm.evaluateHandle 的函数返回一个 Promise,该方法将等待该 Promise 被解决并返回其值。

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

JSHandle 实例可以作为参数传递给该函数。

语法

🌐 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

要传递给 pageFunction 的参数。

🌐 Arguments to be passed to the pageFunction.

返回:

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

一个解析为包含结果的 JSHandle 的承诺。

🌐 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,
);