Puppeteer:page.screenshot超时

huangapple go评论50阅读模式
英文:

Puppeteer: page.screenshot Times Out

问题

我遇到了一个看似简单的Puppeteer问题:当我尝试截取屏幕截图时,像这样...

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

Puppeteer卡住了。它没有报错,也没有任何提示,它就是永远等待下去(记录了“1”但没有“2”),直到整个测试超时。

我不确定该如何解决这个问题,因为screenshot甚至没有一个我可以用来强制它更快超时的timeout选项(就像许多其他Puppeteer函数那样)。有人能提供以下建议吗:

A)可能导致这种情况的任何条件(例如,我可能在加载失败的页面上,或者其他类似的情况)?

B)如何让screenshot截取屏幕截图,或者至少在无法截图时抛出错误?

英文:

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?

答案1

得分: 1

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.

英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 14:27:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定