I am saving a key value pair using chrome.sync.set
in background.js and retrieving it from options.js.
Background.js:
var tempMap = {};
function function1() {
chrome.tabs.query({},function(tabs) {
// tempMap["kk"] = "value"; //LINE 1
});
// tempMap["kk"] = "value"; //LINE 2
save['Map_stored'] = tempMap;
chrome.storage.sync.set(save, function() {
console.log(save); //LINE 3
});
}
If LINE 1 is uncommented:
- options.js shows empty object for stored value
If LINE 2 is uncommented:
- options.js shows
{"kk":"value"}
What is more weird is: Line 3 always shows the right value.
I spent flat 3 hours just to trace this "bug". I hope this helps someone in future.