I am using this code to get chrome.storage.local
value:
function getCachedAuthToken(times){
var cachedToken = "";
if(times > 3){
return "";
}
chrome.storage.local.get('cruiseToken', (result) => {
if (result.cruiseToken) {
console.log("token:" + result.cruiseToken);
cachedToken = result.cruiseToken;
return result.cruiseToken;
} else {
console.log("token:wwwww");
fetchAuthToken("+8615683761628","12345678");
++times;
getCachedAuthToken(times);
}
});
console.log("cachedToken:" + cachedToken);
return cachedToken;
}
now I am sure the result.cruiseToken
have a string value. But the outer cachedToken
value is always "". what should I do get the inner value ?
Try to replace cachedToken = result.cruiseToken;
by cachedToken=JSON.stringify(obj);
And make sure you define it in the manifest:
"permissions": [
"unlimitedStorage",
"clipboardRead",
"clipboardWrite",
"nativeMessaging" ,
"storage"
],