fix(performance): use Runtime.getProperties for improved performance (#12561)

This commit is contained in:
Alex Rudenko 2024-06-10 16:09:52 +02:00 committed by GitHub
parent 0b2999f7b1
commit 8b2059f82a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,6 +87,23 @@ export class CdpJSHandle<T = unknown> extends JSHandle<T> {
override remoteObject(): Protocol.Runtime.RemoteObject {
return this.#remoteObject;
}
override async getProperties(): Promise<Map<string, JSHandle<unknown>>> {
// 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<string, JSHandle>();
for (const property of response.result) {
if (!property.enumerable || !property.value) {
continue;
}
result.set(property.name, this.#world.createCdpHandle(property.value));
}
return result;
}
}
/**