I have two Chrome extensions and in one I need to receive a message in a content script. The other extension is sending a message in its background page. I am following this question but it did not work.
I changed .extension
to .runtime
in the listener and it still does not work. Here's the code:
extension 1, contentscript.js (this is not being fired)
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
console.log("contentscript");
if(sender.id !== "iknbmfmkhcilpbkobjafdhaloffobdbe")
return;
if (document.getElementById("status").innerHTML === "1")
sendResponse({farewell: "goodbye"});
});
extension 2, background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {pdf: "You a pdf?"}, function(response) {alert(response.farewell);});
});
});