I am running a headless Ubuntu 16.04 LTS in the Google Cloud. There is an application I need to run in the background that requires a GUI. I am trying to use Xvfb to allow the program to run, but as the program requires some GUI inputs, I also need to take screenshots of the screen to see what inputs are required.

However, I am having trouble taking screenshots. To test the process of taking a screenshot, I install and run firefox navigated to google. I take a screenshot two ways, using scrot and using imagemagick. Both ways results in a black image with hints of the google homepage in it (see attached picture). The colour and details prevents the use of the screenshot to interpret what is being shown. What is causing this lack of detail and how can I fix this?

The relevant commands are below:

sudo apt-get install xvfb xorg xserver-xorg scrot imagemagick
Xvfb :1 &
export DISPLAY=:1
DISPLAY=:1 firefox https://www.google.com &
DISPLAY=:1 scrot
DISPLAY=:1 import -window root tmp_screenshot.png

enter image description here


I've had a similar issue while using xvfb-run.

According to xvfb-run(1) man page, the default resolution is 640x480x8, thus only 8 bit colors. See option [-s].

The solution was to force the color depth to 16 bits like this:

xvfb-run -s '-screen 0 1280x800x16'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.