Skip to content

Instantly share code, notes, and snippets.

@nhoizey
Forked from clochix/extractsession.js
Last active January 13, 2016 16:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nhoizey/7527818 to your computer and use it in GitHub Desktop.
Save nhoizey/7527818 to your computer and use it in GitHub Desktop.
A Node.js script that generates an HTML file from your Firefox open tabs. Useful when Firefox crashes upon restoration.

A Node.js script that generates an HTML file from your Firefox open tabs. Useful when Firefox crashes upon restoration.

  1. Copy the sessionstore.js file from your Firefox profile
  2. Run node ./extractsession.js > session-`date +"%Y%m%d-%H%M"`.html to generate an HTML file with a list links for every open tab

Thanks to @clochix for the initial script.

#!/usr/bin/env nodejs
//jshint node: true
require('fs').readFile('sessionstore.js', {encoding: 'utf8'}, function (err, data) {
"use strict";
var session;
if (err) {
throw err;
}
session = JSON.parse(data);
console.log('<html><head><meta charset="utf-8"><title>Restored session</title>');
console.log('<style>html { background: #fff; color: #333; }</style>');
console.log('</head><body><ul>');
session.windows.forEach(function (window) {
window.tabs.forEach(function (tab) {
var entry = tab.entries.pop();
console.log('<li><a href="' + entry.url + '">' + entry.title + '</a>');
if (entry.referrer) {
console.log(' (<a href="' + entry.referrer + '">via</a>)')
}
console.log('</li>');
});
});
console.log('</ul></body></html>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment