Headless mode

Starting X server in headless Linux

JxBrowser library can be used in the headless Linux environment, given the X server is running.

Here is how to start the X Server:

1. Install Xvfb server

in your headless Linux, e.g. Ubuntu Server 16.04.2 LTS:

sudo apt-get install xvfb

2. Run your Java application

By starting the standalone X server:

Xvfb :1 -screen 0 800x600x24+32 &
export DISPLAY=:1
java -jar application.jar

or using the xvfb-run command:

xvfb-run --server-args="-screen 0 800x600x24+32" java -jar application.jar

It is mandatory to specify the screen size and the color depth.

What about the “headless” flag?

Chromium 58 and higher support the --headless command line flag which works for Linux only.

The flag allows to run Chromium in Linux headless environment without starting the X server. This flag is designed for the case when you just need to run Chromium in headless environment, load some URL, and attach to the loaded web page using DevTools via the --remote-debugging-port switcher. For example:

chrome --headless --remote-debugging-port=9222 https://chromium.org

In such case you load the localhost:9222 web page in a web browser application and work with the loaded web page using DevTools.

As you can see, the --headless command line flag is designed to be used when you need to load a single web page and work with it via DevTools. We checked Chromium’s source code and figured out that this flag forces Chromium to use a separate, limited version of the Chromium API that does not support most (~80-90%) of the features used in JxBrowser.

It means that this flag disables most of the JxBrowser functionality, such as loading different web pages by URL, HTML, navigating backward and forward, executing JavaScript, etc.

This is why this flag is NOT supported by JxBrowser, and we recommend you to start the X server in order to use JxBrowser in a headless Linux environment.

Go Top