From 5757bc18f2983b71087bd63eaa9369b002f50485 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sat, 22 Jul 2017 16:25:00 -0700 Subject: [PATCH] Rename 'maxTime' option of Page.navigate into 'timeout' The motivation behind this rename is to name all the 'timeout' options across methods similarly. References #39. --- docs/api.md | 4 ++-- lib/NavigatorWatcher.js | 4 ++-- lib/Page.js | 1 + test/test.js | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index 050816268c7..0f111c12985 100644 --- a/docs/api.md +++ b/docs/api.md @@ -432,7 +432,7 @@ Page is guaranteed to have a main frame which persists during navigations. #### page.navigate(url, options) - `url` <[string]> URL to navigate page to - `options` <[Object]> Navigation parameters which might have the following properties: - - `maxTime` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. - `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either: - `load` - consider navigation to be finished when the `load` event is fired. - `networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms. @@ -443,7 +443,7 @@ Page is guaranteed to have a main frame which persists during navigations. The `page.navigate` will throw an error if: - there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. -- the `maxTime` is exceeded during navigation. +- the `timeout` is exceeded during navigation. #### page.pdf(options) - `options` <[Object]> Options object which might have the following properties: diff --git a/lib/NavigatorWatcher.js b/lib/NavigatorWatcher.js index f05de1773d6..e6ba97a2168 100644 --- a/lib/NavigatorWatcher.js +++ b/lib/NavigatorWatcher.js @@ -25,7 +25,7 @@ class NavigatorWatcher { constructor(client, networkManager, options = {}) { this._client = client; this._networkManager = networkManager; - this._maxTime = typeof options['maxTime'] === 'number' ? options['maxTime'] : 30000; + this._timeout = typeof options['timeout'] === 'number' ? options['timeout'] : 30000; this._idleTime = typeof options['networkIdleTimeout'] === 'number' ? options['networkIdleTimeout'] : 1000; this._idleInflight = typeof options['networkIdleInflight'] === 'number' ? options['networkIdleInflight'] : 2; this._waitUntil = typeof options['waitUntil'] === 'string' ? options['waitUntil'] : 'load'; @@ -43,7 +43,7 @@ class NavigatorWatcher { .then(error => new Error('SSL Certiciate error: ' + error.errorType)); let networkIdle = new Promise(fulfill => this._networkIdleCallback = fulfill).then(() => null); let loadEventFired = new Promise(fulfill => this._client.once('Page.loadEventFired', fulfill)).then(() => null); - let watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._maxTime)).then(() => new Error('Navigation Timeout Exceeded: ' + this._maxTime + 'ms exceeded')); + let watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)).then(() => new Error('Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded')); try { // Await for the command to throw exception in case of illegal arguments. diff --git a/lib/Page.js b/lib/Page.js index b235a603b11..6105fc878c4 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -279,6 +279,7 @@ class Page extends EventEmitter { const result = watcher.waitForNavigation(); const referrer = this._networkManager.httpHeaders()['referer']; try { + // Await for the command to throw exception in case of illegal arguments. await this._client.send('Page.navigate', {url, referrer}); } catch (e) { watcher.cancel(); diff --git a/test/test.js b/test/test.js index 5673f81373c..6b854ca22e5 100644 --- a/test/test.js +++ b/test/test.js @@ -371,7 +371,7 @@ describe('Puppeteer', function() { // Hang for request to the empty.html server.setRoute('/empty.html', (req, res) => { }); try { - await page.navigate(PREFIX + '/empty.html', {maxTime: 59}); + await page.navigate(PREFIX + '/empty.html', {timeout: 59}); } catch (e) { error = e; }