Skip to main content
Version: 10.1.0

puppeteer.page.queryobjects

Home > puppeteer > Page > queryObjects

Page.queryObjects() method#

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

Signature:
queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;

Parameters#

ParameterTypeDescription
prototypeHandleJSHandlea handle to the object prototype.
Returns:

Promise<JSHandle>

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

Remarks#

Shortcut 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();