Skip to content

Instantly share code, notes, and snippets.

@lexicalunit
Last active February 23, 2021 21:02
Show Gist options
  • Save lexicalunit/db01dbb0c1c1dc81f54cf31a825d0920 to your computer and use it in GitHub Desktop.
Save lexicalunit/db01dbb0c1c1dc81f54cf31a825d0920 to your computer and use it in GitHub Desktop.
Print out the URLs in the tabs currently in Firefox on macOS.
#!/usr/bin/env python3
import argparse
import json
import pathlib
# You'll need to install python-lz4: https://pypi.org/project/lz4/
import lz4.block
parser = argparse.ArgumentParser(description="List open urls in Firefox tabs")
args = vars(parser.parse_args())
def dump_urls(filepath: pathlib.Path):
stream = open(filepath, "rb")
stream.read(8) # skip past the b"mozLz40\0" header
compressed_bytes = stream.read()
uncompressed_bytes = lz4.block.decompress(compressed_bytes)
text = uncompressed_bytes.decode("utf-8")
data = json.loads(text)
for window in data["windows"]:
for tab in window["tabs"]:
for entry in tab["entries"]:
print(entry["url"])
if __name__ == "__main__":
home = pathlib.Path.home()
firefox = home / "Library" / "Application Support" / "Firefox"
profiles = (firefox / "Profiles").glob("*.default-release")
for profile in profiles:
recovery = profile / "sessionstore-backups" / "recovery.jsonlz4"
if recovery.exists():
dump_urls(recovery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment