How can I run Firefox on Linux headlessly (i.e. without requiring libgtk-x11-2.0.so.0)?
Solution 1
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.
Solution 2
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 &
Solution 3
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.
Solution 4
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.
Solution 5
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.
Related videos on Youtube
Paul D. Waite
Updated on September 17, 2022Comments
-
Paul D. Waite over 1 year
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?
-
Paul D. Waite about 13 yearsExcellent, cheers Gilles, that’s done it. I also found these articles helpful for getting Xvfb running: alittlemadness.com/2008/03/05/running-selenium-headless, and blog.kabisa.nl/2010/05/24/…
-
Kutzi over 5 yearsI think you mean 'xvfb-run -a ...' and not xvfb, right?
-
flob over 5 yearsThanks :-) Maybe it changed in the meantime?
-
DGoiko almost 4 yearsPlease, note that on first releases, Firefox headless mode still neded GTK3 installed. This problem is solved by now, as far as I know.