How to recover a prior session under Firefox v 71.0
I am trying to recover a previous session, after accidentally opening a page before restoring my old session. I had what I thought was the correct sessionstore.jsonlz4 file for the old session, judging by the file size, but apparently the new session was written into that file, and the old session moved to a section with key "lastSessionState". I could not find any information on opening that "last session", so resorted to uncompressing and editing the sessionstore file. I removed the initial section for the new session, and removed the "lastSessionState" key. The remainder of the file seemed to have the same structure as the initial session section. Not having an easy way to re-compress the file, I copied it into the profile as sessionstore.js, as, once upon a time, folks said that sessionstore.js would be read if sessionstore.jsonlz4 was not present. I hid all the files in sessionstore-backups. However, when I started Firefox, it did not find the old session. So...
Hoping someone knows: Is there a way to get Firefox to switch to the "lastSessionState" session? Or, do I need to compress the fixed up sessionstore.js in order to get Firefox to recognize it? Thanks!
(Thanks to the author of the decompression tool dejsonlz4, https://github.com/avih/dejsonlz4 ! I wonder if they would like a pull request for a "rejsonlz4"...)
All Replies (10)
Editing those .json files are super tricky when they get too much data in them. That's why I really don't like json files at all. :/
Although one of our longtime contributors, Jscher, has a tool that can read them & let's you extract the tab's urls so that you can create a new session restore file as a sessionstore.js I believe.
Check it out here: https://www.jeffersonscher.com/ffu/scrounger.html
I would like to push for Firefox making a week's worth of session restore backups tho (the same amount of backups bookmarks have) so that everyone can have a much easier time recovering from a corruption event or personal mistake like you encountered.
I'm sorry, but I did already try that. My sessionstore file, compressed, is about 9MB. (About 10 windows, over 3000 tabs...) The page didn't complete processing the file -- I had to stop it after about 10 minutes, and multiple "page isn't responding" popups. It does seem like a nice tool, though.
But in any case, it would not solve this issue. I have already edited the file and have a sessionstore.js file, which Firefox v71 did not read. (I've had to do sessionstore surgery in the past, to remove toxic pages.) The question is, how can I get the repaired sessionstore recognized? Or, is there a way for Firefox to use the lastSessionState? Seems like it must be in there for a reason...
Gewysig op
Thanks for the reporting back! I'm sorry it wasn't successful using Jscher's tool. That's one of the reasons I despise the json format so much despite that it's a very fast file format for Firefox to read & process.
I'll call in Jscher to see what he thinks here. The fact that you've already performed sessionstore surgery in the past to remove pages is amazing! I've never been able to successfully open or edit JSON session restore files. They've always either crashed/froze my text editors or been impossible to edit due to the sheer overwhelming amount of data in them. So it gives me hope that you can solve this. :)
Thank you, Noah! I should give props to Notepad++ for opening that 9MB file. I'm going to redo the sessionstore edit in Python, so my hands aren't touching it... I'm thinking it might be useful to slightly modify dejsonlz4 into rejsonlz4. That would allow re-compressing the file, to rule out compression as an issue. Maybe it would be good to look for how lastSessionState is used in the Firefox source.
For now, I copied in a profile from a few weeks ago, and copied in places and cookies from the more recent profile with the borked sessionstore. It has most of the session, and has the history of sites after that.
(Just FYA, here's the background: My 10+ year old laptop finally stopped working. I have its disk in an external enclosure. I copied in the AppData\Roaming\Mozilla folder to the new laptop before installing Firefox. It read in the profile, and the old session was working. I don't know what conversion may have been done, if the Firefox on the old laptop was the previous version. The profile folder got renamed. All was well until, in a moment of inattention, I opened a page before restoring the old session...)
You can use the builtin function to decompress a compressed .jsonlz4 file via code in the Browser Console.
async function decompressFile(oFilePath,nFilePath){ let jsonString = await OS.File.read(oFilePath, { compression: "lz4" } ); await OS.File.writeAtomic(nFilePath, jsonString ); } var fu = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils; var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); fp.init(window, "Open File", Ci.nsIFilePicker.modeOpen); fp.appendFilter(".*LZ4* Compressed Files","*.*lz4*"); fp.appendFilter(".LZ4 Compressed Files","*.lz4"); fp.displayDirectory = fu.File(OS.Path.join(OS.Constants.Path.profileDir, "")); fp.open((aResult) => { if (aResult == Ci.nsIFilePicker.returnOK) { if (fp.file.exists() && fp.file.isFile() && fp.file.isReadable()) { var oldfile = fp.file.path; var newfile = oldfile + ".json"; try { decompressFile(oldfile, newfile); console.log("Saved as: \"" + newfile + "\""); } catch (err) {console.log(err);} } } else {console.log("<canceled>");} });
Did you try to open the uncompressed edited sessionstore file in a Firefox tab to make sure that the file doesn't have errors (i.e. it is a valid JSON file) ?
If there is valid session data in the file then you should be able to restore the file without the need to edit the file.
Gewysig op
You're welcome! And I see how it happened now. You did a great save of the previous session from the other laptop. But if you're doing browsing you consider really important, manually backing up the session restore files is a must.
But there's a few addons that help automate it much better: https://addons.mozilla.org/en-US/firefox/addon/tab-session-manager/ https://addons.mozilla.org/en-US/firefox/addon/my-sessions/
Review of Tab Session Manager: https://www.ghacks.net/2019/08/16/tab-session-manager-is-an-add-on-that-saves-your-windows-and-tabs/
That's why I'm constantly backing up files important to me. In Firefox's case, I used to back up my session restore files every few days or sooner depending on how important that session was. As Windows 8 & up, stopped the helpful auto-backup feature aka "Restore Previous Versions" that they had on Windows 7. :(
Excellent work on your stopgap measure you've done for the meantime! I've sent Jscher a message explaining your situation so I hope to see him here sometime soon. :)
ptressel said
I have already edited the file and have a sessionstore.js file, which Firefox v71 did not read.
ptressel said
...I copied it into the profile as sessionstore.js, as, once upon a time, folks said that sessionstore.js would be read if sessionstore.jsonlz4 was not present. I hid all the files in sessionstore-backups. However, when I started Firefox, it did not find the old session.
I think you did the logical thing, hiding all other session history files to encourage Firefox to look for the older file name. Was "Restore Previous Session" missing from the menu or grayed out?
You might also need to hide the sessionstore-backups folder (add OLD to the name temporarily).
I wondered whether Firefox stopped looking for sessionstore.js, but the code to check for uncompressed files still seems to be in Firefox 71: https://dxr.mozilla.org/mozilla-relea.../SessionFile.jsm#319.
So that suggests the surgery might not have been fully successful.
If you try the Scrounger in Chrome, does it work any better there?
Since you are up-and-running-for-now, you might want to do your experiments in a separate profile.
New "Test" Profile
This takes about 3 minutes to set up.
Inside Firefox, type or paste about:profiles in the address bar and press Enter/Return to load it.
Click the "Create a New Profile" button, then click Next. Assign a name like Dec2019, ignore the option to relocate the profile folder, and click the Finish button.
After creating the profile, scroll down to it and click the Launch profile in new browser button.
Firefox should open a new window that looks like a brand new, uncustomized installation. (Your existing Firefox window(s) should not be affected.) Please ignore any tabs enticing you to connect to a Sync account or to activate extensions found on your system so we can get a clean test.
Close the new window for now.
On the about:profiles page, use the "Root" folder link to implant your sessionstore.js file.
Then Launch profile in new window again and see whether you can restore it.
When you are done with the experiments, you can close the extra window without affecting your regular Firefox profile. (Dec2019 will remain available for future testing.)
Note: if this test changed your default profile, use the Set as Default Profile button for your regular profile to set it back to normal.
Apologies for the delay -- I was in transit. Partial answers, in reverse order...
jscher2000 --
Excellent suggestion re. experimenting in a new profile, so I don't muck up what I have now!! I had several spare profiles, so borrowed one of them, and swapped its contents, to do the current test, but since this one is mostly working, I'd better set up a different one for monkeying with. Thanks for the warnings about Sync and extensions. I've been strenuously avoiding Sync. :D
I am fairly sure "Restore previous session" was present but grayed out.
I did run Scrounger under Chrome ;-). (Apologies for mentioning that other browser...) I haven't looked at any process memory limits yet. This laptop has 12GB memory.
cor-el and Jscher2000 --
I was just about to format-check the JSON in the edited file, so will do that next. Was also going to read in the un-edited file (w/ Python), get the value of lastSessionState, write that out as JSON, so my hand editing won't be an issue. Was then going to compare that with a fresh sessionstore to see if the format looks different.
Noah --
Thanks for those extension recommendations!! I really do need to set up backup for the profile! I kept thinking, I need to do this, but there was a shortage of Round TUITs... (https://www.google.com/search?safe=active&hl=en&tbm=isch&q=round+tuit&oq=round+tuit)
Actually, I need to set up backup, period. Don't have backup for the new laptop yet... Eeek.
Ok, answer to one of the question is, yes, it will read an uncompressed sessionstore.js. There was an extraneous character on the end of the file, probably a leftover "}". When I opened the file in Firefox, it did not object, but I renamed it to sessionstore.json, and then it did say there were characters past the legal JSON. And it kindly told me what character the error occurred at, which was one less than the file size. (Notepad++ was able to read and operate on the file, but could not render the end of the 9MB long single line -- characters were overlapped -- so it was hard to see what was on the end. And it was hard to tell where the cursor was. I'm fairly sure that I used vim before, and that the session was smaller. Not wanting to take further chances, I used cut to take off the last character. I don't have Cygwin or WSL re-installed yet, but Git Bash had cut available.)
So, I replaced the contents of a new profile with the damaged profile, took out all the session files, and put in the repaired sessionstore.js...and it recognized it and opened it. WooHoo! Now I have some 20 windows open in two browser instances. I just need to get anything important out of the temporary instance (like this page) and open those tabs in the real one.
The remaining question is... That lastSessionState thing sure looks like it's intended for recovery from D'oh! mistakes like mine. I wonder if "Re-open previous session" is on the roadmap... I wonder also if they might be willing to handle that more like bookmark backups, with multiple past versions kept...
Oh, and MANY THANKS to whoever put in that lastSessionState. Lots easier than going through 1.5 weeks of history and picking out the important ones...