feat(Page): Add global navigation timeout setting (#1728)

This patch introduces `page.setDefaultNavigationTimeout` method to override the 
default 30 seconds navigation timeout.

Fixes #1514
This commit is contained in:
Radu Aron
2018-01-10 23:04:01 +02:00
committed by Andrey Lushnikov
parent 3985dee54e
commit ec8e40f1cb
4 changed files with 41 additions and 11 deletions

View File

@@ -79,6 +79,7 @@ class Page extends EventEmitter {
this._pageBindings = new Map();
this._ignoreHTTPSErrors = ignoreHTTPSErrors;
this._coverage = new Coverage(client);
this._defaultNavigationTimeout = 30000;
this._screenshotTaskQueue = screenshotTaskQueue;
@@ -170,6 +171,13 @@ class Page extends EventEmitter {
return this._networkManager.setOfflineMode(enabled);
}
/**
* @param {number} timeout
*/
setDefaultNavigationTimeout(timeout) {
this._defaultNavigationTimeout = timeout;
}
/**
* @param {!Object} event
*/
@@ -471,7 +479,7 @@ class Page extends EventEmitter {
* @param {!Object=} options
* @return {!Promise<?Response>}
*/
async goto(url, options) {
async goto(url, options = {}) {
const referrer = this._networkManager.extraHTTPHeaders()['referer'];
const requests = new Map();
@@ -480,7 +488,8 @@ class Page extends EventEmitter {
];
const mainFrame = this._frameManager.mainFrame();
const watcher = new NavigatorWatcher(this._frameManager, mainFrame, options);
const timeout = typeof options.timeout === 'number' ? options.timeout : this._defaultNavigationTimeout;
const watcher = new NavigatorWatcher(this._frameManager, mainFrame, timeout, options);
const navigationPromise = watcher.navigationPromise();
let error = await Promise.race([
navigate(this._client, url, referrer),
@@ -527,9 +536,10 @@ class Page extends EventEmitter {
* @param {!Object=} options
* @return {!Promise<!Response>}
*/
async waitForNavigation(options) {
async waitForNavigation(options = {}) {
const mainFrame = this._frameManager.mainFrame();
const watcher = new NavigatorWatcher(this._frameManager, mainFrame, options);
const timeout = typeof options.timeout === 'number' ? options.timeout : this._defaultNavigationTimeout;
const watcher = new NavigatorWatcher(this._frameManager, mainFrame, timeout, options);
const responses = new Map();
const listener = helper.addEventListener(this._networkManager, NetworkManager.Events.Response, response => responses.set(response.url(), response));