From 8b2059f82a801daaa9d27f48d1925bd1335020c6 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 10 Jun 2024 16:09:52 +0200 Subject: [PATCH] fix(performance): use Runtime.getProperties for improved performance (#12561) --- packages/puppeteer-core/src/cdp/JSHandle.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/puppeteer-core/src/cdp/JSHandle.ts b/packages/puppeteer-core/src/cdp/JSHandle.ts index bba5f96b5db..9238c6f3982 100644 --- a/packages/puppeteer-core/src/cdp/JSHandle.ts +++ b/packages/puppeteer-core/src/cdp/JSHandle.ts @@ -87,6 +87,23 @@ export class CdpJSHandle extends JSHandle { override remoteObject(): Protocol.Runtime.RemoteObject { return this.#remoteObject; } + + override async getProperties(): Promise>> { + // We use Runtime.getProperties rather than iterative version for + // improved performance as it allows getting everything at once. + const response = await this.client.send('Runtime.getProperties', { + objectId: this.#remoteObject.objectId!, + ownProperties: true, + }); + const result = new Map(); + for (const property of response.result) { + if (!property.enumerable || !property.value) { + continue; + } + result.set(property.name, this.#world.createCdpHandle(property.value)); + } + return result; + } } /**