踩坑chrome无图浏览器

chrome无图浏览器

centOS8 下安装了chrome,最近有一个需求就是自动导出pdf,定时任务,需要浏览器渲染出pdf

chrome的命令真的太tm多了

可以看这个
https://peter.sh/experiments/chromium-command-line-switches/

但是这网站的命令不全??我可太难了。

网页渲染是要时间的,很多时候pdf都是空的

chrome --headless http://localhost:8080/banana/key --run-all-compositor-stages-before-draw --print-to-pdf=C:\tmp\tmp.pdf

这个命令貌似可以,但是并不行。可以加--virtual-time-budget=10000 让他延迟打印

其他命令

--repl

可以在linux下用js,windos不行(我试过)

--ignore-certificate-errors

忽略https证书的错误

--dump-dom

打印html文件(这个和pdf好像不能同时用)

命令太多了。。。。各种坑。。。

粘一个我最后解决了我的问题的参数url

windows

chrome --headless --disable-gpu --print-to-pdf=d:/test.pdf --run-all-compositor-stages-before-draw --ignore-certificate-errors --acceptInsecureCerts https://127.0.0.1/login --virtual-time-budget=10000

linux

/opt/google/chrome/chrome --headless --disable-gpu --no-sandbox --print-to-pdf=/root/test.pdf --ignore-certificate-errors https://127.0.0.1/login --ignore-certificate-errors --virtual-time-budget=10000

注意--print-to-pdf必须指定完整路径,不然不能生成pdf(我也不知道为什么,反正加./test.pdf这样的路径就有问题)

posted @ 2021-05-19 12:36  吴雄  阅读(483)  评论(0编辑  收藏  举报