New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow options.timeout to be 0
to disable timeout
#887
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay, thanks for the pull request!
lib/NavigatorWatcher.js
Outdated
@@ -40,8 +40,10 @@ class NavigatorWatcher { | |||
|
|||
this._eventListeners = []; | |||
|
|||
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) | |||
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'); | |||
const watchdog = new Promise(fulfill => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little tricky: there should be no watchdog if there's no timeout timer.
I'd rather do:
const navigationPromises = [];
if (this._timeout) {
const watchdog = new Promise(fulfill => {
// ...
});
navigationPromises.push(watchdog);
}
test/test.js
Outdated
@@ -619,6 +619,16 @@ describe('Page', function() { | |||
expect(error.message).toContain('Navigation Timeout Exceeded: 1ms'); | |||
process.removeListener('unhandledRejection', unhandledRejectionHandler); | |||
})); | |||
it('should work when option.timeout set to 0', SX(async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test will run for quite some time - which is unfortunate.
Developer's time is precious! :)
I'd rather make sure that timeout: 0
doesn't set a zero timeout watchdog:
it('should disable timeout when its set to 0', SX(async function() {
let error = null;
await page.goto(PREFIX + '/grid.html', {timeout: 0}).then(e => error = e);
expect(error).toBe(null);
}));
@@ -594,7 +594,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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bunch of other methods that rely on NavigationWatcher, so you should add this clarification there as well:
page.goForward()
page.boBack();
page.reload();
page.waitForNavigation()
0
to disable timeout0
to disable timeout
test/test.js
Outdated
let error = null; | ||
page.goto(PREFIX + '/empty.html', {timeout: 0}).catch(e => error = e); | ||
// const sleep = e => new Promise(ff => setTimeout(ff, e)); | ||
// await sleep(90000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developer's time is precious! :)
agree, sorry but leave it as comment. Perhaps someone want to inspect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, drop these comments: they are not useful for other puppeteer developers.
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) | ||
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'); | ||
navigationPromises.push(watchdog); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is as the @aslushnikov suggestion, it's simple and clear code. But it think it still have problem if user pass timeout 0 as a string. I'd like add more conditional check, or we just rely on the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brutalcrozt yes, we should rely on documentation in this case and expect user to pass in a number. There's also a check that timeout is always a number: https://github.com/GoogleChrome/puppeteer/blob/c46c41d89caefd1e1951055fb041521a2bcc933b/lib/NavigatorWatcher.js#L28
Clarification:the puppeteer launch options is documented accept my question:
as the puppeteer options which first documented as accept 0 to disable timeout. I can't see it's implementation, i hope just i who miss it. Also when i look up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for working on this! Left a few more comments before we can merge this.
const watchdog = new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) | ||
.then(() => 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'); | ||
navigationPromises.push(watchdog); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brutalcrozt yes, we should rely on documentation in this case and expect user to pass in a number. There's also a check that timeout is always a number: https://github.com/GoogleChrome/puppeteer/blob/c46c41d89caefd1e1951055fb041521a2bcc933b/lib/NavigatorWatcher.js#L28
test/test.js
Outdated
it('should disable timeout when its set to 0', SX(async function() { | ||
server.setRoute('/empty.html', (req, res) => {}); | ||
let error = null; | ||
page.goto(PREFIX + '/empty.html', {timeout: 0}).catch(e => error = e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await
is missing:
await page.goto(PREFIX + '/empty.html', {timeout: 0}).catch(e => error = e);
test/test.js
Outdated
let error = null; | ||
page.goto(PREFIX + '/empty.html', {timeout: 0}).catch(e => error = e); | ||
// const sleep = e => new Promise(ff => setTimeout(ff, e)); | ||
// await sleep(90000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, drop these comments: they are not useful for other puppeteer developers.
test/test.js
Outdated
// const sleep = e => new Promise(ff => setTimeout(ff, e)); | ||
// await sleep(90000); | ||
expect(error).toBe(null); | ||
}));// 100000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please drop the comment here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sir
These are different timeouts. One is a navigation timeout, another one is a browser launcher timeout. |
Ok this what i looking for, i just miss it. Thanks for the review, thank for your cooperation 😄 |
0
to disable timeout0
to disable timeout
Intended to close #782 , sorry if this one look really premature.
As the first point
Clarification:
the puppeteer launch options is documented accept
0
to disable timeout. Is #782 only matchgoto
options?i already test with
fit
with 100 sec, and it pass.on my windows machine test 1 spec always fail and that is:
so i just rely on travis
documentation:
should i also change
page.goBack(options)
,page.goForward(options)
? let me know if i miss some