Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Last active March 18, 2024 03:08
Show Gist options
  • Save jscher2000/d7c77f90bde6f37f526faa56c6a2b19e to your computer and use it in GitHub Desktop.
Save jscher2000/d7c77f90bde6f37f526faa56c6a2b19e to your computer and use it in GitHub Desktop.
Firefox Browser Console - Save Current Session
/* Session Backup Script for the Browser Console
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 save dialog should promptly open.
*/
ssj = SessionStore.getBrowserState(); // get Current Session State
if(ssj){
// Set up Save As dialog
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
try { // Fx125+
fp.init(window.browsingContext, 'Open File', Components.interfaces.nsIFilePicker.modeSave);
} catch(e) { // Fx124 and earlier
fp.init(window, 'Open File', Components.interfaces.nsIFilePicker.modeSave);
}
fp.appendFilter("JSON Files", "*.json");
fp.defaultString = "sessionstore-snapshot.json";
// Call Save As dialog
fp.open((aResult) => {
if (aResult == Components.interfaces.nsIFilePicker.returnOK ||
aResult == Components.interfaces.nsIFilePicker.returnReplace) {
try {
IOUtils.writeUTF8(fp.file.path, ssj);
alert('Look for ' + fp.file.path);
} catch (err) {
alert(err);
}
} else {
alert('Okay, not saving');
}
});
}
@jscher2000
Copy link
Author

Had to update from OS.File.writeAtomic() to IOUtils.writeUTF8() for Firefox 104.

@1223334444abc
Copy link

1223334444abc commented Nov 24, 2022

Could not write session state file out of memory undefined
and us this:
Uncaught out of memory

@jscher2000
Copy link
Author

Sorry for the delay in picking up your comment. I can't think of a solution for "out of memory".

@1223334444abc
Copy link

The problem has been solved. I mistakenly used 32-bit Firefox. (It's really an unexpected mistake)

@1223334444abc
Copy link

No one told me that the error was caused by the memory limit of the 32-bit program. A while ago, I was stuck in Firefox crash without knowing why......

@jscher2000
Copy link
Author

Try/catch added for Firefox 125 (currently in Nightly), at lines 16-18, 20.

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