# Unable to sync simple-storage for addon

**URL:** <https://discourse.mozilla.org/t/unable-to-sync-simple-storage-for-addon/8333>\
**Category:** Development\
**Created:** [April 26, 2016, 11:33am UTC](https://discourse.mozilla.org/t/unable-to-sync-simple-storage-for-addon/8333 "2016-04-26T11:33:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon31560143](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@anon31560143](https://discourse.mozilla.org/u/anon31560143)\
**Post date:** [April 26, 2016, 11:33am UTC](https://discourse.mozilla.org/t/unable-to-sync-simple-storage-for-addon/8333/1 "2016-04-26T11:33:54Z")

</div>

I would like to make addon settings and other stored user data syncable.  
Tried the following:

1. Define a syncable pref:  
const  
addonid = require(‘sdk/self’).id,  
simprefs = require(‘sdk/simple-prefs’),  
simstore = require(‘sdk/simple-storage’),  
service = require(‘sdk/preferences/service’),  
store = simstore.storage  
;  
**service.set(‘services.sync.prefs.sync.extensions.’ + addonid + ‘.syncy’, true);**
2. Reflect changes of the storage to this pref:  
**simprefs.prefs[“syncy”] = JSON.stringify(store);**
3. Listen to changes on this pref for updating the storage:  
**simprefs.on(‘syncy’, function() {**  
**store = JSON.parse(simprefs.prefs[“syncy”]);**  
**});**

On **about:config** it looks fine:  
**services.sync.prefs.sync.extensions.test@myName.org.syncy;true**  
**extensions.test@myName.org.syncy;{…}**

But still syncing doesn’t work.  
Also, when I open either a new temporary Firefox profile from the console with **jpm run -b /usr/bin/firefox** or another existing profile with **firefox -P mySecondProfileName** I get the following incomprehensible message in the console:

> 1461668786772 addons.xpi WARN Exception running bootstrap method startup on {fe272bd1-5f76-4ea4-8501-a05d35d823fc}: ReferenceError: invalid assignment left-hand side (resource://gre/modules/addons/XPIProvider.jsm → jar:file:///home/mcl/.mozilla/firefox/c9wvycuh.syncy/extensions/%7Bfe272bd1-5f76-4ea4-8501-a05d35d823fc%7D.xpi!/bootstrap.js → jar:file:///home/mcl/.mozilla/firefox/c9wvycuh.syncy/extensions/%7Bfe272bd1-5f76-4ea4-8501-a05d35d823fc%7D.xpi!/lib/ui.js:407:5) JS Stack trace: require@bootstrap.js:141:4 \< @main.js:19:1 \< require@bootstrap.js:141:4 \< startup@bootstrap.js:28:2 \< this.XPIProvider.callBootstrapMethod@XPIProvider.jsm:4658:9 \< this.XPIProvider.startup@XPIProvider.jsm:2728:13 \< callProvider@AddonManager.jsm:227:12 \< \_startProvider@AddonManager.jsm:833:5 \< AddonManagerInternal.startup@AddonManager.jsm:1016:9 \< this.AddonManagerPrivate.startup@AddonManager.jsm:2782:5 \< amManager.prototype.observe@addonManager.js:58:7

Thanks a lot for any help

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [April 26, 2016, 4:06pm UTC](https://discourse.mozilla.org/t/unable-to-sync-simple-storage-for-addon/8333/2 "2016-04-26T16:06:22Z")

</div>

> [@anon31560143](#):
>
> `/lib/ui.js:407:5`

This is where the error happens. So in your ui.js file on line 407, in the 5th column. It seems you are assigning something that’s not yet defined or similar.

I can’t help you for your main problem, your setup seems correct.

> [@anon31560143](#):
>
> But still syncing doesn’t work.

Does the pref not get synced or do the changes not get through to your code (don’t appear in your simple-storage or aren’t in the pref value you get)?

---

<div class="post-metadata">

**Author:** ![anon31560143](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@anon31560143](https://discourse.mozilla.org/u/anon31560143)\
**Post date:** [April 27, 2016, 11:33am UTC](https://discourse.mozilla.org/t/unable-to-sync-simple-storage-for-addon/8333/3 "2016-04-27T11:33:30Z")

</div>

Sorry, I think this warning in the console is related to a different addon (there is no ui.js in my test xpi).

Concerning the **syncing** :  
Here is the **main.js** of my test addon:

> (_function_() {

> ```
> const
> addonid = require('sdk/self').id,
> simprefs = require('sdk/simple-prefs'),
> simstore = require('sdk/simple-storage'),
> service = require('sdk/preferences/service'),
> store = simstore.storage
> ;
> 
> ```

> ```
> **store.color** = store.color || '#ff0000';
> 
> ```

> ```
> if (simprefs.prefs["syncy"]) {
> **store.color = simprefs.prefs["syncy"];**
> simprefs.prefs["3"] = store.color;
> }
> 
> ```

> ```
> **service.set** ('services.sync.prefs.sync.extensions.' + addonid + '.syncy', true);
> 
> ```

> ```
> simprefs.on('syncy', function() {
> **store.color = simprefs.prefs["syncy"];**
> simprefs.prefs["3"] = store.color;
> });
> 
> ```

> ```
> simprefs.on('1', function() {
> **store.color = simprefs.prefs["1"];**
> **simprefs.prefs["syncy"] = store.color;**
> });
> 
> ```
> 
> })();

In **package.json** :

> ```
> "preferences": [ 
> { 
> "title": "Color 1", 
> "type": "color", 
> "value": "#000000", 
> "name": "1" 
> }, { 
> "title": "Color 3", 
> "type": "color", 
> "value": "#ffffff", 
> "name": "3"
> } 
> ]
> 
> ```

**Expected behavior:**  
When I change color 1 of simple-prefs (via Addon-Manager) this color is stored with simple-storage and also reflected to the synced pref (“syncy”).  
When I open a window of a different Firefox profile (which is synced) then the storage should be overwritten with this synced pref and in addition (to make this overwriting visible) be reflected to pref “3”. Also the syncing of pref “syncy” should show up on _about:config_.

**De facto behavior:**  
When in a FF window of profile A I change color “1” then pref “syncy” will be updated (as expected), color “3” will be updated (as expected) but when I shutdown the window of profile A and open a window of profile B (which is synced with A) this profile does not reflect (= sync) pref “syncy” (on _about:config_ this pref does not reflect the value of profile A).
