I've built simple options form with 3 radio buttons. Seems that my options.js works correctly - i.e. if I change selection of the button, close options dialog and reopen it, the selection that I made previously is restored to the correct choice.
But if I try to pick up setting from another script, using the same statement that was used in options.js, it returns "undefined" string as if there would be no variable value stored in chrome storage.
Code in options.js that works ok:
chrome.storage.local.get(['card'], function(result) {
var card = null;
if(result.card) {
card = result.card;
} else {
card = 'douay';
chrome.storage.local.set({'card': 'douay'});
}
document.getElementById("demo").innerHTML = 'Value currently is ' + card;
document.getElementById(card).checked = true;});
Code in another script (returns "Value currently is undefined"):
chrome.storage.sync.get(['card'], function(result) {
window.alert('Value currently is ' + result.card);
});
And if I set settings and read them in the same script, they work as expected - message with "Value Got! Value is This text shall be stored"
chrome.storage.sync.set({'value': "This text shall be stored"}, function()
{window.alert("Value Saved!")});
chrome.storage.sync.get('value', function(data){
window.alert("Value Got! Value is " + data.value)});