Chrome.storage.sync.set/get isn't working
Chrome.storage.sync.set/get isn't working
构建chrome扩展时可能遇到的一个常见问题是,每次从chrome存储检索数据时,它都会返回UNDEFINED。我来举个例子。
var toStore = "This text shall be stored"
//Script saves toStore and callback function provides confirmation
chrome.storage.sync.set({"value": toStore}, function(){console.log("Value Saved!")});
然后一个函数被一个获得值的事件激活:
var storedItem = chrome.storage.sync.get('value', function(){
console.log("Value Got! Value is " + value)});
或者类似的东西,但是如果你在控制台上的结果总是:
Value Got! Value is Undefined
我将向您展示如何避免这种情况。
使用chrome.store.sync获取存储值。Get时,实际函数不返回保存的值。相反,它返回var "data",其中包含存储值的名称-值对:
chrome.storage.sync.get('value', function(data){
console.log("Value Got! Value is " + data.value)});
该值随后以"data.[value - name]"的名称存储在函数中。如果你运行这个,你应该得到
Value Got! Value is This text shall be stored
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Isn't javascript regex lazy?
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Podio api hook=false isn't working
- ctx.createPattern isn't working
- Chrome.storage.sync.set/get isn't working
- Fabricjs - Resize isn´t working correctly on object
- jScrollPane isn't working
- javascript settimeout reset isn't working
- jquery colorbox isn't working with mootools v1.1
- not :contains isn't working