Chrome.storage.local 无法访问另一个脚本中的数据

Chrome.storage.local Can't access data in another script

这是一个 chrome 扩展程序,涉及 2 个脚本,第一个用于设置页面 (default_popup),第二个用于对某个网页执行操作。设置页面中的一切都很好,但是当我尝试访问第二个脚本中的数据时,我什么也得不到。任何指针将不胜感激!会根据要求添加代码,告诉我你想看什么。

[清单]

{

    "name" : "TEST",

    "description" : "it just works",

    "version" : "1.0",

    "manifest_version" : 2,

    "permissions": [
        "activeTab",
        "declarativeContent",
        "storage"
    ],

    "content_scripts": [
        {
            "matches": [This is filled in the original],
            "js": ["jquery.js", "script.js"]
        }
    ],

    "browser_action":{
        "default_popup": "popup.html"
    }
}

[input.js]

$(function(){


window.onload = function() {


    updateval();


    document.getElementById('save').onclick = function(){
        var value1 = document.getElementById('input_refresh').value;
        var value2 = document.getElementById('input_max').value;
        var value3 = document.getElementById('input_min').value;
        var value4 = document.getElementById('input_disc').value;
        //alert(value);
          chrome.storage.local.set({
            'ref'   :   value1,
            'max'   :   value2,
            'min'   :   value3,
            'disc'  :   value4
                }, function(){
                    console.log('Values saved');

                    $("#save").val("Saved!");

                    setTimeout(function() {
                    $("#save").val("Save Settings");    
                    }, 2000);
          });
    }

    document.getElementById('reset').onclick = function(){

          chrome.storage.local.set({
            'ref'   :   10,
            'max'   :   999999,
            'min'   :   0,
            'disc'  :   30
                }, function(){
                    updateval();
                    console.log('Values got reset');

                    $("#reset").val("Reset!");  

                    setTimeout(function() {
                    $("#reset").val("Reset To Default");    
                    }, 2000);

          });
    }

    }


function updateval (){


            chrome.storage.local.get([
            'ref',
            'max',
            'min',
            'disc'
                ], function(data){
                    $('#input_refresh').val(data.ref);
                    $('#input_max').val(data.max);
                    $('#input_min').val(data.min);
                    $('#input_disc').val(data.disc);
                    console.log('Values Gotten');
        });


}

})();

[script.js]

$(document).ready(function(){

         chrome.storage.local.get([
         'ref',
         'max',
         'min',
         'disc'
            ], function(data){
               var ref    = data.ref;
               var max        = data.max;
               var min        = data.min;
               var disc   = data.disc;
               console.log('Values Gotten');
      });

if(window.location.href.indexOf("") > -1) {
    //console.log("homepage");
    main();
}
});

function main() { additional code here}

首先你需要解析对象

JSON.stringify(result)

这里可以参考chrome.storage.local.get and set