I did what's in the documentation but I got an error saying Cannot read property 'farewell' of undefined
in the background page.
my background.js
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
console.log('ytr');
});
});
The msg is sent because my console.log('test') did print out.
my contentScript.js look like this
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
and I did declare permission tabs and activeTab in manifest.json. What else I missed?