Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Last active March 29, 2019 22:36
Show Gist options
  • Save jscher2000/07f94249b0a5f6d565fb20d88b73bb91 to your computer and use it in GitHub Desktop.
Save jscher2000/07f94249b0a5f6d565fb20d88b73bb91 to your computer and use it in GitHub Desktop.
Browser Console code snippet to Decompress Firefox 56 jsonlz4 Session History file
/*
FOR FIREFOX 66+, USE THE FOLLOWING SCRIPT INSTEAD:
https://gist.github.com/jscher2000/4403507e33df0918289619edb83f8193
NOTE: BEFORE RUNNING THIS SCRIPT, CHECK THIS SETTING:
Type or paste about:config into the address bar and press Enter
Click the button promising to be careful
In the search box type devt and pause while Firefox filters the list
If devtools.chrome.enabled is false, double-click it to toggle to true
Paste this entire script into the command line at the bottom of the Browser Console (Windows: Ctrl+Shift+j)
Then press Enter to run the script. A file picker should promptly open.
See: http://forums.mozillazine.org/viewtopic.php?p=14111285#p14111285
*/
var {utils:Cu} = Components;
function decompressBookmarksFile(oFilePath,nFilePath){
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
return Task.spawn(function* () {
var jsonString = yield OS.File.read(oFilePath,{compression:"lz4"});
yield OS.File.writeAtomic(nFilePath, jsonString);})
}
// Set up file chooser
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
var fu = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils
fp.init(window, "Open File", Components.interfaces.nsIFilePicker.modeOpen);
fp.appendFilter("Session History Files", "*.jsonlz4*");
fp.displayDirectory = fu.File(OS.Path.join(OS.Constants.Path.profileDir, "\sessionstore-backups"));
// Call file chooser
fp.open((aResult) => {
if (aResult == Components.interfaces.nsIFilePicker.returnOK) {
if (fp.file.exists() && fp.file.isFile() && fp.file.isReadable()) {
var oldfile = fp.file.path;
// Construct output file name
var newfile = oldfile + "_converted.json";
try {
decompressBookmarksFile(oldfile, newfile);
console.log("Saved as: \"" + newfile + "\"");
if(confirm("Open JSON file in a Firefox tab?")){
var uri="file:///"+newfile.replace(/\\/g, "/");
window.open(uri, "_blank");
}
}
catch (err) {
console.log(err);
}
}
}
});
@Aterfax
Copy link

Aterfax commented Aug 15, 2017

Script errors out in Nightly 57 with:

fp.show is not a function.

In order to effect a recovery I used the other script which requests a file path found here:

http://forums.mozillazine.org/viewtopic.php?p=14111285#p14111285

I was also using tab groups which meant that I needed to pass the recovery.json back to a firefox prior to Nightly with Tab Groups installed in order to get my tabs and tab groups back.

Nightly 57 upgraded the file into the jsonlz4 but was opening the none primary tab group tabs in the background which I was unable to switch to.

This involved deleting the existing session store at the profile top level to force Firefox ESR to open the recovery.json I had renamed to recovery.js .

In future versions of Firefox tab groups will cease working. The best method I have found for transfering tabs is to bookmark all tabs for each tab group. You can then reload these in the later version of Firefox.

@jscher2000
Copy link
Author

Hi Aterfax, thanks for the report. I updated from the show() method to the open() method. (Which sounds trivial but I had a hard time finding a working example of how to declare the callback.)

@jscher2000
Copy link
Author

I created a webapp that is simpler to use:

@SGC-Alf
Copy link

SGC-Alf commented Nov 15, 2017

Just saying thanks for the webapp. Saved my hide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment