I want logged in user's token information in extension. For that i require token of that user stored in localstorage.
content-script.js
chrome.runtime.sendMessage({
auth: JSON.parse(localStorage.getItem("vuex"))["auth"]
});
background.js
try {
self.importScripts('content-script.js');
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.auth) {
localStorage.setItem("auth", JSON.stringify(request.auth));
}
}
catch (e) {
console.error(e);
}
Manifest.json
{
"manifest_version": 3,
"name": "LinkJoy Browser Extension",
"description": "Shorten long urls in just one click",
"default_locale": "en",
"permissions": [
"activeTab",
"storage"
],
"host_permissions": ["http://localhost:9000/*"],
"icons": {
"16": "icons/linkjoy-logo.png",
"48": "icons/linkjoy-logo.png",
"128": "icons/linkjoy-logo.png"
},
"background": {
"service_worker": "js/background.js"
},
"content_scripts": [
{
"matches": [
"http://localhost:9000/*"
],
"js": [
"js/content-script.js"
]
}
],
"action": {
"default_popup": "popup.html",
"default_title": "__MSG_extName__",
"default_icon": {
"19": "icons/linkjoy-logo.png",
"38": "icons/linkjoy-logo.png"
}
}
}
Similarly, I have tried using chrome.local.storage api also. But still I am getting error 'localStorage' is not defined.