Today, my Firefox browser decided to freeze on startup while loading the pre-existing tabs. After killing it and restarting several times, I realized that the only way to recover was to prevent Firefox from loading the tabs. I located Firefox’s “sessionstore.js” file and moved it (one could also rename it). I started Firefox and it came up fine.
To find the “sessionstore.js” file on Windows 7, open up a “Command Prompt” and type the following:
cd <random_alphanumeric>.default
The macro %APPDATA% will translate to “C:\Users\your_username\AppData\Roaming”.
Windows XP and Mac OS X will have the “sessionstore.js” file in a different location.
I had about 25 tabs opened in the previous session and I did not want to lose those tabs. The tab URLs were stored in the “sessionstore.js” file but the file was big (it contained the open tab URLs and historical URLs) and hard to parse (it was a single huge JSON text string).
I decided to write a PHP script to convert the JSON string into an HTML file with a list of all the URL as links. Below is the PHP script I wrote. Just run it using the command line PHP executable, provide the “sessionstore.js” file location as the input, and it will create a “sessionstore.js.html” file (in the current directory), which you can then open in a browser to see the list of links.
{
// Make sure we have the correct number of args
$args = $_SERVER['argv'];
if (2 != $_SERVER['argc']) {
echo "Format: $args[0] <filename>\n";
exit(-1);
}
$filename = $args[1];
// Read the input file into a json string
$jsonStore = file_get_contents($filename) or die("Failed to open input file");
// Convert the json string into an object
$store = json_decode($jsonStore);
// Create an output .html file
$file = fopen("$filename.html", "w") or die("Failed to create output file");
// Add HTML header
fwrite($file, "<html><body><ul>\n");
// Parse the session store object and generate HTML links for each tab.
// Session stores have windows->tabs->entries array-of-arrays structure.
$windows = $store->windows;
foreach ($windows as $window) {
$tabs = $window->tabs;
foreach ($tabs as $tab) {
$entries = $tab->entries;
foreach ($entries as $entry) {
fwrite($file, "<li><a href="$entry->url">$entry->title</a>\n");
}
}
}
// Add HTML footer
fwrite($file, "</ul></body></html>\n");
// Close the output file
fclose($file);
}
If you find that the “sessionstore.js” does not contain your open tabs, use the “sessionstore.bak” backup file instead. I hope that the script above may prove useful for you. Good luck with your Firefox blues.
Hi,
I recently lost my Firefox profile due to a stupid mistake. I was able to recover a couple of sessionstore files using Recuva, but the tabs aren’t loading in FF when I replace the existing sessionstore.js with any of the recovered SS files. I’m pretty desperate now. I was wondering if you would be able to run your script for me if I send you a link to download my SS files, and email the html files back to me? Command line PHP stuff is above my knowledge of computers.
Thanks,
Justin
Justin, sorry, this reply comes too late.
For others who might wish to put the PHP script above on their web server, please see my recent post, File Upload With PHP, for instructions on creating a file upload web page that could consume the “sessionstore.js” file.
root@local:/home/# php chanhvuongisawizard.php sessionstore.js
PHP Notice: Trying to get property of non-object in /home/tux/chanhvuongisawizard.php on line 26
PHP Warning: Invalid argument supplied for foreach() in /home/tux/chanhvuongisawizard.php on line 27
root@local:/home/#
$windows=$store->windows;
foreach ($windows as $window) {
Hi,
Thanks for letting me know about the error. The error indicates that the “windows” property is missing from “$store” which is the object created from the json “sessionstore.js” file.
I installed the latest Firefox 43.0.3, opened up some browser tabs, quit Firefox and looked at the resulting “sessionstore.js” file. It does contain a root “windows” element and the PHP code did successfully convert the file.
It may be that the “sessionstore.js” file you are using does not contain any opened tabs (aka “windows”) which results in the error. (My bad, I should have added a check for this corner case.)
I suggest viewing the contents of “sessionstore.js” to see whether the root “windows” element is present or not. That should hopefully help to pinpoint the issue.
Happy New Years!
Chanh
Thanks. It might take me a minute to get to, however I definitely appreciate the reply.