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: JSHandles as argument for waitFor and return the success value #1712
Conversation
7b093dd
to
814126c
Compare
lib/FrameManager.js
Outdated
* @param {string|number} polling | ||
* @param {number} timeout | ||
*/ | ||
constructor(frame, predicateBody, polling, timeout) { | ||
constructor(frame, predicateBody, polling, timeout, ...args) { |
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.
nit: missing jsdoc for args
lib/FrameManager.js
Outdated
else if (typeof polling === 'number') | ||
await pollInterval(polling); | ||
return !timedOut; | ||
return await pollInterval(polling); | ||
|
||
/** | ||
* @return {!Promise} |
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.
@return {!Promise<*>}
lib/FrameManager.js
Outdated
let timedOut = false; | ||
setTimeout(() => timedOut = true, timeout); | ||
if (polling === 'raf') | ||
await pollRaf(); | ||
return await pollRaf(); | ||
else if (polling === 'mutation') |
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.
nit: drop elses
lib/FrameManager.js
Outdated
} catch (e) { | ||
error = e; | ||
} | ||
|
||
if (this._terminated || runCount !== this._runCount) | ||
if (this._terminated || runCount !== this._runCount) { | ||
success && await success.dispose(); |
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.
if (success)
..
lib/FrameManager.js
Outdated
* @param {!Object=} options | ||
* @return {!Promise} | ||
*/ | ||
waitForFunction(pageFunction, options = {}, ...args) { | ||
const timeout = options.timeout || 30000; | ||
const polling = options.polling || 'raf'; | ||
const predicateCode = 'return ' + helper.evaluationString(pageFunction, ...args); | ||
return new WaitTask(this, predicateCode, polling, timeout).promise; | ||
if (helper.isString(pageFunction)) |
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.
let's move this to the waitTask
This patch: - teaches page.waitFor* methods to accept JSHandles - starts returning JSHandles from page.waitFor* calls. BREAKING CHANGE: this patch starts allocating `JSHandle`/`ElementHandle` instances for every call to `page.waitFor*` functions. These handles should be disposed manually to avoid memory consumption. Fixes puppeteer#1703, fixes puppeteer#1654, fixes puppeteer#1724.
#1703
#1654