Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome extension要求启用同步,尽管使用了本地存储_Javascript_Google Chrome Extension - Fatal编程技术网

Javascript Chrome extension要求启用同步,尽管使用了本地存储

Javascript Chrome extension要求启用同步,尽管使用了本地存储,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我正在开发一个Chrome扩展,它将数据存储在本地存储器中。但当我从Chrome Play store安装到其他系统时,它会要求打开同步。下面是我的舱单。有趣的是,即使有人拒绝打开同步,它仍然有效 { "manifest_version": 2, "name": "XX", "description": ".....", "version": "0.1", "chrome_url_overrides": { "newtab": "newtab.html" },

我正在开发一个Chrome扩展,它将数据存储在本地存储器中。但当我从Chrome Play store安装到其他系统时,它会要求打开同步。下面是我的舱单。有趣的是,即使有人拒绝打开同步,它仍然有效

{
  "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"
  ]
}
我怎么了

更新 下面是与存储相关的代码

 // 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();
        }
    });
//获取最后一个时间戳
chrome.storage.local.get('records\u fetch\u ts',函数(date\u rec){
旧时间=日期记录['records\u fetch'];
如果(旧时间的类型!=“未定义”){
当前时间=新日期().getTime()
var timeinmilisec=当前时间-旧时间;
天数=数学下限(时间单位毫秒/(1000*60*60*24));
}
});
chrome.storage.local.get('records',函数(result){
记录=结果;
//记录=空;
if(!$.isEmptyObject(记录))
entries=JSON.parse(结果['records'])
//随机结果的准备
如果(entries.length>0)
itemsLength=entries.length;
如果(项目长度>0)
随机数=数学楼层((数学随机()*itemsLength)+1);
单个项目=条目[随机编号];
控制台日志(单个_项);
如果(单个项目!=null)
$('asin').html(单个项目['asin'))
更新(单个项目)
console.log(天)
//如果(记录==null&&days>10){
if((天<0 | |天>10)| |记录==null){
console.log('fetchme dude');
fetchData();
}
});
1)请注意,
chrome.storage.sync
即使禁用了同步,也能正常工作-它的行为就像
local
(限制除外)。因此,用户可以始终使用
sync
,而不必担心用户是否启用了它

2) 无论扩展是否使用
存储
,浏览器都会要求启用同步。请注意以下措辞:

“扩展同步”子选项的用途不仅是存储。同步,还包括:

  • 已安装扩展的列表和安装源
  • 其启用/禁用状态及其原因
  • 他们在扩展“货架”中的顺序
如果您感兴趣,可以查看
chrome://sync-internals/
的同步节点浏览器以查看数据。请注意“扩展”集合和“扩展设置”集合之间的区别。无法启用一个集合而不能启用另一个集合的同步(哦,我多么希望如此)


在本例中,提示提示提示“如果您希望在浏览器的所有实例中安装此功能,请启用同步”,这是正常行为。

@wOxxOm问题已更新。看起来确实是Chrome中的错误/怪癖。请查看是否有报告或自己报告。