Closed ProQuestionAsker closed 4 years ago
You should move const browser = await firefox.launch
out of the loop - that will speed up your script 1000 times. Also pass default viewport size into the newContext
instead of setting it all the time.
Good call! With those changes and a page.on('pageerror'...)
check, it seems to be working. I'll run it a few more times tomorrow and see if it pops up again. Thanks!
Closing as this seems to be resolved. Please comment/reopen if the issue persists.
You should move const browser = await firefox.launch out of the loop - that will speed up your script 1000 times. Also pass default viewport size into the newContext instead of setting it all the time.
This was nice general advice about the code shown. But unless I am missing something this issue doesn't quite discuss the expected scenarios when await context.newPage()
is known to not return for a long time. We're affected by that right now, and I'm starting to debug this. Was hoping to get some more specific advice in here :).
Context:
Code Snippet I'm running a script in Heroku that loops over a number of urls and takes screenshots. Every once in a while (maybe 40% of the time?) the loop will indefinitely hang. I've finally tracked it down to the
newPage
function.A simplified version of my code is something like this:
Describe the bug
I've tried running the script with
process.env.DEBUG='pw:api'
. When combined with lots of console logs, I've found that typically whenawait context.newPage()
runs, this is printed to the terminal:and my script continues as expected.
But sometimes it never prints, never throws an error, and never times out. To be clear, the browser and context both seem to have successfully launched, but the new page doesn't. Sometimes this happens after 10 loops through my script, other times it happens after 1 or 2. Has anyone else stumbled upon something like this?
Many thanks for the amazing work!
Edit to add: I just tried running again with
process.env.DEBUG='pw:browser'
and when it hangs, I get these warnings after the context has launched: