I am trying to use chrome.storage
API to store and get back values in content.js
of my Chrome extension, and I have already set the permission for storage in the manifest.json
file. After using setStorage('test','123456') when I call getStorage('test')
function I am getting 'Value for key is: undefined
in the console. Can you please help me figure out the problem?
function setStorage(key,value){
chrome.storage.local.set({key: value}, function() {
console.log('Value for '+key+' is set to ' + value);
});
function getStorage(key){
chrome.storage.local.get([key], function(result) {
console.log('Value for '+key+' is: ' + result.key);
});
}
Edit: I wrapped key in getStorage()
as an array [key]
.