What i am trying to do is,
Popup.html
In popup.html i created a logIn page, after user click the LogIn button i successfully loggedIn at that time in local storage i store my token and username.
content.js
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
// console.log('Data to Call', response, dialingNumber);
if (response == undefined || response == null) {
window.confirm('Please LogIn...!');
}
else {
// ....
}
background.js
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
var credentials = localStorage.getItem('voi-auth').split("|");
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: credentials});
});
It's working fine at the time i first installed, able to call the credential which i store in local storage from the content script.
Problem
My problem is that if i went to the extension and disable the extension then again enable it , i can't communicate between content and background scripts , response is undefined in content script when i call the send message function, even though the local storage has the token and username. Sad part is it will work fine, only when i inspect the background.js and make it open all the time. It won't work when i close my popup.
Is there any solution to avoid this suitation something like execute the background page like that?