puppeteer/docs/api/puppeteer.executioncontext.md

3.3 KiB

sidebar_label
ExecutionContext

ExecutionContext class

Represents a context for JavaScript execution.

Signature:

export declare class ExecutionContext

Remarks

Besides pages, execution contexts can be found in workers.

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

Example

A Page can have several execution contexts:

  • Each Frame of a page has a "default" execution context that is always created after frame is attached to DOM. This context is returned by the Frame.executionContext() method. - Each Chrome extensions creates additional execution contexts to isolate their code.

Methods

Method Modifiers Description
evaluate(pageFunction, args) Evaluates the given function.
evaluateHandle(pageFunction, args)

Evaluates the given function.

Unlike 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.

frame()
queryObjects(prototypeHandle) Iterates through the JavaScript heap and finds all the objects with the given prototype.