Page.queryObjects() 方法
這個方法會迭代 JavaScript 堆積,並尋找所有具有給定原型物件。
簽名
class Page {
abstract queryObjects<Prototype>(
prototypeHandle: JSHandle<Prototype>,
): Promise<JSHandle<Prototype[]>>;
}
參數
參數 | 類型 | 描述 |
---|---|---|
prototypeHandle | JSHandle<原型> | 物件原型的控制代碼。 |
回傳
Promise<JSHandle<原型[]>>
Promise,它解析為此原型的物件陣列的控制代碼。
範例
// 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();