mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Implement function as a part of a page.waitFor shortcut
This patch adds a function as a possible argument to page.waitFor shortcut. Fixes #91.
This commit is contained in:
@@ -270,16 +270,18 @@ class Frame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(string|number)} selectorOrTimeout
|
||||
* @param {(string|number|function())} selectorOrTimeout
|
||||
* @param {!Object=} options
|
||||
* @return {!Promise}
|
||||
*/
|
||||
waitFor(selectorOrTimeout, options = {}) {
|
||||
if (helper.isString(selectorOrTimeout))
|
||||
return this.waitForSelector(selectorOrTimeout, options);
|
||||
if (helper.isNumber(selectorOrTimeout))
|
||||
return new Promise(fulfill => setTimeout(fulfill, selectorOrTimeout));
|
||||
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrTimeout)));
|
||||
waitFor(selectorOrFunctionOrTimeout, options = {}) {
|
||||
if (helper.isString(selectorOrFunctionOrTimeout))
|
||||
return this.waitForSelector(selectorOrFunctionOrTimeout, options);
|
||||
if (helper.isNumber(selectorOrFunctionOrTimeout))
|
||||
return new Promise(fulfill => setTimeout(fulfill, selectorOrFunctionOrTimeout));
|
||||
if (typeof selectorOrFunctionOrTimeout === 'function')
|
||||
return this.waitForFunction(selectorOrFunctionOrTimeout, options);
|
||||
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrFunctionOrTimeout)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -554,12 +554,12 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} selectorOrTimeout
|
||||
* @param {(string|number|function())} selectorOrTimeout
|
||||
* @param {!Object=} options
|
||||
* @return {!Promise<undefined>}
|
||||
* @return {!Promise}
|
||||
*/
|
||||
waitFor(selectorOrTimeout, options) {
|
||||
return this.mainFrame().waitFor(selectorOrTimeout, options);
|
||||
waitFor(selectorOrFunctionOrTimeout, options = {}) {
|
||||
return this.mainFrame().waitFor(selectorOrFunctionOrTimeout, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user