I fetch data from chrome local storage using this function:
function getStorageByKey(key) {
chrome.storage.sync.get(key, function(obj) {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
console.log('function log')
console.log(obj)
return obj
});
}
I call it like this:
var storage = getStorageByKey('hidden_threads')
console.log("function's return")
console.log(storage)
and the logging output is:
function's return
undefined
function log
{hidden_threads: Array(1)}
I guess this means that the data is being passed through the function appropriately, but I don't understand why console.log(storage)
happens before the function finishing execution. I assume that's why it is returning undefined, but not sure about the mechanism that causes this.