How to Make Firefox Restore Your Session under Linux

2007-07-24 23:22:19 GMT

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!