Skip to main content
Version: 24.41.0

Realm class

Signature

export declare abstract class Realm

Remarks

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

(Experimental) Returns the origin that created the Realm. For example, if the realm was created by an extension content script, this will return the origin of the extension (e.g., chrome-extension://<extension-id>).

Methods

Method

Modifiers

Description

evaluate(pageFunction, args)

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

If the function passed to realm.evaluate 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.

evaluateHandle(pageFunction, args)

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.

extension()

(Experimental) Returns the Extension that created this realm, if applicable. This is typically populated when the realm was created by an extension content script injected into a page.

waitForFunction(pageFunction, options, args)

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

Arguments can be passed from Node.js to pageFunction.