Browser.storage.sync not saving properly

#1

I’ve implemented an options-page in my addon that allows to configure how the frontend behaves. Before publishing the addon on addons.mozilla.org and assigning a unique addon ID, this worked flawlessly.

Now that I’ve published the addon, saving new settings doesn’t work properly anymore, no matter if running the published addon or my development environment via web-ext. Sometimes the addon options page throws an “Type​Error: can’t access dead object” exception or after about 20 seconds some error message with “session id” is appearing.

Settings will be saved seemingly randomly after a minute or so, sometimes changes are completely lost.

I can only assume, that saving the settings via browser.storage.sync.set somehow doesn’t work anymore now that the addon is “live”. I use the following command:

return browser.storage.sync.set({
'settings': this._settings
});

this._settings is a very small JSON that only consists of a few strings, integers and arrays.

In the frontend I gain access to the settings via initally loading them with browser.storage.sync.get(‘settings’) into an object, then accessing the values within.

I use the latest Firefox Developer Edition. Happens also in non-developer editions.

Addendum:
Currently I call browser.storage.sync.set at any point when the settings change. Maybe this is the problem?
Is it better to use browser.storage.local.set and browser.storage.local.get for regular use in my addon, and only use browser.storage.sync.set and browser.storage.sync.get once in while?
E.g. only sync when the extension is updated, or every few hours, something like that.

#2

Can anyone tell me something about using browser.storage.sync? Am I using it wrongly, or is it somewhat common to run into server-lag when syncing to firefox?

(Martin Giger) #3

A couple of things:

  • You may want to cache the result from a sync.get call, since those can be fairly slow, since it fetches the data from the sync server. Afaik you have to cache yourself (but I may be wrong there).
  • I assume your sync.set promise is resolved and not rejected?
  • You are logged in with your Firefox Account and have add-on syncing enabled.