Reputation: 23
I have no idea why I can't set a value in chrome.storage.sync
(same issue with storage.local
), I've tried multiple solutions online, but sadly none of them work
This is my popup.js
file (linked to the popup.html
file)
window.addEventListener("DOMContentLoaded", () => {
let my_key = "some string";
let value = "some value"
chrome.storage.sync.set({[my_key]: value}, function() {
console.log('Value is set to ' + value);
});
chrome.storage.sync.get([my_key], function(result) {
console.log('Value currently is ' + result.key);
});
});
Everytime the output is Value currently is undefined
.
Upvotes: 2
Views: 192
Reputation: 1373
You should use result[my_key]
not result.key
chrome.storage.sync.get([my_key], function(result) {
console.log('Value currently is ' + result[my_key]);
});
Upvotes: 1
Reputation: 310
For dynamic keys you have to set the variable in brackets: {[my_key]: value}
and also set a value for value
.
Upvotes: 1