19

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?

10

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.

| improve this answer | |
  • Excellent — thanks for adding an up-to-date, high-quality answer; that’s exactly what Stack Exchange is designed for. – Paul D. Waite Dec 22 '17 at 10:00
  • 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 at 22:30
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 &
| improve this answer | |
7

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.

| improve this answer | |
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.

| improve this answer | |
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.
| improve this answer | |
  • I think you mean 'xvfb-run -a ...' and not xvfb, right? – Kutzi Jan 18 '19 at 12:49
  • Thanks :-) Maybe it changed in the meantime? – flob Jan 22 '19 at 9:23

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.