Skip to content

Instantly share code, notes, and snippets.

@aviv926
Last active August 14, 2025 13:33
Show Gist options
  • Save aviv926/773209b917a0dff64c68de134c3af525 to your computer and use it in GitHub Desktop.
Save aviv926/773209b917a0dff64c68de134c3af525 to your computer and use it in GitHub Desktop.
Recover lost Firefox tabs after a system crash, SSD failure, or when your drive goes into read-only mode. This guide explains how to restore your browsing session from the recovery.baklz4 file found in your Firefox profile folder. Includes step-by-step instructions, the exact file paths you need, and references to tools for decompressing and con…

Recovering Firefox Tabs from recovery.baklz4 (Drive Failure Guide)

If your drive fails and goes into read-only mode (like my Samsung 980 Pro did), Firefox may lose the usual sessionstore.js file used for restoring tabs. However, there’s still hope — Firefox stores active tabs in different files depending on its state:

  • When Firefox is running → Tabs are saved in: profile.folder\sessionstore-backups\recovery.baklz4
  • When Firefox is not running → Tabs are saved in: profile.folder\sessionstore.js
    In my case, because the browser crashed with the drive, sessionstore.js didn’t exist. The only survivor was recovery.baklz4.

Steps to Restore Tabs

Thanks to user136036, who posted the Python code to handle .baklz4 .lz4 .mozlz4 .jsonlz4 .baklz4 files, I was able to bring my session back.

1. Uncompress recovery.baklz4

Use the provided Python code to decompress the file.

Needs lz4: pip install lz4

from sys import argv, exit
import os

try:
    import lz4.block as lz4
except ImportError:
    print("Please install lz4 via   'pip install lz4'.")


EXTENSIONS = {"1": ".lz4", "2": ".mozlz4", "3": ".jsonlz4", "4": ".baklz4"}



def check_overwrite(path):
    if os.path.exists(path):
        i = input(f"File {path} already exists. Overwrite? y/n\n")
        if i.lower() == "y":
            print("Overwriting file.")
            return True
        else:
            print("Exiting.")
            exit(1)
    else:
        return True


def print_info():
    print(f"Usage: {argv[0]} <infile>")
    print("Decompress Mozilla-LZ4 encoded <infile> or compress <infile> to Mozilla-LZ4.")
    print("Output file will be put in same folder as input file.")
    exit(1)


def choose_ext():
    print(f"Please choose file extension:")
    for k, v in EXTENSIONS.items():
        print(f"{k}: {v}")
    if (i := input()) in EXTENSIONS.keys():
        return EXTENSIONS[i]
    else:
        print("Invalid extension.\nExiting")
        exit(1)


def main():
    if len(argv) != 2:
        print_info()

    else:
        if not os.path.exists(argv[1]):
            print_info()
        else:
            in_full_name = os.path.basename(argv[1])
            in_folder_path = os.path.dirname(argv[1])
            in_name, in_ext = os.path.splitext(argv[1])  # "search.json", ".mozlz4"
            in_file_handle = open(argv[1], "rb")

            if in_ext.lower() in EXTENSIONS.values():
                ''' Decompress '''
                print(f"Trying to decompress {in_full_name}")
                out_file = os.path.join(in_folder_path, f"{in_name}")
                if check_overwrite(out_file):
                    with open(out_file, "wb") as f:
                        assert in_file_handle.read(8) == b"mozLz40\0"
                        f.write(lz4.decompress(in_file_handle.read()))

            else:
                ''' Compress '''
                print(f"Trying to compress {in_full_name}")
                ext = choose_ext()
                out_file = os.path.join(in_folder_path, f"{in_full_name}{ext}")
                if check_overwrite(out_file):
                    with open(out_file, "wb") as f:
                        f.write(b"mozLz40\0" + lz4.compress(in_file_handle.read()))


if __name__ == '__main__':
    main()

Windows user run example:

python.exe .\script.py .\recovery.baklz4
Trying to decompress recovery.baklz4
python.exe .\script.py .\recovery.json
Trying to compress recovery.json
Please choose file extension:
1: .lz4
2: .mozlz4
3: .jsonlz4 ---->>> you need this one
4: .baklz4

2. Convert&Rename to JSONLZ4 format

Change the compression format (recovery.baklz4) to match what Firefox expects (sessionstore.jsonlz4) and rename so it will be like this: recovery.jsonlz4 (Change the compression with the script)→ recovery.baklz4 → recovery.jsonlz4 (rename)→ sessionstore.jsonlz4

3. Move to the profile folder

Copy the new sessionstore.jsonlz4 into your main profile folder (same folder that normally contains prefs.js, places.sqlite, etc.).

4. Restore in Firefox

Open Firefox and click: ☰ Menu → History → Restore Previous Session.

All your tabs from the last session should now load. 🙂


Helpful References


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