Skip to content

Migration: Move from localStorage to browser/chrome.storage (with sync support) #108

@prem-k-r

Description

@prem-k-r

Description

We plan to migrate MYNT from localStorage to the browser Storage API (browser.storage.local / chrome.storage.sync) for better reliability and optional cross-device sync support on Chrome.

This issue tracks the migration plan and key considerations.


Proposed changes

  • Use browser.storage.local / chrome.storage.sync instead of localStorage
  • Keep using localStorage for quotes and IndexedDB for wallpapers due to Chrome sync storage limits

Things to take care of

1. Migration of existing users’ data

  • Detect existing settings stored in localStorage
  • Migrate them to the new Storage API
  • Clear localStorage after successful migration
  • Ensure no user data loss during update

2. Chrome vs Firefox handling

  • Use chrome.storage.sync on Chrome (if available)
  • Fallback to browser/chrome.storage.local on Firefox
  • Firefox will remain local-only (no sync support)

3. Chrome storage.sync limits

  • Respect Chrome sync quotas
  • Sync only lightweight settings
  • Continue storing wallpapers and quotes locally

4. Offline support

  • Extension must work fully offline
  • storage.sync writes locally first
  • Sync happens later when the browser is online
  • Code must not assume internet availability

5. Async handling

  • chrome.storage.* APIs are asynchronous
  • UI must wait for settings before rendering
  • Avoid race conditions on startup

6. Centralized storage wrapper

Use a single wrapper everywhere in the codebase, for example:

const Storage = {
    get: (keys) => {
        if (chrome.storage?.sync) return chrome.storage.sync.get(keys);
        return chrome.storage.local.get(keys);
    },
    set: (obj) => {
        if (chrome.storage?.sync) return chrome.storage.sync.set(obj);
        return chrome.storage.local.set(obj);
    }
};

7. Initial sync timing

  • Chrome sync is not instant on fresh installs
  • Load default UI first
  • Update UI when synced settings arrive using storage.onChanged

8. Backup and restore compatibility

  • Old backups (localStorage-based) must continue to work
  • New backups should be created from the Storage API
  • Restore logic must support both formats

9. Required permission

Add to manifest.json:

"permissions": ["storage"]

10. Avoid double-saving

  • Do not save the same data in:

    • localStorage
    • chrome.storage.local
    • chrome.storage.sync
  • After migration, maintain a single source of truth

Note

AI generated description (Errors are there)

Metadata

Metadata

Assignees

Labels

refactorCode improvement without changing behavior

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions