puppeteer.page.queryobjects
Home > puppeteer > Page > queryObjects
#
Page.queryObjects() methodThis method iterates the JavaScript heap and finds all objects with the given prototype.
Signature:queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;
#
ParametersParameter | Type | Description |
---|---|---|
prototypeHandle | JSHandle | a handle to the object prototype. |
Promise<JSHandle>
Promise which resolves to a handle to an array of objects with this prototype.
#
RemarksShortcut for page.mainFrame().executionContext().queryObjects(prototypeHandle).
#
Example// Create a Map objectawait page.evaluate(() => window.map = new Map());// Get a handle to the Map object prototypeconst mapPrototype = await page.evaluateHandle(() => Map.prototype);// Query all map instances into an arrayconst mapInstances = await page.queryObjects(mapPrototype);// Count amount of map objects in heapconst count = await page.evaluate(maps => maps.length, mapInstances);await mapInstances.dispose();await mapPrototype.dispose();