我已经使用 apt 在我的 Ubuntu 20 VM 上安装了 Google Chrome。当我运行诸如
google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html
一切正常,我得到了呈现的 html 页面的 pdf。但是,如果我添加一些 url 参数,例如:
google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html?foo=bar
然后生成的 PDF 为空白。它包含页眉和页脚,但没有其他内容。首先,有没有其他人遇到过这个或者我做错了什么?也许这是在 headless chrome 中内置的不接受 url 参数?
我已经通过 Google 进行了搜索,但无法找到答案,因此非常感谢您提供任何帮助。
编辑:只是添加;我尝试使用反斜杠转义问号,但这也没有用。
最佳答案
您需要添加反斜杠 ( \ )
在所有查询参数中。
我在这里发布示例,请看一下!
initial_html_file_path = /var/www/html/temp.html?foo=bar&foo2=bar2
converted_html_file_path = /var/www/html/temp.html\?foo\=bar\&foo2\=bar2
-> 最终脚本
google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html\?foo\=bar\&foo2\=bar2
关于shell - 使用带有 url 参数的 headless chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68132639/