I am new to JavaScript and chrome extensions. I am writing an extension that needs to get a value out of the local storage of the web page to which it is a page action. Here is a snippet of manifest.
manifest.json
:
{
"content_scripts": [
{
"matches": ["http://url/*"],
"js": ["user_story_template.js"]
}
],
"page_action": {
"default_title": "Promotify",
"default_icon": "promotify_20.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://url/*",
"declarativeContent",
"storage"
]
}
Here is a snippet of the content script:
function get_token(){
//alert("Starting processing...");
var auth_token = "";
chrome.storage.local.get('token', function(result){
auth_token = result.token;
});
I have looked for answers and a lot of them say that this way should work. I should be able to do this from the content script. However, am not getting any value. I have tried using HTML also to no avail. When I go into the inspector on the page and look under resources there is a value for token in local storage.Can anyone see what I might be doing wrong? I am sure that I am missing something.
Some of the places I have looked for the answer:
Easy way to get Local Storage Value to Content Script [Chrome Extension]
Access chrome local storage used in both content script and popup?