New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Page): introduce Page.queryObjects #1005
Conversation
This patch introduces Page.queryObjects and ExecutionContext.queryObjects methods to query JavaScript heap for objects with a certain prototype. Fixes puppeteer#304.
test/test.js
Outdated
await page.evaluate(() => window.map = new Map()); | ||
const prototypeHandle = await page.evaluateHandle(() => Map.prototype); | ||
const objectsHandle = await page.queryObjects(prototypeHandle); | ||
const count = await page.evaluate(objects => objects.length, objectsHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make me feel safer, can we actually check that the object here is the map and is usable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This is really exciting. It feels a bit clumsy to use, but maybe that is ok. I was hoping for something like |
Disposing an array of JSHandles is not very nice and talkative from protocol's point of view: await Promise.all(handles.map(handle => handle.dispose())); Most of the time you'll be satisfied with inspecting the objects with const objectPrototype = await page.evaluateHandle(() => Object.prototype);
const objectsHandle = await page.queryObjects(objectPrototype);
const count = await page.evaluate(objects => objects.length, objectsHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This patch introduces `Page.queryObjects` and `ExecutionContext.queryObjects` methods to query JavaScript heap for objects with a certain prototype. Fixes puppeteer#304.
This patch introduces
Page.queryObjects
andExecutionContext.queryObjects
methods to query JavaScript heapfor objects with a certain prototype.
Fixes #304.