puppeteer: [Bug]: page.waitForNetworkIdle timeout inconsistently
Bug description
For some reason page.waitForNetworkIdle is timing out for no reason. the network is empty and even so it timeout after 30 seconds.
This error happens only sometimes and is very weird. Despite of that, I find a way to make it fail consistently by repeating some steps multiple times
Steps to reproduce the problem:
I created a repo with some simple puppeteer code
Locally
you can reproduce it locally by (my current local environment is WSL2 ubuntu)
- clone the repo
- install dependencies
yarn yarn start
In GitHub Actions
- Create a new issue in the reproduction repo or use the issue
test - Create any comment
- Check the actions tab
Puppeteer version
“puppeteer”: “14.1.1”,
Node.js version
Local v16.15.0 / node 16
npm version
local 8.9.0 / actions https://github.com/actions/checkout
What operating system are you seeing the problem on?
Linux
Relevant log output
file:///home/runner/work/puppetter-timeout-reproduction/puppetter-timeout-reproduction/upleveled-drone.mjs:18421
rejectCallback(new TimeoutError("Timeout exceeded while waiting for event"));
^
TimeoutError: Timeout exceeded while waiting for event
at Timeout.<anonymous> (file:///home/runner/work/puppetter-timeout-reproduction/puppetter-timeout-reproduction/upleveled-drone.mjs:18421:22)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
Thanks for any attention that you gave to this issue, puppeteer is an amazing tool that we use every day in my company. I am also open to creating a PR if we are able to identify what is the problem.
Good energy 👍👍👍👍
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 15 (3 by maintainers)
Having similar issue here. I notice that when an ajax request completes very quickly I get this timeout. As if the monitoring of network being idle begins after the network is already idle.
Ideally,
waitForNetworkIdleshould resolve even when no network activity is expected. Or perhaps have an optionactivityExpect: boolean // defaults to true.I am having the same issue!
Yeah, looks like some sort of bug! Thanks for reporting.
I ran into the same problem and I think I found out why this is happening.
In my case (you may have something else), the site sends beacon requests, which chrome marks as ping (judging by the mdn documentation):
(in the compatibility table, chrome does not support beacon)
Beacon requests, in turn, do not require responses, which is why when checking in the NetworkEventManager.numRequestsInProgress request.response() is always null and puppeteer believes that the request has not yet been completed.
The solution is either to add a check to NetworkEventManager.numRequestsInProgress on request.resourceType() === ‘ping’ or not to add this type to httpRequestsMap at all.
Something like this
UPD. However, I did not meet such requests on the example of @Josehower, but the hangups remained. So the problem is deeper 😦
Hey, didn’t have time to look into that yet. The code for the function is here https://github.com/puppeteer/puppeteer/blob/main/src/common/Page.ts#L1944 It looks like sometimes the request count does not update as expected.
Adding some context to where the app times out.
The app is tested by
puppeteerupdating an image source with a nonvalid URL, which results in a 404 response from the server, the image update is happening on each letter type which causes a bunch of 404 happening quick.The code that fails is
The unexpected behavior is sometimes this
page.waitForNetworkIdle()is timing out after 30 secs which is very weird. also, the block that fails is always different. (sometimes fails in check No1 and sometimes breaks on check 6 etc)The problem is this error is not always happening, actually, most of the
waitForNetworkIdle’s do not timeout what would be the expected behavior, since a broken link should respond with a 404 very quick.Add again here a link to the full GitHub actions workflow with the fail example