I'm trying to get a simple message passing to work on chrome extension, but I'm not getting a response. I'm sending a message from popup.js to the content script and the content script should return a response.
My popup.js:
let myButton= document.getElementById('myButton');
myButton.onclick = function(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
};
my content script:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("Message Received");
console.log(request.greeting);
if (request.greeting == "hello")
myFunction(sendResponse);
return true;
});
function myFunction(sendResponse)
{
console.log('Sending response');
sendResponse({farewell: "goodbye"});
}
In the console I'm getting the 'Sending response' message, but not the log after that in the popup.js