From 34a96a846232745384987b61ac1a8066a70da002 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 14 Jul 2017 13:59:36 -0700 Subject: [PATCH] Rename navigation option 'waitFor' into 'waitUntil'. This patch renames navigation option 'waitFor' into 'waitUntil' to avoid confusion with 'page.waitFor' call. References #39. --- docs/api.md | 6 +++--- lib/Navigator.js | 6 +++--- test/test.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/api.md b/docs/api.md index 3fc4b2899f6..6f63b9779b8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -232,11 +232,11 @@ Page is guaranteed to have a main frame which persists during navigations. - `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. - - `waitFor` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either: + - `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. - - `networkIdleInflight` <[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitFor: 'networkidle'` parameter. - - `networkIdleTimeout` <[number]> A timeout to wait before completing navigation. Takes effect only with `waitFor: 'networkidle'` parameter. + - `networkIdleInflight` <[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter. + - `networkIdleTimeout` <[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter. - returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. The `page.navigate` will throw an error if: diff --git a/lib/Navigator.js b/lib/Navigator.js index af933bc8c12..cbfff512381 100644 --- a/lib/Navigator.js +++ b/lib/Navigator.js @@ -28,9 +28,9 @@ class Navigator { this._maxTime = typeof options['maxTime'] === 'number' ? options['maxTime'] : 30000; this._idleTime = typeof options['networkIdleTimeout'] === 'number' ? options['networkIdleTimeout'] : 1000; this._idleInflight = typeof options['networkIdleInflight'] === 'number' ? options['networkIdleInflight'] : 2; - this._waitFor = typeof options['waitFor'] === 'string' ? options['waitFor'] : 'load'; + this._waitUntil = typeof options['waitUntil'] === 'string' ? options['waitUntil'] : 'load'; - console.assert(this._waitFor === 'load' || this._waitFor === 'networkidle', 'Unknown value for options.waitFor: ' + this._waitFor); + console.assert(this._waitUntil === 'load' || this._waitUntil === 'networkidle', 'Unknown value for options.waitUntil: ' + this._waitUntil); } /** @@ -52,7 +52,7 @@ class Navigator { throw e; } - const error = await Promise.race([certificateError, watchdog, this._waitFor === 'load' ? loadEventFired : networkIdle]); + const error = await Promise.race([certificateError, watchdog, this._waitUntil === 'load' ? loadEventFired : networkIdle]); this._cleanup(); if (error) throw error; diff --git a/test/test.js b/test/test.js index d5c10930c94..79a2e95d4dc 100644 --- a/test/test.js +++ b/test/test.js @@ -274,7 +274,7 @@ describe('Puppeteer', function() { // Navigate to a page which loads immediately and then does a bunch of // requests via javascript's fetch method. let navigationPromise = page.navigate(PREFIX + '/networkidle.html', { - waitFor: 'networkidle', + waitUntil: 'networkidle', networkIdleTimeout: 100, networkIdleInflight: 0, // Only be idle when there are 0 inflight requests }); @@ -324,7 +324,7 @@ describe('Puppeteer', function() { // Navigate to a page which loads immediately and then opens a bunch of // websocket connections and then a fetch request. let navigationPromise = page.navigate(PREFIX + '/websocket.html', { - waitFor: 'networkidle', + waitUntil: 'networkidle', networkIdleTimeout: 100, networkIdleInflight: 0, // Only be idle when there are 0 inflight requests/connections });