Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer: page.screenshot Times Out

Tags:

puppeteer

I have a seemingly simple problem with Puppeteer: when I try to take a screenshot, like so ...

console.log(1)
await page.screenshot({ path: 'screenshot.png' });
console.log(2)

Puppeteer hangs. It doesn't error out or anything, it just waits forever (logging "1" but not "2"), until the whole test times out.

I'm not sure how to resolve this, as screenshot doesn't even have a timeout option I can use to force it to timeout faster (as many other Puppeteer functions do). Can anyone suggest:

A) any conditions that would cause this (eg. could I somehow be on a page that failed to load, or something like that)?

B) how I can get screenshot to take the screenshot, or at least throw an error if it can't?

like image 422
machineghost Avatar asked Sep 02 '25 02:09

machineghost


1 Answers

I finally did what I should have done from the start, and retried doing what my test was doing manually. When I did, I noticed that just before the screenshot was taken, my site was doing a plain old window.alert.

As soon as I commented that alert out, the screenshot worked successfully!

So, for future reference: if your page.screenshot is timing out, check for any alerts (or, presumably, confirms or prompts), as apparently Puppeteer can't handle taking a screenshot of one of the web's oldest UI features.

P.S. I filed https://github.com/puppeteer/puppeteer/issues/9801, so hopefully it will get fixed and I can delete this question/answer.

like image 172
machineghost Avatar answered Sep 08 '25 01:09

machineghost