Skip to content

Instantly share code, notes, and snippets.

@alexxroche
Forked from tmonjalo/list-fftabs.py
Last active August 15, 2023 10:28
Show Gist options
  • Save alexxroche/5ce6949aee8ab08d328e70a38a0ae493 to your computer and use it in GitHub Desktop.
Save alexxroche/5ce6949aee8ab08d328e70a38a0ae493 to your computer and use it in GitHub Desktop.
List all Firefox tabs with title and URL
#! /usr/bin/env python3
"""
List all Firefox tabs with title and URL
Supported input: json or jsonlz4 recovery files
Default output: title (URL)
Output format can be specified as argument
"""
import sys
import pathlib
import lz4.block
import json
path = pathlib.Path.home().joinpath('.mozilla/firefox')
files = path.glob('*default*/sessionstore-backups/recovery.js*')
try:
template = sys.argv[1]
except IndexError:
template = '%s (%s)'
for f in files:
b = f.read_bytes()
if b[:8] == b'mozLz40\0':
b = lz4.block.decompress(b[8:])
j = json.loads(b)
pages = {}
for w in j['windows']:
for t in w['tabs']:
i = t['index'] - 1
tg_id = f"{t['userContextId']}"
if tg_id in pages:
if 'title' in t['entries'][i] and 'url' in t['entries'][i]:
pages[tg_id].append(f"0: {t['entries'][i]['title']}, ({t['entries'][i]['url']})")
elif 'docIdentifier' in t['entries'][i] and 'url' in t['entries'][i]:
pages[tg_id].append(f"{t['entries'][i]['ID']}: {t['entries'][i]['docIdentifier']}, ({t['entries'][i]['url']})")
else:
if 'title' in t['entries'][i] and 'url' in t['entries'][i]:
pages[tg_id] = [f"{t['entries'][i]['ID']}: {t['entries'][i]['title']}, ({t['entries'][i]['url']})"]
elif 'docIdentifier' in t['entries'][i] and 'url' in t['entries'][i]:
pages[tg_id] = [f"0: {t['entries'][i]['docIdentifier']}, ({t['entries'][i]['url']})"]
for tg in pages:
print(f"###################\n"
f"### Tab group {tg} ###\n"
f"###################"
)
for p in pages[tg]:
print(f"{p}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment