Skip to main content
Version: 24.38.0

Page.queryObjects() 方法

🌐 Page.queryObjects() method

此方法迭代 JavaScript 堆并查找具有给定原型的所有对象。

🌐 This method iterates the JavaScript heap and finds all objects with the given prototype.

语法

🌐 Signature

class Page {
abstract queryObjects<Prototype>(
prototypeHandle: JSHandle<Prototype>,
): Promise<JSHandle<Prototype[]>>;
}

参数

🌐 Parameters

范围

🌐 Parameter

类型

🌐 Type

描述

🌐 Description

prototypeHandle

JSHandle<Prototype>

对象原型的句柄。

🌐 a handle to the object prototype.

返回:

Promise<JSHandle<Prototype[]>>

Promise 解析为具有此原型的对象数组的句柄。

🌐 Promise which resolves to a handle to an array of objects with this prototype.

示例

🌐 Example

// Create a Map object
await page.evaluate(() => (window.map = new Map()));
// Get a handle to the Map object prototype
const mapPrototype = await page.evaluateHandle(() => Map.prototype);
// Query all map instances into an array
const mapInstances = await page.queryObjects(mapPrototype);
// Count amount of map objects in heap
const count = await page.evaluate(maps => maps.length, mapInstances);
await mapInstances.dispose();
await mapPrototype.dispose();