Skip to content
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

Merged
merged 4 commits into from Sep 30, 2017
Merged

Allow options.timeout to be 0 to disable timeout #887

merged 4 commits into from Sep 30, 2017

Conversation

sukrosono
Copy link
Contributor

@sukrosono sukrosono commented Sep 26, 2017

Intended to close #782 , sorry if this one look really premature.

As the first point

every feature should be accompanied by a test
are we count this one count as feature? if yes is this correct way to test it?

Clarification:
the puppeteer launch options is documented accept 0 to disable timeout. Is #782 only match goto options?

i already test with fit with 100 sec, and it pass.

on my windows machine test 1 spec always fail and that is:

Page Network Events Page.Events.Response should not report body unless request is finished

so i just rely on travis

documentation:
should i also change page.goBack(options) , page.goForward(options) ? let me know if i miss some

Copy link
Contributor

@aslushnikov aslushnikov left a 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!

@@ -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 => {
Copy link
Contributor

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() {
Copy link
Contributor

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.
Copy link
Contributor

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()

@sukrosono sukrosono changed the title Allow options.timeout to be 0 to disable timeout [WIP] Allow options.timeout to be 0 to disable timeout Sep 27, 2017
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);
Copy link
Contributor Author

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.

Copy link
Contributor

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);
}
Copy link
Contributor Author

@sukrosono sukrosono Sep 28, 2017

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?

Copy link
Contributor

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

@sukrosono
Copy link
Contributor Author

Clarification:

the puppeteer launch options is documented accept 0 to disable timeout.

my question:

  • is it same the page options and puppeteer options?
  • is it completely different thing? what's the relation?

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 Puppeteer, Browser and Launcher class, that class not importing NavigationWatcher. Sorry dude if i just to noisy 😄

Copy link
Contributor

@aslushnikov aslushnikov left a 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);
}
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sir

@aslushnikov
Copy link
Contributor

is it same the page options and puppeteer options?
is it completely different thing? what's the relation?

These are different timeouts. One is a navigation timeout, another one is a browser launcher timeout.

@sukrosono
Copy link
Contributor Author

https://github.com/GoogleChrome/puppeteer/blob/c46c41d89caefd1e1951055fb041521a2bcc933b/lib/Launcher.js#L177

Ok this what i looking for, i just miss it. Thanks for the review, thank for your cooperation 😄

@sukrosono sukrosono changed the title [WIP] Allow options.timeout to be 0 to disable timeout Allow options.timeout to be 0 to disable timeout Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constantly getting Navigation Timeout Error
2 participants