Posted on December 17, 2014 · Posted in Misc

How to Restore Previous Session (Tabs) in Firefox

In this article we’ll consider how to restore the previous session with open tabs in Mozilla Firefox. The problem of loosing all tabs as a result of Mozilla Firefox crash (due to different reasons: from power outages to running out of available memory and system hang) occurs quite often.

The mechanism of automatic Session Restore appeared in the second version of the browser already.  Firefox saves all open windows and tabs, including urls of pages, the size and position of a window/tab and information entered into the text fields, into a special file (sessionstore.js). When the session has been completed incorrectly, Firefox tries to automatically restore the previous session based on the data in this file with all windows and tabs that had been opened before the browser failed. If the browser fails in the second time, the window with the following message appears after you start Firefox for the next time:

Well, this is embarrassing.

Firefox is having trouble recovering your windows and tabs. This is usually caused by a recently opened web page.

You can try:

  • Removing one or more tabs that you think may be causing the problem
  • Starting an entirely new browsing session

Restore the Previous Session (Tabs) in Firefox

Firefox can restore all windows and tabs open at the last exit or unexpected failure of Firefox. If you check the tabs opened earlier that have to be restored and click «Restore» button, Firefox opens these web-pages.

If the Session Restore window doesn’t appear automatically, you can try to call it by clicking History -> Restore Previous Session.

Note. This window can also be called by entering about:sessionrestore in the address bar of the browser.

Mozilla Firefox - Restore Previous Session

If Restore Previous Session menu is not active (as in the snapshot), something has gone wrong and you’ll have to use advanced means to restore the tabs.

Firstly, let’s talk about the backup mechanism of open tabs and windows in Firefox. Firefox saves the information about the current session in sessionstore.js, which is located in the user profile folder (C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\xxx.default – in Windows 7 and 8, or c:\Documents and Settings\username\Application Data\Mozilla\Firefox\xxx.default in XP). If you track how its size is changed in process of working in Firefox, you can notice that when opening a new tab/window its size grows, and when closing a tab/window, it reduces.

After its failure, Firefox automatically tries to load the information about open tabs and windows from sessionstore.js. If this file is damaged, unavailable, has wrong format or browser doesn’t see it on some reason, Firefox starts a new clean session, and Restore Previous Session menu becomes inactive. However, there is no reason to give up — there are some other ways to restore the list of previously opened tabs.

The matter is that sessionstore.bak that contains information about the previous Firefox session is stored in the same profile directory. This file is a copy of sessionstore.js, which is automatically created if Firefox has failed in the previous time.

Important. Before going to the manual method of recovery, back up your files sessionstore.js and sessionstore.bak by copying them to any directory.

Close Firefox and rename sessionstore.bak into sessionstore.js (with replacement), then try to run Firefox again. Look, if the previous session restore has been successful.

Tip. This directory also can find sessionstore-1.js, sessionstore-2.js, etc.. These are the earlier copies of open sessions. Look at the date when these files have been created. If the session recovery on this date suits you, try to rename sessionstore-1.js into sessionstore.js and run Firefox.

If this means hasn’t helped, you can try to get a URL list from sessionstore.js files. The file format is quite specific. You can analyze file contents manually and find all open pages that are contained in the constructions starting from «url»:»http, but it’s quite hard and time consuming.

sessionstore.js file format

Let’s try to automate extraction of urls from this file:

  • First of all, you need to install Firefox extension for developers Firebug (Firefox -> Add-ons – > Get Add-ons -> Firebug – > Install).
  • Then find the previously copied file sessionstore.js and rename it into sessionstore.txt.
  • Open this file in the browser (Firefox->New tab ->Open file, specify the path to the txt file).
  • Run Firebug console (Firefox->Web Development->Firebug-> Open Firebug)
  • In the bottom of the window there is a console prompt (it is marked with the red rectangle on the screenshot). Copy the next js-code into it: javascript:(function(){var D=document,H,i=j=0,P=D.getElementsByTagName('PRE'),t='',R=/[^:]\{"entries":\[\{("url":"([^"]*)")\,("title":"([^"]*)"){0,1}/g,T,U;for(j=0;E=P[j];j++){H=E.innerHTML;while(R.exec(H)){U=RegExp.$2;T=RegExp.$4;if(T.length==0){T=U;}t+='<b>['+(++i)+']</b> <a href='+U+'>'+T+' ('+U+')<\/a><br>';}}with({write(t);close()}})(); And press Enter.Firebug console prompt
  • After that a new tab appears that contains all the links the script has been able to extract from the session restore file.
  • Open the links you need.

Related Articles