I am trying to store and get objects by using chrome.storage for my chrome extension and want to do it simultaneously with two different key-value pairs. Doing this individually works but I need to set and get both pairs simultaneously and that is not working. I haven't seen much documentation on multiple key-value pairs with chrome.storage which is the reason for my confusion. This is the code that I am trying to use, how do I fix it?
var key = 'key', stored1 = {'val': object1.innerHTML};
var key2 = 'key2', stored2 = {'val': object2.innerHTML};
chrome.storage.local.set({[key]: stored1, [key2]: stored2}, function() {
console.log('Saved', key, stored1);
console.log('Saved', key2, stored2);
});
function fun() {
chrome.storage.local.get(['key', 'key2'], function(result) {
if (Object.values(result)[0] != undefined) {
something = Object.values(result)[0].val
}
if (Object.values(result)[1] != undefined) {
gpaTable.innerHTML = Object.values(result)[1].val;
}
});
}