I want to use chrome with the --headless flag on a server without an X server running to get screenshots and/or print-to-pdf of a page. Without running a display server, chrome errors out immediately because GTK can not open the display. root@FreeBSD:~ # echo $DISPLAY DISPLAY: Undefined variable. root@FreeBSD:~ # chrome --headless --disable-gpu --no-sandbox --screenshot --verbose http://example.com [81628:457269248:0510/101444.736930:ERROR:browser_main_loop.cc(284)] Gtk: cannot open display: --- When I try running it with xvfb. root@FreeBSD:~ # service dbus onestart root@FreeBSD:~ # Xvfb :0 -screen 0 1024x768x24 & root@FreeBSD:~ # setenv DISPLAY :0 root@FreeBSD:~ # chrome --version Chromium 58.0.3029.81 root at FreeBSD:~ # chrome --headless --disable-gpu --no-sandbox --screenshot --verbose http://example.com This seems to just hang (runs on the command line without any output). My guess is that chrome is droping the --headless flag and going ahead and initializing as if it were running on an actual system --- On a debian system with chromium (57.0.2987) installed from the package repository, the command seems to run without an X sever (even xvfb) running beforehand. root@debian:~# apt-get install chromium ... root@debian:~# chromium --version Chromium 57.0.2987.98 Built on 8.7, running on Debian 8.7 root@debian:~# chromium --headless --disable-gpu --screenshot --verbose http://example.com [0507/071136.814541:WARNING:audio_manager.cc(321)] Multiple instances of AudioManager detected [0507/071136.814714:WARNING:audio_manager.cc(278)] Multiple instances of AudioManager detected [0507/071137.002908:INFO:headless_shell.cc(378)] Screenshot written to file screenshot.png. The command exits without error and the screenshot.png file is in the folder where the command ran from. --- Some reference links: - https://developers.google.com/web/updates/2017/04/headless-chrome - https://chromium.googlesource.com/chromium/src/+/master/headless/README.md - https://chromium.googlesource.com/chromium/src/+/58.0.3029.81/headless/
Created attachment 182480 [details] patch - Add initial headless support The initial support has not implemented --print-to-pdf command because they are working on it. https://codereview.chromium.org/2829973002/ https://bugs.chromium.org/p/chromium/issues/detail?id=603559
FYI I only tested the screenshot feature and it works fine. % chrome --headless --disable-gpu --screenshot https://chromium.org [0510/190816.914216:INFO:headless_shell.cc(377)] Screenshot written to file screenshot.png
(In reply to Carlos J. Puga Medina from comment #2) Hi, Thanks for the patch After building and installing (make package and pkg add on another machine) With no display server running chrome still crys about no GTK root@FreeBSD:~ # chrome --headless --disable-gpu --screenshot https://chromium.org [1027:455172096:0511/033557.631033:ERROR:browser_main_loop.cc(284)] Gtk: cannot open display: --- Once Xvfb is running I ger another error, through earlier debuging I figured out this was something to do with the chrome sandbox root@FreeBSD:~ # Xvfb :0 -screen 0 1024x768x24 & [1] 1029 root@FreeBSD:~ # setenv DISPLAY :0 root@FreeBSD:~ # chrome --headless --disable-gpu --screenshot https://chromium.org [1031:455172096:0511/033608.962407:ERROR:desktop_window_tree_host_x11.cc(1147)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType) ^C --- On disabling the sandbox chrome requires dbus to be running root@FreeBSD:~ # chrome --headless --disable-gpu --no-sandbox --screenshot http://chromium.org [1133:520788224:0511/033758.184624:ERROR:bus.cc(427)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory [1133:520788224:0511/033758.185061:ERROR:bus.cc(427)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory [1133:520788224:0511/033758.185292:ERROR:bus.cc(427)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory [1133:520788224:0511/033758.185481:ERROR:bus.cc(427)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory ^C --- After starting dbus same symptoms, this still hangs here. root@FreeBSD:~ # service dbus onestart Starting dbus. root@FreeBSD:~ # chrome --headless --disable-gpu --no-sandbox --screenshot http://chromium.org ^C --- I dont know if I have done something wrong with building/packaging the patch. Does chrome --headless require a running x server and gtk, dbus?
Headless chromium doesn't require a running X server. You should build chromium from ports or use poudriere(8) to build packages from the ports tree.
Created attachment 182513 [details] patch I've realized that a patch was missing.
After applying the new patch, chromium --headless should run smoothly.
(In reply to Carlos J. Puga Medina from comment #5) Hey patched the ports tree with your patch and built, still no go. However found https://github.com/gliaskos/freebsd-chromium and built that. It seems to work. I believe the last patch to that repository was yours "Update chromium to 58.0.3029.110 and add initial headless support". That works great, would love to see it in head soon. Also with chromium 59 out soon (few weeks) id love to help test --headless with pdf support for you. Thnaks
A commit references this bug: Author: cpm Date: Fri May 12 12:45:43 UTC 2017 New revision: 440680 URL: https://svnweb.freebsd.org/changeset/ports/440680 Log: - Add initial headless support [1] - Add patch to get the host OS name for BSD - Bump PORTREVISION PR: 219188 [1] Reported by: Reshad Patuck <reshadpatuck1@gmail.com> Changes: head/www/chromium/Makefile head/www/chromium/files/patch-chrome_app_chrome__main.cc head/www/chromium/files/patch-chrome_chrome__paks.gni head/www/chromium/files/patch-headless_lib_browser_headless__content__browser__client.cc head/www/chromium/files/patch-headless_lib_browser_headless__content__browser__client.h head/www/chromium/files/patch-headless_lib_headless__content__main__delegate.cc head/www/chromium/files/patch-headless_lib_headless__content__main__delegate.h head/www/chromium/files/patch-headless_lib_headless__macros.h head/www/chromium/files/patch-remoting_host_host__details.cc
Committed! Thanks
(In reply to Carlos J. Puga Medina from comment #9) Built and tested from ports tree, --screenshot working. Waiting on v59 to test --print-to-pdf. Thanks.