diff --git a/docs/api/index.md b/docs/api/index.md
index 88e7d46f..aab590d9 100644
--- a/docs/api/index.md
+++ b/docs/api/index.md
@@ -6,40 +6,40 @@ sidebar_label: API
## Classes
-| Class | Description |
-| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). |
-| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a Chromium instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). |
-| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
-| [BrowserFetcher](./puppeteer.browserfetcher.md) | BrowserFetcher can download and manage different versions of Chromium and Firefox. |
-| [CDPSession](./puppeteer.cdpsession.md) | The CDPSession
instances are used to talk raw Chrome Devtools Protocol. |
-| [Connection](./puppeteer.connection.md) | |
-| [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. |
-| [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page. |
-| [CSSCoverage](./puppeteer.csscoverage.md) | |
-| [CustomError](./puppeteer.customerror.md) | |
-| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the dialog
event. |
-| [ElementHandle](./puppeteer.elementhandle.md) | ElementHandle represents an in-page DOM element. |
-| [EventEmitter](./puppeteer.eventemitter.md) | The EventEmitter class that many Puppeteer classes extend. |
-| [ExecutionContext](./puppeteer.executioncontext.md) |
This class represents a context for JavaScript execution. A \[Page\] might have many execution contexts: - each [frame](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) has "default" execution context that is always created after frame is attached to DOM. This context is returned by the [Frame.executionContext()](./puppeteer.frame.executioncontext.md) method. - [Extension](https://developer.chrome.com/extensions)'s content scripts create additional execution contexts.
Besides pages, execution contexts can be found in [workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
| -| [FileChooser](./puppeteer.filechooser.md) | File choosers let you react to the page requesting for a file. | -| [Frame](./puppeteer.frame.md) | At every point of time, page exposes its current frame tree via the [page.mainFrame](./puppeteer.page.mainframe.md) and [frame.childFrames](./puppeteer.frame.childframes.md) methods. | -| [HTTPRequest](./puppeteer.httprequest.md) | Represents an HTTP request sent by a page. | -| [HTTPResponse](./puppeteer.httpresponse.md) | The HTTPResponse class represents responses which are received by the [Page](./puppeteer.page.md) class. | -| [JSCoverage](./puppeteer.jscoverage.md) | | -| [JSHandle](./puppeteer.jshandle.md) | Represents an in-page JavaScript object. JSHandles can be created with the [page.evaluateHandle](./puppeteer.page.evaluatehandle.md) method. | -| [Keyboard](./puppeteer.keyboard.md) | Keyboard provides an api for managing a virtual keyboard. The high level api is [Keyboard.type()](./puppeteer.keyboard.type.md), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page. | -| [Mouse](./puppeteer.mouse.md) | The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. | -| [Page](./puppeteer.page.md) |Page provides methods to interact with a single tab or [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium.
:::note
One Browser instance might have multiple Page instances.
:::
| -| [ProtocolError](./puppeteer.protocolerror.md) | ProtocolError is emitted whenever there is an error from the protocol. | -| [Puppeteer](./puppeteer.puppeteer.md) |The main Puppeteer class.
IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require puppeteer
. That class extends Puppeteer
, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).
Extends the main [Puppeteer](./puppeteer.puppeteer.md) class with Node specific behaviour for fetching and downloading browsers.
If you're using Puppeteer in a Node environment, this is the class you'll get when you run require('puppeteer')
(or the equivalent ES import
).
CDPSession
instances are used to talk raw Chrome Devtools Protocol. |
+| [Connection](./puppeteer.connection.md) | |
+| [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. |
+| [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page. |
+| [CSSCoverage](./puppeteer.csscoverage.md) | |
+| [CustomError](./puppeteer.customerror.md) | |
+| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the dialog
event. |
+| [ElementHandle](./puppeteer.elementhandle.md) | ElementHandle represents an in-page DOM element. |
+| [EventEmitter](./puppeteer.eventemitter.md) | The EventEmitter class that many Puppeteer classes extend. |
+| [ExecutionContext](./puppeteer.executioncontext.md) | Represents a context for JavaScript execution. |
+| [FileChooser](./puppeteer.filechooser.md) | File choosers let you react to the page requesting for a file. |
+| [Frame](./puppeteer.frame.md) | At every point of time, page exposes its current frame tree via the [page.mainFrame](./puppeteer.page.mainframe.md) and [frame.childFrames](./puppeteer.frame.childframes.md) methods. |
+| [HTTPRequest](./puppeteer.httprequest.md) | Represents an HTTP request sent by a page. |
+| [HTTPResponse](./puppeteer.httpresponse.md) | The HTTPResponse class represents responses which are received by the [Page](./puppeteer.page.md) class. |
+| [JSCoverage](./puppeteer.jscoverage.md) | |
+| [JSHandle](./puppeteer.jshandle.md) | Represents a reference to a JavaScript object. Instances can be created using [Page.evaluateHandle()](./puppeteer.page.evaluatehandle.md).
Handles prevent the referenced JavaScript object from being garbage-collected unless the handle is purposely [disposed](./puppeteer.jshandle.dispose.md). JSHandles are auto-disposed when their associated frame is navigated away or the parent context gets destroyed.
Handles can be used as arguments for any evaluation function such as [Page.$eval()](./puppeteer.page._eval.md), [Page.evaluate()](./puppeteer.page.evaluate.md), and [Page.evaluateHandle()](./puppeteer.page.evaluatehandle.md). They are resolved to their referenced object.
| +| [Keyboard](./puppeteer.keyboard.md) | Keyboard provides an api for managing a virtual keyboard. The high level api is [Keyboard.type()](./puppeteer.keyboard.type.md), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page. | +| [Mouse](./puppeteer.mouse.md) | The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. | +| [Page](./puppeteer.page.md) |Page provides methods to interact with a single tab or [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium.
:::note
One Browser instance might have multiple Page instances.
:::
| +| [ProtocolError](./puppeteer.protocolerror.md) | ProtocolError is emitted whenever there is an error from the protocol. | +| [Puppeteer](./puppeteer.puppeteer.md) |The main Puppeteer class.
IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require puppeteer
. That class extends Puppeteer
, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).
Extends the main [Puppeteer](./puppeteer.puppeteer.md) class with Node specific behaviour for fetching and downloading browsers.
If you're using Puppeteer in a Node environment, this is the class you'll get when you run require('puppeteer')
(or the equivalent ES import
).
executionContext
|
-| args | Params | argument to pass to the page function |
+| Parameter | Type | Description |
+| ------------ | -------------- | ----------------------------------------------- |
+| pageFunction | Func \| string | The function to evaluate. |
+| args | Params | Additional arguments to pass into the function. |
**Returns:**
Promise<Awaited<ReturnType<Func>>>
-A promise that resolves to the return value of the given function.
-
-## Remarks
-
-If the function passed to the `executionContext.evaluate` returns a Promise, then `executionContext.evaluate` would wait for the promise to resolve and return its value. If the function passed to the `executionContext.evaluate` returns a non-serializable value, then `executionContext.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
+The result of evaluating the function. If the result is an object, a vanilla object containing the serializable properties of the result is returned.
## Example 1
@@ -45,7 +43,7 @@ console.log(result); // prints "56"
## Example 2
-A string can also be passed in instead of a function.
+A string can also be passed in instead of a function:
```ts
console.log(await executionContext.evaluate('1 + 2')); // prints "3"
@@ -53,13 +51,15 @@ console.log(await executionContext.evaluate('1 + 2')); // prints "3"
## Example 3
-[JSHandle](./puppeteer.jshandle.md) instances can be passed as arguments to the `executionContext.* evaluate`:
+Handles can also be passed as `args`. They resolve to their referenced object:
```ts
const oneHandle = await executionContext.evaluateHandle(() => 1);
const twoHandle = await executionContext.evaluateHandle(() => 2);
const result = await executionContext.evaluate(
- (a, b) => a + b, oneHandle, * twoHandle
+ (a, b) => a + b,
+ oneHandle,
+ twoHandle
);
await oneHandle.dispose();
await twoHandle.dispose();
diff --git a/docs/api/puppeteer.executioncontext.evaluatehandle.md b/docs/api/puppeteer.executioncontext.evaluatehandle.md
index 103b8d7e..d35dcfa9 100644
--- a/docs/api/puppeteer.executioncontext.evaluatehandle.md
+++ b/docs/api/puppeteer.executioncontext.evaluatehandle.md
@@ -4,6 +4,12 @@ sidebar_label: ExecutionContext.evaluateHandle
# ExecutionContext.evaluateHandle() method
+Evaluates the given function.
+
+Unlike [evaluate](./puppeteer.executioncontext.evaluate.md), 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.
+
**Signature:**
```typescript
@@ -20,27 +26,24 @@ class ExecutionContext {
## Parameters
-| Parameter | Type | Description |
-| ------------ | -------------- | --------------------------------------------------------------- |
-| pageFunction | Func \| string | a function to be evaluated in the executionContext
|
-| args | Params | argument to pass to the page function |
+| Parameter | Type | Description |
+| ------------ | -------------- | ----------------------------------------------- |
+| pageFunction | Func \| string | The function to evaluate. |
+| args | Params | Additional arguments to pass into the function. |
**Returns:**
Promise<[HandleFor](./puppeteer.handlefor.md)<Awaited<ReturnType<Func>>>>
-A promise that resolves to the return value of the given function as an in-page object (a [JSHandle](./puppeteer.jshandle.md)).
-
-## Remarks
-
-The only difference between `executionContext.evaluate` and `executionContext.evaluateHandle` is that `executionContext.evaluateHandle` returns an in-page object (a [JSHandle](./puppeteer.jshandle.md)). If the function passed to the `executionContext.evaluateHandle` returns a Promise, then `executionContext.evaluateHandle` would wait for the promise to resolve and return its value.
+A [handle](./puppeteer.jshandle.md) to the result of evaluating the function. If the result is a `Node`, then this will return an [element handle](./puppeteer.elementhandle.md).
## Example 1
```ts
const context = await page.mainFrame().executionContext();
-const aHandle = await context.evaluateHandle(() => Promise.resolve(self));
-aHandle; // Handle for the global object.
+const handle: JSHandleEvaluates the given function.
Unlike [evaluate](./puppeteer.executioncontext.evaluate.md), 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.
pageFunction
. If pageFunction
returns a Promise, then handle.evaluate
would wait for the promise to resolve and return its value. |
-| [evaluateHandle(pageFunction, args)](./puppeteer.jshandle.evaluatehandle.md) | | This method passes this handle as the first argument to pageFunction
. |
-| [executionContext()](./puppeteer.jshandle.executioncontext.md) | | Returns the execution context the handle belongs to. |
-| [getProperties()](./puppeteer.jshandle.getproperties.md) | | The method returns a map with property names as keys and JSHandle instances for the property values. |
-| [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. |
-| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | |
-| [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | |
-| [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this JSHandle. |
-| [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. |
+| Method | Modifiers | Description |
+| ---------------------------------------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [asElement()](./puppeteer.jshandle.aselement.md) | | |
+| [dispose()](./puppeteer.jshandle.dispose.md) | | Releases the object referenced by the handle for garbage collection. |
+| [evaluate(pageFunction, args)](./puppeteer.jshandle.evaluate.md) | | Evaluates the given function with the current handle as its first argument. |
+| [evaluateHandle(pageFunction, args)](./puppeteer.jshandle.evaluatehandle.md) | | Evaluates the given function with the current handle as its first argument. |
+| [executionContext()](./puppeteer.jshandle.executioncontext.md) | | |
+| [getProperties()](./puppeteer.jshandle.getproperties.md) | | Gets a map of handles representing the properties of the current handle. |
+| [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. |
+| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | |
+| [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | |
+| [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to the \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this handle. |
+| [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. |
diff --git a/docs/api/puppeteer.jshandle.remoteobject.md b/docs/api/puppeteer.jshandle.remoteobject.md
index 868762a1..8f8286bf 100644
--- a/docs/api/puppeteer.jshandle.remoteobject.md
+++ b/docs/api/puppeteer.jshandle.remoteobject.md
@@ -4,7 +4,7 @@ sidebar_label: JSHandle.remoteObject
# JSHandle.remoteObject() method
-Provides access to \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this JSHandle.
+Provides access to the \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this handle.
**Signature:**
diff --git a/src/common/Accessibility.ts b/src/common/Accessibility.ts
index c3459332..e1f13e82 100644
--- a/src/common/Accessibility.ts
+++ b/src/common/Accessibility.ts
@@ -185,7 +185,7 @@ export class Accessibility {
let backendNodeId: number | undefined;
if (root) {
const {node} = await this.#client.send('DOM.describeNode', {
- objectId: root._remoteObject.objectId,
+ objectId: root.remoteObject().objectId,
});
backendNodeId = node.backendNodeId;
}
diff --git a/src/common/AriaQueryHandler.ts b/src/common/AriaQueryHandler.ts
index 935a7ce3..a8239557 100644
--- a/src/common/AriaQueryHandler.ts
+++ b/src/common/AriaQueryHandler.ts
@@ -33,7 +33,7 @@ async function queryAXTree(
role?: string
): Promise