I'm using Amazon Linux. I want to run a headless chromium browser to use on my node.js Selnium tests. So I fire up my Xvfb server like so ...

if ! pidof /usr/bin/Xvfb; then Xvfb :0 -screen 5 1024x768x8 & fi

However, when I try and take a screenshot after my tests have failed,

DISPLAY=:0 import -window root /tmp/screenshot.png

I get the error mentioned below...

+ import -window root /tmp/screenshot.png
import: unable to open X server `:0' @ error/import.c/ImportImageCommand/369.

How do I take a screenshot of Xvfb buffer?

  • 2
    Your example works fine here (debian 9). You can try xwd and xwud instead of image, works here, too. Maybe check again whether Xvfb is still running, and running on :0?
    – mviereck
    May 15, 2017 at 23:48
  • Do you hvea an example of what you're talking about -- e.g. using another tool besides imagemagick?
    – Dave
    May 16, 2017 at 13:42
  • 3
    it is similar to your example. xwd -display :0 -root -out /tmp/pic takes a snapshot, and xwud -in /tmp/pic shows it.
    – mviereck
    May 16, 2017 at 15:02
  • Wrks on RHEL/CentOS 7 too. @mviereck you must write an answer. Apr 19, 2019 at 11:50
  • I see an error says unable to open X server, it should be a problem that the X server itself is not reachable Apr 23, 2019 at 11:21

1 Answer 1


I tried something similar (on another distribution and to take a screenshot of an xterm window, but this should not be much different) I had to use display :1 as display :0 is already used :

$ Xvfb :1 -screen 5 1024x768x8 &
[1] 23728
$ pidof /usr/bin/Xvfb
$ DISPLAY=:1 xterm 2>/dev/null &
[2] 23767
$ DISPLAY=:1 xwd -root -silent | convert xwd:- png:/tmp/screenshot.png

And I have a "/tmp/screenshot.png" file with the expected xterm window on a black background. You can also use

xwd -display :1 -root -silent | convert xwd:- png:/tmp/screenshot.png
  • 2
    Debian/Ubuntu: To install xwd and convert, run: apt-get install x11-apps imagemagick
    – kenorb
    Jun 22, 2021 at 23:45

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.