英文:
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 alert
s (or, presumably, confirm
s or prompt
s), 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 alert
s (or, presumably, confirm
s or prompt
s), 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论