0

I am trying to take a screenshot using Firefox's command line interface. I made sure that the new profile has a name that is unique from all other existing profiles. The last command runs, but never terminates and doesn't produce a screenshot.

$ firefox --version
> Mozilla Firefox 66.0.3
$ firefox -CreateProfile unique-profile-name
> *** You are running in headless mode.
$ firefox -P unique-profile-name -headless --screenshot https://developer.mozilla.com/en-US/
> *** You are running in headless mode.

How can I use the command line interface and firefox to create a screenshot of a page?

I got the "take screenshot" command from https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode.

I have tried specifying the window size too with --window-size=800,1000 and making sure the URL does not redirect.

2
  • tl;dr there should be double before screenshot option. Also add the image file name after the screenshot option.
    – Biswapriyo
    Aug 25, 2019 at 20:55
  • @Biswapriyo Sorry that first one is only typo. Add a filename still does not work (--screenshot test.jpg https://developer.mozilla.com/en-US/).
    – wdkmaaeo
    Aug 25, 2019 at 22:03

1 Answer 1

1

There seems to be a cert error with the given url, the cert is invalid for the requested domain, this is probably the reason why firefox screenshot won't work in this example. Try either:

  • Accept the cert as an exception in firefox and rerun headless firefox (it shouldn't hang anymore). If commandline is a must, this might help.

OR

  • If firefox is not essential, try chromium with --ignore-certificate-errors:

chromium --headless --screenshot=output.jpg --ignore-certificate-errors https://developer.mozilla.com/en-US

PS: -headless is implied when using firefox --screenshot

3
  • The cert error did not appear when I made the post. Trying with a url that does not give a cert error (for example, http://example.com/) does not work. It is essential that Firefox is used.
    – wdkmaaeo
    Aug 27, 2019 at 15:20
  • That's weird, that is what caused my hangup with firefox headless. Otherwise your commands work without need for modification. Does the command finish when not visiting an HTTPS site? Do you have rights to write to the working directory?
    – tuxmedo
    Aug 27, 2019 at 16:15
  • I tested some more and some URLs work, but most dont. I've tested HTTP/HTTPS, subdomain/not subdomain, 3XX redirects/no redirects. I can visit all of them no problem with the Firefox GUI. There doesn't seem to be any rhyme or reason to which ones will work. I've also cleared the cache.
    – wdkmaaeo
    Aug 29, 2019 at 0:43

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.