mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Defer evaluation onInitalized
This commit is contained in:
parent
e8af69e5bb
commit
2b0d0e6551
@ -52,6 +52,9 @@ class WebPage {
|
||||
this.onLoadFinished = null;
|
||||
this.onResourceError = null;
|
||||
this.onResourceReceived = null;
|
||||
this.onInitialized = null;
|
||||
this._deferEvaluate = false;
|
||||
|
||||
this.libraryPath = path.dirname(scriptPath);
|
||||
|
||||
this._onConfirm = undefined;
|
||||
@ -192,6 +195,10 @@ class WebPage {
|
||||
*/
|
||||
open(url, callback) {
|
||||
console.assert(arguments.length <= 2, 'WebPage.open does not support METHOD and DATA arguments');
|
||||
this._deferEvaluate = true;
|
||||
if (typeof this.onInitialized === 'function')
|
||||
this.onInitialized();
|
||||
this._deferEvaluate = false;
|
||||
this._page.navigate(url).then(result => {
|
||||
var status = result ? 'success' : 'fail';
|
||||
if (!result) {
|
||||
@ -219,6 +226,8 @@ class WebPage {
|
||||
* @param {!Array<!Object>} args
|
||||
*/
|
||||
evaluate(fun, ...args) {
|
||||
if (this._deferEvaluate)
|
||||
return await(this._page.evaluateOnInitialized(fun, ...args));
|
||||
return await(this._page.evaluate(fun, ...args));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user