google-chrome - 保持 Chrome 在 headless 模式下运行

标签 google-chrome google-chrome-headless

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

我的主要问题是 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 ,但没有找到合适的。或者有没有其他方法可以推迟 headless Chrome 的退出?

最佳答案

你可以试试这个答案 https://stackoverflow.com/a/46424041/4830701
复制粘贴在这里以供引用

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

关于google-chrome - 保持 Chrome 在 headless 模式下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49940264/

相关文章:

javascript - 由于主线程正忙, 'wheel' 输入事件的处理延迟了 xxx 毫秒

javascript - 在 chrome 打包的应用程序中自定义标题栏

javascript - 完全迷失了如何保存扩展弹出窗口内容

google-chrome - 如何使用已解压的扩展程序启动 Chrome?

javascript - jQuery Mobile 对话框在 Chrome 中立即消失

python - 在 Linux 上使用 headless Chrome 访问拒绝页面,而有头 Chrome 通过 Python 使用 Selenium 在 Windows 上运行

chromium - 在 Jest 中使用 puppeteer 上传文件

带文件下载的 Angular ng e2e 测试用例不适用于 headless chrome

node.js - 无论我做什么,Selenium 都不会在 headless 模式下启动 chrome

google-chrome - 如何在 Windows 10 上的 Chrome 60 中使用 Headless Chrome?