How to Make Firefox Restore Your Session under Linux

When you restart your GNOME / KDE session, Firefox asks you the same boring question once again:


Seems familiar?

The reason it happens is that Firefox doesn't implement the X session protocol so every time you log out from your Linux desktop, Firefox gets mercilessly killed. I don't plan to patch Firefox to implement X session protocol, because I don't have the special knowledge and it'd took too much time for me, but I present you a pretty good hack that works really nice.

Edit {your-firefox-directory}/components/nsSessionStartup.js as follows:

Original code:

// prompt and check prefs
this._doRestore = this._lastSessionCrashed ? this._doRecoverSession() : this._doResumeSession();

Updated code:

// prompt and check prefs
var ignoreSessionCrash = this._getPref("sessionstore.ignore_session_crash", false);
this._doRestore = !ignoreSessionCrash && this._lastSessionCrashed
                      ? this._doRecoverSession()
                      : this._doResumeSession();

From now on if you want to always restore your session upon startup, you have to set the sessionstore.ignore_session_crash variable to true within the about:config page of Firefox (you have to type about:config in the address bar).

if Firefox keeps crashing due to an evil web page that is saved in your session, then you have to manually set the sessionstore.ignore_session_crash variable to false by editing the {your-home-directory}/.mozilla/firefox/{your-profile-dir}/prefs.js file as follows:

original line: user_pref("browser.sessionstore.ignore_session_crash", true);
updated line: user_pref("browser.sessionstore.ignore_session_crash", false);

Good luck hacking your Firefox until the X session protocol gets implemented in it!


  1. Marek Běl says:

    2014-11-7, Friday at 16:10

    I am experiencing same problem on Debian unstable with XFCE with Iceweasel (Firefox) 31.2.0esr-3. I think that your hack is not aplicable there as I can't locate nsSessionStartup.js nor its content. My problem was fixed by compiling Iceweasel package from its source code.

    apt-get -b source iceweasel
    sudo dpkg -i iceweasel_31.2.0esr-3_amd64.deb

    On multicore system you can speed up compilation by using more threads. E.g.:

    DEB_BUILD_OPTIONS="parallel=4" apt-get -b source iceweasel

  2. Marek Běl says:

    2014-11-7, Friday at 16:55

    This problem is found to be fixed for binary version of the Iceweasel (Firefox) package 33.0-2.

  3. Marek Běl says:

    2015-4-3, Friday at 14:38

    I was wrong, compiling from source doesn't fix anything, re-installation only resets crash counter, allowing for one successful restart. To workaround problem open about:config in browser's location bar and set preference browser.sessionstore.max_resumed_crashes to -1. This workaround could lead to Firefox always crashing after start, if saved session contains some data causing that. In such case start firefox in safe mode by -safe-mode command line parameter.

    firefox -safe-mode

Leave a Reply

Your email address will not be published.