1

I'm trying to test simple messaging between the content script and background script. But I can't really figure out why my response from the listener is not returning anything. My background script activates the message by the onClicked event listener

my manifest:

{
"background":  {
    "scripts": ["content.js"]
}, 
"browser_action": {
    "default_icon": "19.png"
},
"manifest_version" : 2,
"name": "test",
"version": "0.1",
"permissions": ["tabs"],
"content_scripts": [ {
        "matches": [ "*://twitter.com/*"],
        "js": ["scrape.js"]
} ]}

background script(content.js)

chrome.browserAction.onClicked.addListener(function(tabs) { 
    chrome.tabs.sendMessage(tabs.id, {text: "hey"}, function(response) {
        console.log("Response: ", response);
    });
});

content script (scrape.js):

chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
    console.log("Received %o from %o, frame", msg, sender.tab, sender.frameId);
    sendResponse({farewell:"bye"});
});

I'm passing the tabID to the sendmessage function, but i'm not sure why my content script is not able to return a valid response. I've browsed several different stack posts and no luck so far

Apprentice Programmer
  • 1,485
  • 4
  • 26
  • 39
  • 1
    Make sure to look at the correct [console](https://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension) – wOxxOm Mar 07 '18 at 08:39

0 Answers0