X
Tap here to go to the mobile version of the site.

Support Forum

Headless Firefox doesn't work

Posted

I try to make Firefox' headless mode work but so far to no avail. I tested with versions 67b (Windows) and 66 (Linux).

First try: Windows 10. firefox -screenshot FILENAME URL (or several variations of this command) opens several invisible firefox processes but the shell returns immediately. The processes keep running until I kill them. No screenshot is made.

Second try: Ubuntu. The above command is answered by "You are running in headless mode" ... but that's it, no screenshot is generated. I have write access to the directory, I tried the -no-remote switch.

Any ideas what I'm doing wrong?

I try to make Firefox' headless mode work but so far to no avail. I tested with versions 67b (Windows) and 66 (Linux). First try: Windows 10. firefox -screenshot FILENAME URL (or several variations of this command) opens several invisible firefox processes but the shell returns immediately. The processes keep running until I kill them. No screenshot is made. Second try: Ubuntu. The above command is answered by "You are running in headless mode" ... but that's it, no screenshot is generated. I have write access to the directory, I tried the -no-remote switch. Any ideas what I'm doing wrong?

Chosen solution

You did delete the content of the profile folder because it is quite possible that some settings aren't compatible with headless mode? I needed a fresh profile to make Firefox close after running this command (only a limited set of files is created), so best is not to use a profile that has been used. I also needed the 'cd' command to make sure that the screenshot was saved to the correct folder. You can check places.sqlite to see whether the website is visited. If you monitor the profile folder while the command is running then you should see files getting modified.

Read this answer in context 1
Quote

Additional System Details

Application

  • User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.55 Safari/537.36 Vivaldi/2.5.1511.4

More Information

jscher2000
  • Top 10 Contributor
8430 solutions 68766 answers

Hi wortwart, I ran this and got a cursor with a circling blue arrow and then all quiet. I can't figure out where the image is, or whether it actually was saved. Processes remained in memory.

"C:\Program Files\Firefox Developer Edition\firefox.exe" -headless --screenshot test.png https://www.userchrome.org/

Since this may be an issue with the MDN documentation, could I suggest trying their forum over here:

https://discourse.mozilla.org/c/mdn

(You can log in using a Github account.)

Hi wortwart, I ran this and got a cursor with a circling blue arrow and then all quiet. I can't figure out where the image is, or whether it actually was saved. Processes remained in memory. "C:\Program Files\Firefox Developer Edition\firefox.exe" -headless --screenshot test.png https://www.userchrome''.''org/ Since this may be an issue with [https://developer.mozilla.org/docs/Mozilla/Firefox/Headless_mode the MDN documentation], could I suggest trying their forum over here: https://discourse.mozilla.org/c/mdn (You can log in using a Github account.)
Was this helpful to you? 0
Quote

Question owner

Thank you for your response! I contacted MDN: https://discourse.mozilla.org/t/issues-with-firefox-headless/38553

Thank you for your response! I contacted MDN: https://discourse.mozilla.org/t/issues-with-firefox-headless/38553
Was this helpful to you? 0
Quote
cor-el
  • Top 10 Contributor
  • Moderator
17177 solutions 155255 answers

Helpful Reply

I got it to work on Linux. I'm using a clean profile and use the Profile Manager to create a profile (test-ss) and then remove all files in this profile so that Firefox can initialize the profile for headless mode. To ensure the correct download folder is set I do a 'cd' to the default Downloads folder because the screenshot is saved to the active folder and you need write permission. I launch Firefox by specifying the full path and use the -P <profile> switch to launch Firefox with the test-ss profile. On Windows you can create a .cmd file with these commands.


cd ~/Downloads
/usr/local/mozilla/firefox-RE/firefox -screenshot test.png https://support.mozilla.org/en-US/questions/firefox -P test-ss -no-remote
I got it to work on Linux. I'm using a clean profile and use the Profile Manager to create a profile (test-ss) and then remove all files in this profile so that Firefox can initialize the profile for headless mode. To ensure the correct download folder is set I do a 'cd' to the default Downloads folder because the screenshot is saved to the active folder and you need write permission. I launch Firefox by specifying the full path and use the -P <profile> switch to launch Firefox with the test-ss profile. On Windows you can create a .cmd file with these commands. ---- <pre><nowiki>cd ~/Downloads /usr/local/mozilla/firefox-RE/firefox -screenshot test.png https://support.mozilla.org/en-US/questions/firefox -P test-ss -no-remote</nowiki></pre>

Modified by cor-el

Was this helpful to you? 1
Quote

Question owner

Thank you, cor-el! I just tried your exact syntax with the Firefox path adopted to my systems (/usr/bin/firefox on Ubuntu and "\Program Files (x86)\Mozilla Firefox\firefox.exe" on Windows 10) but the results were the same as described above. Firefox works fine otherwise on both systems.

Thank you, cor-el! I just tried your exact syntax with the Firefox path adopted to my systems (/usr/bin/firefox on Ubuntu and "\Program Files (x86)\Mozilla Firefox\firefox.exe" on Windows 10) but the results were the same as described above. Firefox works fine otherwise on both systems.

Modified by wortwart

Was this helpful to you?
Quote
cor-el
  • Top 10 Contributor
  • Moderator
17177 solutions 155255 answers

Chosen Solution

You did delete the content of the profile folder because it is quite possible that some settings aren't compatible with headless mode? I needed a fresh profile to make Firefox close after running this command (only a limited set of files is created), so best is not to use a profile that has been used. I also needed the 'cd' command to make sure that the screenshot was saved to the correct folder. You can check places.sqlite to see whether the website is visited. If you monitor the profile folder while the command is running then you should see files getting modified.

You did delete the content of the profile folder because it is quite possible that some settings aren't compatible with headless mode? I needed a fresh profile to make Firefox close after running this command (only a limited set of files is created), so best is not to use a profile that has been used. I also needed the 'cd' command to make sure that the screenshot was saved to the correct folder. You can check places.sqlite to see whether the website is visited. If you monitor the profile folder while the command is running then you should see files getting modified.
Was this helpful to you? 1
Quote

Question owner

Thank you, it finally worked! Indeed using the headless mode with a fresh profile made the difference. (I thought that "-p my-new-profile" creates a new profile if it doesn't exist but headless mode just ignored this flag.)

Thank you, it finally worked! Indeed using the headless mode with a fresh profile made the difference. (I thought that "-p my-new-profile" creates a new profile if it doesn't exist but headless mode just ignored this flag.)
Was this helpful to you?
Quote
McCoy
  • Top 10 Contributor
430 solutions 3831 answers

Hello wortwart,

Would you be so kind as to mark cor-el's post (the one that solved your problem) as Chosen Solution  ? ("Solved Problem" button to the right)

Thank you in advance  !

Hello wortwart, Would you be so kind as to mark cor-el's post (the one that solved your problem) as Chosen Solution ? ("Solved Problem" button to the right) Thank you in advance !
Was this helpful to you?
Quote

Question owner

Sure ... done!

Sure ... done!
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.