1

I need to install/uninstall my web extension (for Chrome and Firefox) frequently and I would like to have some dev settings to be persisted between installs to avoid constant re-entering the settings after each new install.

I tried to use web-extension storage API, but all saved data is deleted automatically on a web-extension uninstall. Maybe there is some other way to do this?

dajnz
  • 1,178
  • 1
  • 8
  • 20
  • There's no such API. You can [export the data to a file](https://stackoverflow.com/a/19328891) and import it later. – wOxxOm Apr 13 '20 at 13:48
  • Do the settings need to be secure? Is it OK if they are readable by another extension? – Makyen Apr 15 '20 at 05:31

1 Answers1

2

On Firefox, values stored with storage.sync are readable after you uninstall and re-install the extension. It is available even if you don't setup Firefox Sync. For example:

manifest.json:

{
  "name":"foo",
  "version":"1",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": ["storage"],
  "browser_specific_settings": {
    "gecko": {
      "id": "counter@example.com", <= this is required to keep values after reinstalling

      "strict_min_version": "68.0"
    }
  }
}

background.js:

chrome.storage.sync.get({ foo: 0 }, result => {
  console.log('count: ', result.foo); <= You will see this value is kept and increased even after you reinstall this extension.
  chrome.storage.sync.set({ foo: result.foo + 1 });
});

Sadly this doesn't work on Chrome for me with a testing local extension, even if you've configured your Google account. Chrome looks to not provide any mechanism to identify an extension across multiple time installations.

Piro
  • 244
  • 1
  • 5
  • Thank you, but I need some solution for both browsers, so it looks like I need to rethink my needs and find out something else. – dajnz Apr 14 '20 at 06:03