21

I’ve got Dreamhost shared hosting, and I’m trying to run Firefox 3.0 on it headlessly for use with Selenium.

When I try to run it (~/local/bin/firefox/firefox), I get the following error message:

error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory

How can I run Firefox on Linux without requiring this shared object file?

5 Answers 5

15

You can't run Firefox without all the Gtk libraries it requires, but that's easily solved by installing the libraries. Normally you would install Firefox through a package management system and this would pull in all the required libraries.

To run Firefox normally, you need an X server (that's the part that displays the windows and their contents, as opposed to things like Gtk which are libraries that the applicattion uses to build the content). That's something you wouldn't usually run on a server. There are a very few things you can do in Firefox without an X server, I don't know if Selenium is one of them.

To run Firefox on your server, run a “virtual” X server. A simple one is Xvfb (virtual framebuffer X server). It's in the X.org server distribution. Sample usage:

Xvfb :19 -screen 0 1024x768x16 &
export DISPLAY=:19
firefox &
1
12

I know this is a rather old question, but I wanted to add a more recent answer as I got directed here by Google and had to search for a while to find the answer.

As of Firefox 57, you can run in headless mode simply by installing Firefox and running:

firefox -headless http://test.com/

See the Firefox dev docs here.

1
  • 1
    Please, note that on first releases, Firefox headless mode still neded GTK3 installed. This problem is solved by now, as far as I know.
    – DGoiko
    May 20, 2020 at 22:30
9

You can't; it is linked with the X and Gtk+ client libraries, and I don't think it's even possible to build it without them.

Even in the Firefox headless version, GTK+ is still needed.

1
  • As of 2022-11, libgtk-3 is still required in Ubuntu 22.04 Server. That is, after apt install libgtk-3-dev; firefox --headless start to work. Nov 22, 2022 at 23:49
2

Since Selenium is a GUI testing tool, I would find it hard to believe that it can work without X.

So my best guess is that your headless server requires an X installation such as that suggested by Gilles. There are a number of similar alternatives.

2

You can

  • use a Firefox in a virtual framebuffer: xvfb-run -a firefox
  • use SlimerJS (a embedded Gecko/rendering engine from Firefox) with xcfb,
  • use PhantomJS as embedded WebKit without the need for a display and selenium support via GhostDriver - if WebKit is OK for you.
2
  • I think you mean 'xvfb-run -a ...' and not xvfb, right?
    – Kutzi
    Jan 18, 2019 at 12:49
  • Thanks :-) Maybe it changed in the meantime?
    – flob
    Jan 22, 2019 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .