14

I would like to make a batch script for Firefox that restores my last session upon launching the script from a shortcut. I found that I could do this rather easily in Chrome with the --restore-last-session argument. I made this script and placed it along-side chrome.exe:

chrome.exe --restore-last-session

Can the same be done with Firefox? I am aware of the built-in options within the Firefox menu, but I would like to make this script so that Firefox restores instantly when I open it.

26

Your question is oddly framed.  Why do you specifically want to be able to do this from a script?  Do you just want to be able to start Firefox and restore your previous session, or do you specifically want to do this only part of the time?

Firefox has an option to restore the previous session all the time.  In “Options” / “General”, set “When Firefox starts” to “Show your windows and tabs from last time”:

Firefox “Options” / “General” page

Then just start Firefox normally, and it will restore your previous session.

  • 9
    Yes, I wanted Firefox to restore my session every time I run it. I skimmed past the option in my haste to figure this out. Thank you for your answer. – Mr. Mendelli Oct 31 '17 at 4:03
  • 5
    @Mr.Mendelli, this option is also available for Chrome. – Khalid Hussain Oct 31 '17 at 9:48
  • @G-Man for transparent positions, I flag your action and go usefully Thank you! – It Wasn't Me May 12 at 6:35
4

For more information, this is what ./firefox --help outputs on my Mac:

Usage: ./firefox [ options ... ] [URL]
       where options include:

  --g-fatal-warnings Make all warnings fatal

Firefox options
  -h or --help       Print this message.
  -v or --version    Print Firefox version.
  -P <profile>       Start with <profile>.
  --profile <path>   Start with profile at <path>.
  --migration        Start with migration wizard.
  --ProfileManager   Start with ProfileManager.
  --no-remote        Do not accept or send remote commands; implies
                     --new-instance.
  --new-instance     Open new instance, not a new window in running instance.
  --UILocale <locale> Start with <locale> resources as UI Locale.
  --safe-mode        Disables extensions and themes for this session.
  --headless         Run without a GUI.
  --marionette       Enable remote control server.
  --browser          Open a browser window.
  --new-window <url> Open <url> in a new window.
  --new-tab <url>    Open <url> in a new tab.
  --private-window <url> Open <url> in a new private window.
  --preferences      Open Preferences dialog.
  --search <term>    Search <term> with your default search engine.
  --jsconsole        Open the Browser Console.
  --jsdebugger       Open the Browser Toolbox.
  --wait-for-jsdebugger Spin event loop until JS debugger connects.
                     Enables debugging (some) application startup code paths.
                     Only has an effect when `--jsdebugger` is also supplied.
  --devtools         Open DevTools on initial load.
  --start-debugger-server [ws:][ <port> | <path> ] Start the debugger server on
                     a TCP port or Unix domain socket path. Defaults to TCP port
                     6000. Use WebSocket protocol if ws: prefix is specified.
  --recording <file> Record drawing for a given URL.
  --recording-output <file> Specify destination file for a drawing recording.
  --setDefaultBrowser Set this app as the default browser.

You can see that no option like restore-session is listed. Also, Mozilla's official document listed 7 cases when Firefox restores the session, without mentioning command line.

You may try configuring Firefox to always restore previous session in Preferences > General > When Firefox starts (select Show your windows and tabs from last time) and invoke ./firefox plainly.

  • 2
    So I guess there’s a lesson to be learned here:  If your answer starts with a screenful of boring, non-narrative text, followed by a sentence that says that the answer is “no”, because the screenful of boring, non-narrative text turned out not to reveal an answer, then people will not read the last line of your answer. – G-Man Nov 1 '17 at 19:56
4

I think the UI setting to just load your last session on start up as shown in the other answer is the best. But just in case someone absolutely needs to know how to do this with command line you can try

firefox.exe -new-tab about:sessionrestore

It's actually just a page so it can be used with the -new-tab and -new-window parameters.

  • Your script brings up the restore window as if Firefox unexpectedly stopped as you said, but shows no history options. I believe a session.js script needs to be defined (if possible) for the script to add the defined session as a valid option upon execution. Your script and parameters are good to know, I think I'll experiment with them and my theory just to see if this is possible with a batch script. – Mr. Mendelli Nov 2 '17 at 8:10

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.