I'm trying to build a little chrome extension, and, shortly, I have a popup where the user is prompt to flag/unflag a set of checkboxes. A function than modify a JSON object according to checked/unchecked boxes and later saves it in chrome.storage.local.
So far so good; problems starts at a later stage, when I try to recover the stored data into the content_script. I managed to pass the object into an alert, but, in order for my script to work, I need that JSON to be stored back into a var.
This is the code I inserted in the popup.js and that works fine
chrome.storage.local.set({
capacity: object
}, function() {
console.log('stored with chrome.storage.local');
});
here's the code I have in the actual script:
var capacity;
load();
function load() {
chrome.storage.local.get('capacity', function(result){
capacity = result.capacity;
alert(result.capacity);
}
I'm trying to get capacity to be the same var it was on popup.js when I saved it, but after several attempts I only managed to get the values printed in the alert.
So my question is: is it possible to do this? Where am I getting this wrong?