Volatil3
Volatil3

Reputation: 15016

Chrome extension asks to turn on Sync despite of using local storage

I am working on a Chrome extension that stores data in local storage. But when I install to someone else system from Chrome Play store, it asks to Turn on Sync. Below is my manifest. The interesting thing is, even if someone refuses to turn sync on, it still works.

{
  "manifest_version": 2,
  "name": "XX",
  "description": ".....",
  "version": "0.1",
  "chrome_url_overrides": {
    "newtab": "newtab.html"
  },
  "icons": {
    "16": "icon_16.png",
    "128": "icon_128.png",
    "48": "icon_48.png"
  },
  "content_scripts": [
    {
      "matches": [
        "http://*/*"
      ],
      "css": [
        "bootstrap.css"
      ],
      "js": [
        "jquery.js",
        "bootstrap.js",
        "custom.js"
      ],
      "run_at": "document_end"
    }
  ],
  "background": {
  },
  "browser_action": {
    "default_title": "..."
  },
  "permissions": [
    "tabs",
    "storage"
  ]
}

What's wrong am I doing?

Update Below is the code related to the storage

 // Fetch last timestamp
    chrome.storage.local.get('records_fetch_ts', function (date_rec) {
        old_time = date_rec['records_fetch_ts'];
        if(typeof old_time != 'undefined') {
            current_time = new Date().getTime()
            var timeinmilisec = current_time - old_time;
            days = Math.floor(timeinmilisec / (1000 * 60 * 60 * 24));
        }

    });

    chrome.storage.local.get('records', function (result) {
        records = result;
        //records = null;

        if (!$.isEmptyObject(records))
            entries = JSON.parse(result['records'])

            // Preparation of Random result
            if (entries.length > 0)
                itemsLength = entries.length;

            if (itemsLength > 0)
                random_number = Math.floor((Math.random() * itemsLength) + 1);

            single_item = entries[random_number];
            console.log(single_item);

            if (single_item != null)
                $('#asin').html(single_item['asin'])
            updateUI(single_item)
            console.log(days)
        //if (records == null && days > 10) {
        if ((days < 0 || days > 10) || records == null) {
            console.log('Fetch me dude');
            fetchData();
        }
    });

Upvotes: 0

Views: 135

Answers (1)

Xan
Xan

Reputation: 77591

1) As a note, chrome.storage.sync will work even if sync is disabled - it just will behave like local (except for limits). So one can always use sync and not worry if it's enabled by the user or not.

2) The browser will ask to turn on sync regardless of whether the extension uses storage at all. Note the wording:

Sync nag

The purpose of Extensions sync sub-option is not only storage.sync, but also:

  • the list of installed extensions and the installation source,
  • their enabled/disabled state and its reason,
  • their order in the extension "shelf".

If you're curious, you can look at chrome://sync-internals/'s Sync Node Browser to see the data. Note the difference between "Extensions" and "Extensions settings" collections. It's not possible to enable syncing one but not the other (oh, how I wish it was).

In this case, the prompt is suggesting "if you want this installed in all instances of your browser, turn on sync", and it's normal behavior.

Upvotes: 1

Related Questions