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);
}
}
}
});
@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