Skip to content

Commit 53531c9

Browse files
sukrosonoaslushnikov
authored andcommitted
feat(page): Allow Page.goto's timeout to be 0 to disable timeout (#887)
This patch allows passing 0 to disable timeout for the following methods: - page.goto - page.waitForNavigation - page.goForward - page.goBack Fixes #782.
1 parent bafd937 commit 53531c9

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

docs/api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ If there's no element matching `selector`, the method throws an error.
573573

574574
#### page.goBack(options)
575575
- `options` <[Object]> Navigation parameters which might have the following properties:
576-
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
576+
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
577577
- `waitUntil` <[string]> When to consider a navigation finished, defaults to `load`. Could be either:
578578
- `load` - consider navigation to be finished when the `load` event is fired.
579579
- `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.
586586

587587
#### page.goForward(options)
588588
- `options` <[Object]> Navigation parameters which might have the following properties:
589-
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
589+
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
590590
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
591591
- `load` - consider navigation to be finished when the `load` event is fired.
592592
- `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.
600600
#### page.goto(url, options)
601601
- `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`.
602602
- `options` <[Object]> Navigation parameters which might have the following properties:
603-
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
603+
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
604604
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
605605
- `load` - consider navigation to be finished when the `load` event is fired.
606606
- `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
711711

712712
#### page.reload(options)
713713
- `options` <[Object]> Navigation parameters which might have the following properties:
714-
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
714+
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
715715
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
716716
- `load` - consider navigation to be finished when the `load` event is fired.
717717
- `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]
906906

907907
#### page.waitForNavigation(options)
908908
- `options` <[Object]> Navigation parameters which might have the following properties:
909-
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
909+
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
910910
- `waitUntil` <[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
911911
- `load` - consider navigation to be finished when the `load` event is fired.
912912
- `networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout` ms.

lib/NavigatorWatcher.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ class NavigatorWatcher {
4040

4141
this._eventListeners = [];
4242

43-
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout))
44-
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded');
45-
const navigationPromises = [watchdog];
43+
const navigationPromises = [];
44+
if (this._timeout) {
45+
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout))
46+
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded');
47+
navigationPromises.push(watchdog);
48+
}
4649

4750
if (!this._ignoreHTTPSErrors) {
4851
const certificateError = new Promise(fulfill => {

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ describe('Page', function() {
624624
expect(error.message).toContain('Navigation Timeout Exceeded: 1ms');
625625
process.removeListener('unhandledRejection', unhandledRejectionHandler);
626626
}));
627+
it('should disable timeout when its set to 0', SX(async function() {
628+
let error = null;
629+
await page.goto(PREFIX + '/grid.html', {timeout: 0}).catch(e => error = e);
630+
expect(error).toBe(null);
631+
}));
627632
it('should work when navigating to valid url', SX(async function() {
628633
const response = await page.goto(EMPTY_PAGE);
629634
expect(response.ok).toBe(true);

0 commit comments

Comments
 (0)