Keep Chrome running in headless mode

1,808 views
Skip to first unread message

sergue...@gmail.com

unread,
May 17, 2018, 11:07:59 AM5/17/18
to headless-dev

I want to use Chrome browser in headless mode to produce images (PNG, JPEG) out of SVG graphic. 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. As I understand, if I start Chrome with following arguments:


    chromium --headless http://myserver.org


It exits together with document.onload event. But at this moment not all data fetched from the server (I using XMLHttpRequest) and therefore drawing is not complete.

I found workaround if I start chrome with debugging port enabled like:


    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. Is there possibility to let Chrome running longer with other flags?

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?


I found slightly better workaround with --remote-debugging-socket-fd=0, but it does not work on Windows. And still it is not a solution for the problem.

Eric Seckler

unread,
May 18, 2018, 6:53:18 AM5/18/18
to sergue...@gmail.com, headless-dev
You can also start headless with --remote-debugging-pipe, which should keep it alive as well. Not sure if this works under Windows though. If you want to interact with headless, you'll still need to use devtools either way, and --remote-debugging-port=X is the suggested way of doing that. Maybe you could run headless_shell in a VM or container so that you can get access to a port?

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/509691c6-de7f-4825-9bfd-3f390ea8a2cf%40chromium.org.

sergue...@gmail.com

unread,
May 18, 2018, 7:20:15 AM5/18/18
to headless-dev, sergue...@gmail.com


Am Freitag, 18. Mai 2018 12:53:18 UTC+2 schrieb Eric Seckler:
You can also start headless with --remote-debugging-pipe, which should keep it alive as well. Not sure if this works under Windows though. If you want to interact with headless, you'll still need to use devtools either way, and --remote-debugging-port=X is the suggested way of doing that. Maybe you could run headless_shell in a VM or container so that you can get access to a port?

Software, where I want to use such mode, should run on all platforms (Linux/Mac/Windows) with regular user privileges.
Especially for Windows it is not possible to enable HTTP port without admin password.

And in principle, I do not need dev tools at all - I just need that chrome runs little bit longer.
In ideal case - until window.close() called from JavaScript side.

Eric Seckler

unread,
May 18, 2018, 7:24:22 AM5/18/18
to sergue...@gmail.com, headless-dev
From what I can tell, --remote-debugging-pipe should work on windows, too. Did you try?

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.

sergue...@gmail.com

unread,
May 18, 2018, 7:31:28 AM5/18/18
to headless-dev, sergue...@gmail.com

Am Freitag, 18. Mai 2018 13:24:22 UTC+2 schrieb Eric Seckler:
From what I can tell, --remote-debugging-pipe should work on windows, too. Did you try?

No - I was not aware about this option.
Is it available in latest released version of chrome?
Is there any info about this option - which flags should I use?

Eric Seckler

unread,
May 18, 2018, 7:48:26 AM5/18/18
to sergue...@gmail.com, headless-dev
It exposes a devtools connection over pipes (#3 and #4). I'm not aware of documentation other than the code. It should have landed in M67, so available in Chrome Beta now.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
Reply all
Reply to author
Forward
0 new messages