保持 Chrome 运行 处于无头模式

Keep Chrome running in headless mode

我想在无头模式下使用 Chrome 浏览器从 SVG 图形中生成图像(PNG、JPEG)。代码在正常交互模式下工作,但我在无头模式下使用它时遇到问题。

我的主要问题是 headless Chrome 在 HTML 页面绘制完成之前退出。据我了解,如果我使用以下参数开始 Chrome:

chromium --headless http://myserver.org

document.onload事件一起退出。但此时并非所有数据都从服务器获取(我使用 XMLHttpRequest),因此绘制不完整。

如果我启动 chrome 并启用调试端口,我找到了解决方法,例如:

chromium --headless --remote-debugging-port=7777 http://myserver.org

但这不是我想要的,尤其是当我没有权限打开节点上的 http 端口时。是否有可能让 Chrome 运行 与其他标志一起使用更长的时间?我查了一个lot of them,但是没找到合适的。或者有没有其他方法可以推迟无头的退出Chrome?

你可以试试这个答案

复制粘贴此处以供参考

Use the binary /opt/google/chrome/chrome directly not google-chrome which points to bash script /usr/bin/google-chrome.

Taken from comments in

https://developers.google.com/web/updates/2017/04/headless-chrome#screenshots