Skip to content

Instantly share code, notes, and snippets.

@s-zeid
Last active April 8, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-zeid/5b0bca1284a9d3ca7c81822e0cdc05b3 to your computer and use it in GitHub Desktop.
Save s-zeid/5b0bca1284a9d3ca7c81822e0cdc05b3 to your computer and use it in GitHub Desktop.
Get sessionstore JSON for a single Firefox window (including private windows)
// Run in Browser Console (Ctrl+Shift+J; ≡ menu → Web Developer → Browser Console),
// then right click on the JSON output and click Copy object.
// Use (eg.) <https://code.s.zeid.me/bin/blob/master/sessionstore2html> to convert to HTML.
SessionStore.getWindowState(window);
// * Change the output directory at the bottom and run in Browser Console
// (Ctrl+Shift+J; ≡ menu → Web Developer → Browser Console).
// * <https://code.s.zeid.me/bin/blob/master/sessionstore2html> must be on your $PATH.
// * This function will replace `~/` at the start of the output directory with the
// path to your home directory.
// * The output filename is based on the current local time and will be of the
// format `%Y-%m-%d.%H-%M-%S.html`.
// * If the window from which you opened the Browser Console is private,
// a `private.` prefix will be added to the output filename.
await (async function(dirname) {
const { Subprocess } = ChromeUtils.import("resource://gre/modules/Subprocess.jsm");
const notWindows = AppConstants.platform != "win";
const pathSeparator = notWindows ? "/" : "\\";
const home = Subprocess.getEnvironment()[notWindows ? "HOME" : "USERPROFILE"];
if (home)
dirname = dirname.replace(/^~[\/\\]/, home + pathSeparator);
const now = new Date();
let filename = new Date(now - now.getTimezoneOffset() * 60 * 1000).toISOString();
filename = filename.substring(0, 19).replace(/T/g, ".").replace(/:/g, "-");
filename += ".html";
const prefix = document.documentElement.hasAttribute("privatebrowsingmode") ? "private" : "";
filename = (prefix ? prefix + "." : "") + filename;
const process = await Subprocess.call({
command: await Subprocess.pathSearch("sessionstore2html"),
arguments: [`--output=${dirname}/${filename}`, "-"]
});
await process.stdin.write(SessionStore.getWindowState(window));
await process.stdin.close();
return process;
})("~/path/to/tabs");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment