Implement page.waitForFunction method

The page.waitForFunction method allows to wait for a general predicate.
The predicate will be continiously polled for in page, until
it either returns true or the timeout happens.

The polling parameter could be one of the following:
- 'raf' - to poll on every animation frame
- 'mutation' - to poll on every dom mutation
- <number> - to poll every X milliseconds

References #91
This commit is contained in:
Andrey Lushnikov
2017-07-27 15:17:43 -07:00
parent 47a0366b16
commit ff5ed1c738
5 changed files with 197 additions and 31 deletions

View File

@@ -571,6 +571,16 @@ class Page extends EventEmitter {
return this.mainFrame().waitForSelector(selector, options);
}
/**
* @param {function()} pageFunction
* @param {!Object=} options
* @param {!Array<*>} args
* @return {!Promise}
*/
waitForFunction(pageFunction, options = {}, ...args) {
return this.mainFrame().waitForFunction(pageFunction, options, ...args);
}
/**
* @param {string} selector
* @param {!Array<string>} filePaths
@@ -637,10 +647,10 @@ function convertPrintParameterToInches(parameter) {
if (typeof parameter === 'undefined')
return undefined;
let pixels;
if (typeof parameter === 'number') {
if (helper.isNumber(parameter)) {
// Treat numbers as pixel values to be aligned with phantom's paperSize.
pixels = /** @type {number} */ (parameter);
} else if (typeof parameter === 'string') {
} else if (helper.isString(parameter)) {
let text = parameter;
let unit = text.substring(text.length - 2).toLowerCase();
let valueText = '';