作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试将大发票转换为 PDF 时出现“超时错误:WAITING Page.printToPDF 失败”:
Unhandled Rejection at: Promise Promise { <rejected>
TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded
at Object.waitWithTimeout (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/helper.js:224:26)
at Page.createPDFStream (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2045:49)
at Page.pdf (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2057:37)
at /var/www/montbeau/releases/20210929161149/scripts/invoice_to_pdf.js:175:20
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
} reason: TimeoutError: waiting for Page.printToPDF failed: timeout
30000ms exceeded
at Object.waitWithTimeout (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/helper.js:224:26)
at Page.createPDFStream (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2045:49)
at Page.pdf (/var/www/montbeau/releases/20210929161149/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:2057:37)
at /var/www/montbeau/releases/20210929161149/scripts/invoice_to_pdf.js:175:20...
如何增加超时时间?
最佳答案
在 puppeteer/lib/cjs/puppeteer/common/Page.js
的 createPDFStream
方法中,超时作为一个选项出现:
2007 const { scale = 1, displayHeaderFooter = false, headerTemplate = '', footerTemplate = '', printBackground = false, landscapdscape = false, pageRanges = '', preferCSSPageSize = false, margin = {}, omitBackground = false, timeout = 30000, } = options;
[...]
2045 const result = await helper_js_1.helper.waitWithTimeout(printCommandPromise, 'Page.printToPDF', timeout);
所以尽管 timeout
不是 https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions 的记录选项, 它似乎确实是 .pdf
方法的一个选项。
关于puppeteer - 获取 "TimeoutError: waiting for Page.printToPDF failed"时如何增加 pupetteer 的 Page.pdf 的超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69436420/
尝试将大发票转换为 PDF 时出现“超时错误:WAITING Page.printToPDF 失败”: Unhandled Rejection at: Promise Promise { Time
我是一名优秀的程序员,十分优秀!