Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Last active January 27, 2026 11:56
Show Gist options
  • Select an option

  • Save jscher2000/623eb8e9fb0167a139e2c089523f83c9 to your computer and use it in GitHub Desktop.

Select an option

Save jscher2000/623eb8e9fb0167a139e2c089523f83c9 to your computer and use it in GitHub Desktop.
Export Current Tab Titles/URLs to CSV - Script for Firefox's Browser Console
/* Export Current Tab Titles/URLs to CSV - 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 = JSON.parse(SessionStore.getBrowserState()); // get Current Session State
if(ssj && ssj.windows && ssj.windows.length > 0){
// Build tab list
var out = '"Win","Tab","Title","URL"\n';
var wins = ssj.windows;
for (var w=0; w<wins.length; w++){
var tabs = wins[w].tabs;
for (t=0; t<tabs.length; t++){
var tab = tabs[t].entries[tabs[t].index - 1];
out += (w+1) + ',' + (t+1) + ',"' + (tab.title ? tab.title.replace(/\"/g, "'") : "") + '","' + tab.url + '"\n';
}
}
// 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("CSV Files", "*.csv");
fp.defaultString = "sessionstore-current-tabs.csv";
// Call Save As dialog
fp.open((aResult) => {
if (aResult == Components.interfaces.nsIFilePicker.returnOK ||
aResult == Components.interfaces.nsIFilePicker.returnReplace) {
try {
IOUtils.writeUTF8(fp.file.path, out);
alert('Look for ' + fp.file.path);
} catch (err) {
alert(err);
}
} else {
alert('Okay, not saving');
}
});
} else {
alert('Could not get session data!');
}
@3top1a
Copy link

3top1a commented Jan 26, 2026

New error: Uncaught NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIFilePicker.init]

Firefox 147.0.1 (64-bit), NixOS.

As a workaround, just add console.log(out) right before // Set up Save As dialog, and copy the message output.

@jscher2000
Copy link
Author

New error: Uncaught NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIFilePicker.init]

Firefox 147.0.1 (64-bit), NixOS.

I can't replicate the error on 147.0.1/Windows, but I'll watch for more reports.

@3top1a
Copy link

3top1a commented Jan 27, 2026

Oh nevermind, it didn't work on rafal's version, works fine on the main one.

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