Skip to main content
Version: 25.3.0

字段类

🌐 Realm class

语法

🌐 Signature

export declare abstract class Realm

附注

🌐 Remarks

这个类的构造函数被标记为内部。第三方代码不应直接调用构造函数或创建继承 Realm 类的子类。

🌐 The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Realm class.

属性

🌐 Properties

属性

🌐 Property

修饰符

🌐 Modifiers

类型

🌐 Type

描述

🌐 Description

origin

readonly

字符串 | 未定义

🌐 string | undefined

(实验) 返回创建该 Realm 的来源。例如,如果该 realm 是由扩展内容脚本创建的,则此方法将返回扩展的来源(例如,chrome-extension://<extension-id>)。

方法

🌐 Methods

方法

🌐 Method

修饰符

🌐 Modifiers

描述

🌐 Description

evaluate(pageFunction, args)

在字段的上下文中评估一个函数并返回结果值。

🌐 Evaluates a function in the realm's context and returns the resulting value.

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

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

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

evaluateHandle(pageFunction, args)

在该字段的上下文中评估函数,并返回结果的 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 实例可以作为参数传递给该函数。

extension()

(实验性) 返回创建此域的 扩展(如果适用)。当域是由注入页面的扩展内容脚本创建时,通常会填充此信息。

waitForFunction(pageFunction, options, args)

等待函数在字段的上下文中求值时返回一个真值。

🌐 Waits for a function to return a truthy value when evaluated in the realm's context.

参数可以从 Node.js 传递到 pageFunction

🌐 Arguments can be passed from Node.js to pageFunction.