tl;dr Firefox Nightly on Linux supports running SlimerJS headlessly. More platforms and full headless Firefox are coming soon.
Over the last couple of years, I’ve worked on a few big web projects like PDF.js and PluotSorbet where I’ve wanted a better way to run automated tests in Firefox. My usual workflow would either involve opening a test page in Firefox manually, using a homegrown automation script that would pop open Firefox and steal focus as it ran tests, or fighting with XVFB to run Firefox in the background. I missed the days of running C++ or Node unit tests directly from the command line and not having some new window open. If only Firefox supported a headless mode…
Headless Firefox had been in the back of my mind for awhile, so when January rolled around this year and my previous project was winding down, I was happy to hear I’d be working on headless Firefox. It also turns out, I wasn’t the only person who wanted a headless mode for Firefox. We heard from multiple organizations and developers that they wanted an easier way to test Firefox and there was even a feature request nine years ago with quite a bit of following. For the first phase of headless browsing we decided to target SlimerJS, since it is a simpler application based on Firefox, it comes with an API for controlling the browser, and developers are already using it for testing. Fast forward a few months, and I’m happy to announce the I’ve finished the first big milestone by getting SlimerJS to run completely headlessly with Firefox Nightly on Linux.
If you’re on Linux and want to try it out:
- Download and install Firefox Nightly.
- Get the SlimerJS source. Note: once the changes land in a stable release you can just follow the regular download instructions for SlimerJS.
Shell12git clone https://github.com/laurentj/slimerjs.gitcd slimerjs
- Modify src/application.ini to bump the version of Firefox supported.
diff1234567891011--- a/src/application.ini+++ b/src/application.ini@@ -8,7 +8,7 @@ Copyright=Copyright 2012-2017 Laurent Jouanneau & Innophi[Gecko]MinVersion=38.0.0-MaxVersion=52.*+MaxVersion=55.*[XRE]EnableExtensionManager=1
- Create a SlimerJS test script. For example snapshot.js:
- Test it out. Make sure to set the MOZ_HEADLESS environment variable and change the SLIMERJSLAUNCHER path to point to wherever you installed Firefox nightly
Shell1MOZ_HEADLESS=1 SLIMERJSLAUNCHER=/home/bdahl/nightly/dist/bin/firefox ./src/slimerjs snapshot.js
Next up, I’ll be working on getting Firefox to run headlessly without SlimerJS and instead being controlled by either WebDriver (Selenium) or maybe a devtools protocol (to be decided) and on getting headless working on MacOS and Windows. For more updates, follow along in the headless browsing meta bug and in SlimerJS’s bug.