简体   繁体   English

让Chrome以无头模式运行

[英]Keep Chrome running in headless mode

I want to use Chrome browser in headless mode to produce images (PNG, JPEG) out of SVG graphic. 我想在无头模式下使用Chrome浏览器从SVG图形中生成图像(PNG,JPEG)。 Code works in normal interactive mode, but I have problems to use it in headless mode. 代码在普通交互模式下工作,但我在无头模式下使用它有问题。

My main problem is that headless Chrome exits before drawing of HTML page is completed. 我的主要问题是在完成HTML页面绘制之前无头Chrome退出。 As I understand, if I start Chrome with following arguments: 据我了解,如果我使用以下参数启动Chrome:

chromium --headless http://myserver.org

It exits together with document.onload event. 它与document.onload事件一起退出。 But at this moment not all data fetched from the server (I using XMLHttpRequest) and therefore drawing is not complete. 但此时并非从服务器(我使用XMLHttpRequest)获取的所有数据都因此并未完成。

I found workaround if I start chrome with debugging port enabled like: 如果我启动chrome启用调试端口,我找到了解决方法,如:

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

But this is not that I want, especially when I do not have privileges to open http ports on the node. 但这不是我想要的,特别是当我没有权限在节点上打开http端口时。 Is there possibility to let Chrome running longer with other flags? 是否有可能让Chrome与其他旗帜一起运行更长时间? I check a lot of them , but did not found appropriate one. 我检查了很多 ,但没找到合适的。 Or is there any other methods to postpone exit of the headless Chrome? 或者还有其他方法可以推迟无头Chrome的退出吗?

You could try this answer https://stackoverflow.com/a/46424041/4830701 您可以尝试这个答案https://stackoverflow.com/a/46424041/4830701

Copy pasted here for reference 复制粘贴在此处以供参考

Use the binary /opt/google/chrome/chrome directly not google-chrome which points to bash script /usr/bin/google-chrome. 直接使用二进制/ opt / google / chrome / chrome而不是指向bash脚本/ usr / bin / google-chrome的google-chrome。

Taken from comments in 摘自评论

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以无头模式运行 Chrome - running Chrome in headless mode Chrome 在没有无头模式的情况下无法运行(Ubuntu 18.04) - Chrome not running without headless mode (Ubuntu 18.04) 检测从JavaScript无头模式运行的Chrome - Detect Chrome running in headless mode from JavaScript 关于运行Google Chrome 59无头模式的警告 - Warning on running Google Chrome 59 headless mode 在VSTS托管代理上以Chrome(无头模式)运行Selenium测试 - Running Selenium Tests in Chrome (Headless mode) on a VSTS Hosted Agent Chrome 在 Selenium Python 中运行无头模式时卡在移动版本中 - Chrome is stuck in mobile version while running headless mode in Selenium Python 在Chrome中运行无头模式时,将文件下载到路径 - Download a file to a path when running headless mode in Chrome Chrome和Firefox始终通过Gitlab-runner以无头模式运行 - Chrome and Firefox running ALWAYS in headless mode through Gitlab-runner 在Ubuntu上运行无头Chrome - Running headless chrome on Ubuntu 在无头模式下运行 Chrome 如何影响我的 selenium 测试与正常模式? - How can running Chrome in headless mode affect my selenium testing vs normal mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM