[英]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.