
Firefox 56 supports headless mode on Windows - sohkamyung
https://bugzilla.mozilla.org/show_bug.cgi?id=1355150
======
celerity
I just finished writing an article that explains how to connect WebDriver to
Firefox running in the new headless mode on Windows if anybody's interested:
[https://intoli.com/blog/running-selenium-with-headless-
firef...](https://intoli.com/blog/running-selenium-with-headless-firefox/)

It should be pretty similar on Linux, and probably macOS when it comes around.

~~~
mykmelez
Great article! I'm the product manager for the headless feature, and I'm
unsure why `binary.add_command_line_options('-headless')` doesn't work for
you, as the flag does work when invoking Firefox directly:

> "c:\Program Files\Nightly\firefox.exe" -headless

(It also works when Firefox is invoked from a Node.js script in a test suite
for a Node.js program that drives Firefox.)

Perhaps this is a Selenium issue?

~~~
celerity
Thanks! That was guess as well, since running the command you posted from cmd
does work. I dug around selenium's source code a bit, but decided to take the
pragmatic path and use the MOZ_HEADLESS environment variable instead.

------
scardine
Is there a linux headless mode already? Selenium chrome driver headless is
pretty much useless in linux because important methods like `send_keys` need X
anyway for keyboard mappings or something like that.

~~~
RJIb8RBYxzAMX9u
Genuine noob question: could you not use Xvfb?

~~~
jordache
you can, and it worked, prior to availability of headless options(Phantom
sucks). However xvfb is yet another dependency that could cause breakage.

~~~
seanp2k2
It also takes a bit longer to start up IIRC, but xvfb + chrome driver on
Jenkins definitely works for running tests.

------
robk
It's not very clear how to actually use this in a test environment like
Selenium etc. At least with headless Chrome there are libraries now to drive
it via the remote debug protocol like [https://github.com/LucianoGanga/simple-
headless-chrome](https://github.com/LucianoGanga/simple-headless-chrome)

This feels a little nicer than Selenium as it's one less layer of abstraction.

EDIT: guess from other comments WebDriver is the right method to access.

~~~
paulirish
FWIW, from the Chome side, we think there's more power via the protocol rather
than WebDriver.

~~~
jgraham
Well, yes, a low level protocol is going to have at least the same features as
a higher level protocol implemented in terms of it. However I think you should
mention the significant disadvantages of using a nonstandard API:

* Doesn't generalise to driving other browsers. Using a standardised API gives you the possibility to run your automation against any top tier browser. If you are testing a website this ought to be a top consideration.

* Uncertain compatibilty story. I assume that the devtools protocol can change at the whim of the Chrome team. Using something standardised means that your tests and client are more likely to continue working.

* More limited selection of clients. WebDriver in particular has a large number of production-grade clients that are actively maintained.

I'm not claiming that WebDriver is perfect; certainly if I designed it from
scratch it would look very different. And yes, there is a period of churn as
it moves toward being a standard. But I think the advantages of cross-browser
support are a compelling reason for it to be the default tool for remote
automation tasks that are within the scope of its featureset. By all means, if
you have something that cannot be done with a standardized technology look at
the proprietary solutions. But I don't think it should be your first pot of
call.

~~~
rodgerd
All of these look like advantages if you're building a monopoly and have a
contempt for anything that slows that down.

------
zlagen
Do you need to use selenium to control Firefox in headless mode or does it
have something lower level like Chrome's devtools protocol?

~~~
masklinn
1\. You can use the WebDriver protocol[0] without selenium

2\. Firefox's WebDriver endpoint geckodriver[1] is a layer above
Firefox/Gecko's native Marionette protocol[2]

So you doubly don't need to use selenium, you can write your own WebDriver
client (which should be cross-browser assuming the browsers either support
WebDriver natively or have a WD layer of some sort installed) or you can use
raw Marionette (either a hand-rolled client or an existing client)

[0] [https://w3c.github.io/webdriver/webdriver-
spec.html#protocol](https://w3c.github.io/webdriver/webdriver-
spec.html#protocol)

[1]
[https://github.com/mozilla/geckodriver](https://github.com/mozilla/geckodriver)

[2] [https://developer.mozilla.org/en-
US/docs/Mozilla/QA/Marionet...](https://developer.mozilla.org/en-
US/docs/Mozilla/QA/Marionette)

------
arunitc
I was wondering if I could use this (using a plugin) or Chrome to generate PDF
files on the web server. Most of the PDF generation software out there are
quite expensive.

~~~
gjjrfcbugxbhf
Latex is free.

~~~
JBorrow
Really not the same thing (e.g. pandoc for html -> pdf via LaTeX) as having a
webkit based renderer. They do not look the same at all; sometimes it is good
to have a LaTeX output but most of the time you are going to want a more
accurate representation of your HTML.

~~~
majewsky
The original question didn't state that he was starting from HTML. If you want
to generate an invoice or such from plain data, then LaTeX seems like a good
fit. Rendering HTML is a whole different bag.

------
whysohard
What are the biggest challenges when implementing headless mode? I'm asking
cause this feature took some time to be delivered both in Firefox and Chrome
and I always assumed that it should be 'pretty' straightforward to implement.
Is it that both engines were coupled with GUI libs?

~~~
bzbarsky
There are a bunch of things which are tied to native GUI libs in ways that
make headless a little annoying to implement. Some examples, from memory and
looking at the patches/dependencies in the Firefox bugs on this:

1) Theming of form controls to make them look like native widgets.

2) Clipboard.

3) Printing.

4) Fonts and font rendering.

5) General "now it's time to repaint" machinery.

This is in no way an exhaustive list. In practice what you have to do for
headless is create the relevant GUI bits anyway, but not actually show them on
screen, then deal with whatever quirks your GUI library has when its bits are
not shown.

------
jalfresi
How is it controlled when in headless mode? Still via Webdriver or does
Firefox support Chrome Debugger Protocol?

~~~
masklinn
> Still via Webdriver

WebDriver or Marionette.

------
anotheryou
So I can navigate by cardinal directions now (like scrolling south a bit)?

Joke aside: can somone explain "headless" to me here?

~~~
majewsky
When you run the browser, but it doesn't actually display anything on screen.

Uses include rendering a screenshot (e.g. a preview thumbnail) of some website
on a server, or running automated UI tests that click around a web app and
fill out forms to verify its functionality.

~~~
jshelly
Thank you for taking the time to explain. I had the same question.

------
jscholes
Anyone know if this supports audio playback?

~~~
padenot
Firefox audio developer here. I haven't heard from the folks doing this, and I
would have been the person doing the code reviews so I suppose it's left
untouched.

Edit: looking at the code, it will work just fine, and that means I can even
use it myself to run Firefox's unit and integration tests, I usually use xvfb
on Linux.

------
heisenbit
Firefox 55 introduced major changes in the process model. My scrolling on the
Mac is slow and not smooth. Others have reported the same. Maybe focusing on
stabilizing this big change over one or two releases would be a good thing?

Of course headless is also needed as the PhantomJS solution is not maintained
anymore since April. See discussion here:
[https://news.ycombinator.com/item?id=14105489](https://news.ycombinator.com/item?id=14105489)

------
eberkund
It is good to see some competition, I would hate to see automated tests being
done purely in Chrome simply because it is the simplest browser to setup in
headless mode.

------
oneplane
But can you really run windows headless? I thought even the Server Core and
IoT versions wanted some sort of GPU even just to display a blue/blank screen.

~~~
milcron
IoT Core has a headless mode. I don't think it can run Firefox though... UWP
apps only.

------
ttoinou
Does that mean we'll soon have an alternative to ElectronJS / NWJS based on
Firefox ? (Positron :p ?)

~~~
owaislone
It already exists:
[https://github.com/mozilla/positron](https://github.com/mozilla/positron)

~~~
reitanqild
Checked. Discontinued. It used to be prism or something but that was
discontinued years ago.

The sometimes really make it hard for us fanboys (prism, Brendan and
uncertainty about the future of extensions) :-|

------
tmaly
Are there some examples available for this? I would love to replace some of my
PhantomJS stuff

------
CloudQA
Great! This will help us run selenium tests much faster.

------
goferito
Please don't forget about Linux

------
pmlnr
"headless"

Poke me when there are no X11/Qt/GTK/whatever dependencies at all - that is
headless.

[https://packages.debian.org/stretch/firefox-
esr](https://packages.debian.org/stretch/firefox-esr)

~~~
swiley
This got down voted a lot but GTK is really a pretty painful dependency in
many situations (especially gtk3)

Not that Firefox itself is particularly lightweight.

~~~
megous
Why?

