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

fix: add Page.loadEventFired listener before navigating #92

Merged

Conversation

halbgut
Copy link
Contributor

@halbgut halbgut commented Nov 3, 2017

When navigating it sometimes happens that the navigate callback result is sent after the Page.loadEventFired event is sent. The result is that the PDF generation promise never resolves. With this PR the generate function first sets the Page.loadEventFired listener and calls navigate after.

For my personally at least 50% of the tests were failing locally every time. Which tests failed seemed pretty random. Now they consistently pass. Just out of curiosity, have you never encountered this issue?

@codecov
Copy link

codecov bot commented Nov 3, 2017

Codecov Report

Merging #92 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #92   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines         108    106    -2     
  Branches       12     12           
=====================================
- Hits          108    106    -2
Impacted Files Coverage Δ
src/index.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0be3977...2062cf5. Read the comment docs.

src/index.ts Outdated
await Page.navigate({url});
await throwIfCanceled(options);
await Page.loadEventFired();
await navigate(client, url);
Copy link
Owner

Choose a reason for hiding this comment

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

Could we instead just await on the two in parallel?

await Promise.all([Page.navigate({url}), Page.loadEventFired()]); // Resolve order varies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, way nicer!

@halbgut halbgut force-pushed the fix/naviate-triggered-after-page-load branch from 495cc73 to 6f4f20a Compare November 4, 2017 23:45
src/index.ts Outdated
await throwIfCanceled(options);
await Page.loadEventFired();
await Promise.all([
client.Page.navigate({url}),
Copy link
Owner

Choose a reason for hiding this comment

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

Drop the unnecessary client..

test/index.ts Outdated
setTimeout(() => {
document.getElementById('test').innerHTML = 'Passed!';
}, 100);
document.addEventListener('DOMContentLoaded', () => {
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The event listener isn't strictly necessary. But the longer timeout is. When running this test locally on my machine it consistently failed with the new behavior. Only with the increased timeout it passes.

Copy link
Owner

Choose a reason for hiding this comment

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

Please remove the event listener. Keep the timeout at 100ms and try to increase the test timer to 300ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can decrease this timeout to 200ms. If I keep it at 100ms the "permature" test runs after the timeout callback runs. I changed it to 500ms in order to have some tolerance.

Copy link
Owner

Choose a reason for hiding this comment

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

200ms is okay. Thanks.

@halbgut halbgut force-pushed the fix/naviate-triggered-after-page-load branch from 6f4f20a to bbf8b5a Compare November 4, 2017 23:51
@westy92 westy92 added the bug label Nov 5, 2017
@westy92 westy92 merged commit 5f584c6 into westy92:master Nov 5, 2017
@westy92
Copy link
Owner

westy92 commented Nov 5, 2017

Thank you!

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 this pull request may close these issues.

2 participants