How can I restart Firefox from the command-line and restore the previous state completely (or as much as possible) after restart? Sure, I can do something like killall firefox; firefox
, but that would not restore the session.

- 609

- 18,305
5 Answers
You can set Firefox to open with the previously open windows & tabs. It should be under Preferences -> General -> "When Firefox starts". Set that to "Show my windows and tabs from last time":
You should now be able to restart firefox
with killall firefox; firefox &
and have the same session.

- 242,166
I think you need to do a setting in firefox before you restart it from command line. Go to:
Prefrences->General->When Firefox starts
and select :
Show my windows and tabs from last time
then from the command line , restart it the way you like ( may be killall firefox; firefox&
) and you ll get the desired result.
For more advance tuning about session restore you can type about:config
in address bar and search for session or restore to change it.
https://support.mozilla.org/en-US/questions/1089103#answer-794586

- 7,202
-
The 'show my windows and tabs from last time' setting has been renamed to 'open previous windows and tabs' (about:preferences#general) – user598527 Apr 27 '22 at 13:50
Unfortunately, there's no easy way to accomplish this. The closest thing to it would actually be using the Firefox Console (Shift
+ F2
) and typing in restart
.
Aside from that, one could install an Addon or take @terdon's advice in his answer and change Firefox Preferences to "Show my windows and tabs from last time" When Firefox starts and "restarting" with
$ killall firefox; sleep 1; firefox &
UPDATE: The "gcli" was removed from firefox in 2018. Therefore, the "Shift+F2" shortcut no longer works.

- 3,309
If you desire to restart Firefox with two or more profiles, this Bash script appears to work consistently:
#!/bin/bash
killall -s SIGTERM firefox; sleep 60
firefox -P "user" &
firefox -P "default settings" &
Replace the quoted profile names with your own (see about:profiles
). Use the -foreground
flag to control which windows appears on top, if desired.
As noted by the other answers, enable the 'open previous windows and tabs' setting in the preferences (about:preferences#general
)
The value in sleep 60
(seconds) can potentially be lowered.

- 609
-
At 60 seconds, I've still got the "Firefox is still running" error when the script starts Firefox after
sleep
. Ryzen 5700G, 32GB DDR4 RAM. – user598527 May 23 '22 at 21:53 -
Regarding cron, see: https://unix.stackexchange.com/questions/700698/a-basic-bash-script-to-start-a-gui-program-works-partially-in-cron – user598527 May 23 '22 at 21:59
As of 2020, edit advanced settings via about:config
, search for resume
and set the browser.sessionstore.resume_session_once
flag to true
, then exit.
Here's documentation on the flag: https://kb.mozillazine.org/Browser.sessionstore.resume_session_once

- 609

- 111