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

page.waitForNavigation() timeout=0 does not disable timeout, but actually sets it to zero #1417

Closed
vonGameTheory opened this issue Nov 18, 2017 · 3 comments · Fixed by #1435
Assignees
Labels

Comments

@vonGameTheory
Copy link

v1.0.0-rc page.waitForNavigation()

setting timeout:0 should disable timeout according to the docs (meaning it never times out), but it seems to just actually set it to 0 seconds, and then promise reverts to null immediately everytime.

@vonGameTheory
Copy link
Author

Or on second thought, maybe it isn't "setting it to zero seconds" rather than just breaking it somehow as it doesn't throw a timeout error, but the promise returned just seems to disappear (starts out as pending but silently goes to null immediately). In any case, it doesn't work.

@vonGameTheory
Copy link
Author

vonGameTheory commented Nov 20, 2017

So here is the relevant bit of code from NavigatorWatcher.js, line 49 and following:

    const lifecycleCompletePromise = new Promise(fulfill => {
      this._lifecycleCompleteCallback = fulfill;
    });
    this._navigationPromise = Promise.race([
      this._createTimeoutPromise(),
      lifecycleCompletePromise
    ]).then(error => {
      this._cleanup();
      return error;
    });
  }

  /**
   * @return {?Promise<?Error>}
   */
  _createTimeoutPromise() {
    if (!this._timeout)
      return null;
    const errorMessage = 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded';
    return new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout))
        .then(() => new Error(errorMessage));
  }

If timeout is set to zero, then _createTimeoutPromise returns a non-Promise plain null, which ends up in the Promise.race function above it, apparently with the idea that it would just ignore it, but any non-Promise given to Promise.race will "win the race" immediately and be returned as the resolved value, thus resolving _navigationPromise with null, which should never happen.

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Nov 20, 2017
Since non-promise values always win the `Promise.race`, we shouldn't
return `null` for timeout promise in NavigationWatcher.

Instead, we can return a promise that never resolved. It should be
GC'd later with the navigation watcher itself.

Fixes puppeteer#1417.
@aslushnikov aslushnikov self-assigned this Nov 20, 2017
@aslushnikov
Copy link
Contributor

@vonGameTheory thank you for the investigation. I've sent the fix.

aslushnikov added a commit that referenced this issue Nov 21, 2017
#1435)

Since non-promise values always win the `Promise.race`, we shouldn't
return `null` for timeout promise in NavigationWatcher.

Instead, we can return a promise that never resolved. It should be
GC'd later with the navigation watcher itself.

Fixes #1417.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants