Skip to content
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

Merged
merged 2 commits into from Jan 4, 2018

Conversation

JoelEinbinder
Copy link
Collaborator

* @param {string|number} polling
* @param {number} timeout
*/
constructor(frame, predicateBody, polling, timeout) {
constructor(frame, predicateBody, polling, timeout, ...args) {
Copy link
Contributor

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

else if (typeof polling === 'number')
await pollInterval(polling);
return !timedOut;
return await pollInterval(polling);

/**
* @return {!Promise}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return {!Promise<*>}

let timedOut = false;
setTimeout(() => timedOut = true, timeout);
if (polling === 'raf')
await pollRaf();
return await pollRaf();
else if (polling === 'mutation')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: drop elses

} catch (e) {
error = e;
}

if (this._terminated || runCount !== this._runCount)
if (this._terminated || runCount !== this._runCount) {
success && await success.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (success)
..

* @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))
Copy link
Contributor

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

@aslushnikov aslushnikov merged commit 05b1aca into puppeteer:master Jan 4, 2018
igorshapiro pushed a commit to WiserSolutions/puppeteer that referenced this pull request Jan 16, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants