mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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.
This commit is contained in:
parent
bafd937fc3
commit
53531c9a92
10
docs/api.md
10
docs/api.md
@ -573,7 +573,7 @@ If there's no element matching `selector`, the method throws an error.
|
|||||||
|
|
||||||
#### page.goBack(options)
|
#### page.goBack(options)
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `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:
|
- `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.
|
- `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.
|
- `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)
|
#### page.goForward(options)
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `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:
|
- `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.
|
- `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.
|
- `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)
|
#### page.goto(url, options)
|
||||||
- `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`.
|
- `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:
|
- `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:
|
- `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.
|
- `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.
|
- `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)
|
#### page.reload(options)
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `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:
|
- `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.
|
- `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.
|
- `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)
|
#### page.waitForNavigation(options)
|
||||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
- `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:
|
- `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.
|
- `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.
|
- `networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout` ms.
|
||||||
|
@ -40,9 +40,12 @@ class NavigatorWatcher {
|
|||||||
|
|
||||||
this._eventListeners = [];
|
this._eventListeners = [];
|
||||||
|
|
||||||
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout))
|
const navigationPromises = [];
|
||||||
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded');
|
if (this._timeout) {
|
||||||
const navigationPromises = [watchdog];
|
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) {
|
if (!this._ignoreHTTPSErrors) {
|
||||||
const certificateError = new Promise(fulfill => {
|
const certificateError = new Promise(fulfill => {
|
||||||
|
@ -624,6 +624,11 @@ describe('Page', function() {
|
|||||||
expect(error.message).toContain('Navigation Timeout Exceeded: 1ms');
|
expect(error.message).toContain('Navigation Timeout Exceeded: 1ms');
|
||||||
process.removeListener('unhandledRejection', unhandledRejectionHandler);
|
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() {
|
it('should work when navigating to valid url', SX(async function() {
|
||||||
const response = await page.goto(EMPTY_PAGE);
|
const response = await page.goto(EMPTY_PAGE);
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user