diff --git a/docs/api.md b/docs/api.md index 9a991754..29a4a605 100644 --- a/docs/api.md +++ b/docs/api.md @@ -573,7 +573,7 @@ If there's no element matching `selector`, the method throws an error. #### page.goBack(options) - `options` <[Object]> Navigation parameters which might have the following properties: - - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. - `waitUntil` <[string]> When to consider a navigation finished, 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. @@ -586,7 +586,7 @@ Navigate to the previous page in history. #### page.goForward(options) - `options` <[Object]> Navigation parameters which might have the following properties: - - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. - `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. @@ -600,7 +600,7 @@ Navigate to the next page in history. #### page.goto(url, options) - `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`. - `options` <[Object]> Navigation parameters which might have the following properties: - - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. - `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. @@ -711,7 +711,7 @@ Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#ke #### page.reload(options) - `options` <[Object]> Navigation parameters which might have the following properties: - - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. - `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. @@ -906,7 +906,7 @@ Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args] #### page.waitForNavigation(options) - `options` <[Object]> Navigation parameters which might have the following properties: - - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds. + - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. - `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. diff --git a/lib/NavigatorWatcher.js b/lib/NavigatorWatcher.js index 30b91a31..808e9bce 100644 --- a/lib/NavigatorWatcher.js +++ b/lib/NavigatorWatcher.js @@ -40,9 +40,12 @@ class NavigatorWatcher { this._eventListeners = []; - const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) - .then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'); - const navigationPromises = [watchdog]; + const navigationPromises = []; + if (this._timeout) { + const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) + .then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'); + navigationPromises.push(watchdog); + } if (!this._ignoreHTTPSErrors) { const certificateError = new Promise(fulfill => { diff --git a/test/test.js b/test/test.js index 434720fe..2337a9a4 100644 --- a/test/test.js +++ b/test/test.js @@ -624,6 +624,11 @@ describe('Page', function() { expect(error.message).toContain('Navigation Timeout Exceeded: 1ms'); process.removeListener('unhandledRejection', unhandledRejectionHandler); })); + it('should disable timeout when its set to 0', SX(async function() { + let error = null; + await page.goto(PREFIX + '/grid.html', {timeout: 0}).catch(e => error = e); + expect(error).toBe(null); + })); it('should work when navigating to valid url', SX(async function() { const response = await page.goto(EMPTY_PAGE); expect(response.ok).toBe(true);