As I work on a Chrome extension, I am facing an issue with retrieving information from chrome.storage. This involves saving some data in the options page and then accessing it in the content_script.
In the options.js
, this is how the information is saved:
function save_options() {
var color = document.getElementById('color').value;
chrome.storage.sync.set({
favoriteColor: color
}, function() {
console.log("Color saved");
});
}
However, when trying to access this information in my content_script.js
, I encountered difficulties. Here's what I attempted:
var color = null;
chrome.storage.sync.get('favoriteColor', function(item){
color = item.favoriteColor;
});
alert(color); // This line does not work as intended