mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(page): introduce page.setDefaultTimeout (#3854)
Method `page.setDefaultTimeout` overrides default 30 seconds timeout for all `page.waitFor*` methods, including navigation and waiting for selectors. Fix #3319.
This commit is contained in:
17
lib/Page.js
17
lib/Page.js
@@ -30,6 +30,7 @@ const {Coverage} = require('./Coverage');
|
||||
const {Worker} = require('./Worker');
|
||||
const {createJSHandle} = require('./JSHandle');
|
||||
const {Accessibility} = require('./Accessibility');
|
||||
const {TimeoutSettings} = require('./TimeoutSettings');
|
||||
const writeFileAsync = helper.promisify(fs.writeFile);
|
||||
|
||||
class Page extends EventEmitter {
|
||||
@@ -78,11 +79,12 @@ class Page extends EventEmitter {
|
||||
this._target = target;
|
||||
this._keyboard = new Keyboard(client);
|
||||
this._mouse = new Mouse(client, this._keyboard);
|
||||
this._timeoutSettings = new TimeoutSettings();
|
||||
this._touchscreen = new Touchscreen(client, this._keyboard);
|
||||
this._accessibility = new Accessibility(client);
|
||||
this._networkManager = new NetworkManager(client);
|
||||
/** @type {!FrameManager} */
|
||||
this._frameManager = new FrameManager(client, frameTree, this, this._networkManager);
|
||||
this._frameManager = new FrameManager(client, frameTree, this, this._networkManager, this._timeoutSettings);
|
||||
this._networkManager.setFrameManager(this._frameManager);
|
||||
this._emulationManager = new EmulationManager(client);
|
||||
this._tracing = new Tracing(client);
|
||||
@@ -268,7 +270,14 @@ class Page extends EventEmitter {
|
||||
* @param {number} timeout
|
||||
*/
|
||||
setDefaultNavigationTimeout(timeout) {
|
||||
this._frameManager.setDefaultNavigationTimeout(timeout);
|
||||
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} timeout
|
||||
*/
|
||||
setDefaultTimeout(timeout) {
|
||||
this._timeoutSettings.setDefaultTimeout(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -664,7 +673,7 @@ class Page extends EventEmitter {
|
||||
*/
|
||||
async waitForRequest(urlOrPredicate, options = {}) {
|
||||
const {
|
||||
timeout = 30000
|
||||
timeout = this._timeoutSettings.timeout(),
|
||||
} = options;
|
||||
return helper.waitForEvent(this._networkManager, Events.NetworkManager.Request, request => {
|
||||
if (helper.isString(urlOrPredicate))
|
||||
@@ -682,7 +691,7 @@ class Page extends EventEmitter {
|
||||
*/
|
||||
async waitForResponse(urlOrPredicate, options = {}) {
|
||||
const {
|
||||
timeout = 30000
|
||||
timeout = this._timeoutSettings.timeout(),
|
||||
} = options;
|
||||
return helper.waitForEvent(this._networkManager, Events.NetworkManager.Response, response => {
|
||||
if (helper.isString(urlOrPredicate))
|
||||
|
||||
Reference in New Issue
Block a user