that's my popUp.js.
window.onload = function() {
chrome.extension.sendMessage({
type: "login-check"
});
};
and that's my Background script.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
switch(request.type){
case "login-check":
checkLogin();
break;
}
});
function checkLogin() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {type: "login"}, function(response){
console.log(response.farewell)
});
});
}
and that's my content-script.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.type == "login")
sendResponse({farewell: "goodbye"});
});
My message is sending from popUp.js to background.js but not sending from background to content script , showing me an error "Error in event handler for (unknown): TypeError: Cannot read property 'farewell' of undefined " Please answer this question i am new to Chrome extension development and please don't send me link to others answers i have already implement all the possible answers in stack overflow. Thanks in Advance. and that's my Manifest.json
{
"manifest_version": 2,
"name": "Time Tracking Extension",
"description": "This Extension is for Time Tracking",
"version": "2.1",
"browser_action": {
"default_icon": "logo.png",
"default_popup": "popUp.html"
},
"permissions": ["storage", "tabs", "cookies"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["css/mystyles.css", "css/jquery-ui.css", "css/bootstrap.min.css"],
"js": ["js/jquery.min.js", "js/jquery-ui.js", "js/bootstrap.min.js", "js/content-script.js"]
}
]
}