Skip to content

[feature] Add an import export of the whole sessions. #937

Open

Description

@0wwafa

I have many open documents in dillinger.
Since they are saved in localStorage, a nice function would be to backup/restore them individually or all together.

Something like:

(function() {
    const data = JSON.stringify(localStorage, null, 2);
    const blob = new Blob([data], { type: "application/json" });
    const url = URL.createObjectURL(blob);

    const today = new Date().toISOString().split('T')[0];

    const a = document.createElement("a");
    a.href = url;

    a.download = `${window.location.hostname}-backup-${today}.json`;
    document.body.appendChild(a);
    a.click();

    // Clean up
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
})();

and

(function() {
    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.json';
    fileInput.style.display = 'none';

    fileInput.onchange = e => {
        const file = e.target.files[0];
        if (!file) return;

        const reader = new FileReader();
        reader.onload = readerEvent => {
            try {
                const content = readerEvent.target.result;
                const data = JSON.parse(content);

                localStorage.clear();

                // Restore the keys
                Object.keys(data).forEach(key => {
                    localStorage.setItem(key, data[key]);
                });

                document.location.reload(true);
            } catch (error) {
                console.error("Error parsing the backup file. Is it a valid JSON?", error);
            }
        };

        reader.readAsText(file);
    };

    document.body.appendChild(fileInput);
    fileInput.click();

    document.body.removeChild(fileInput);
})();

Activity

  1. 0wwafa commented on Jul 18, 2026

    @0wwafa
    Author

    Please, @joemccann

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions