So I've already asked this question, but the responses given didn't work (I've updated this post with a few of the suggestions from before)... Here is the link to that question in case anybody who wants to take a stab at this also wants to see what what was said before.
Chrome extension: sendMessage doesn't work
I've already read the documentation from Google on 'message passing' a few times and have probably looked at over 10 other questions with the same problem and already tried quiet a few variations of most of their "solutions" and of what I have below... This is black magic, right? Either way, here it goes.
manifest.json File:
{
"manifest_version" : 2,
"name" : "Message Test",
"version" : "1.0",
"browser_action": {
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches" : ["<all_urls>"],
"js": ["message-test.js"]
}
]
}
popup.html File:
<html>
<body>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
popup.js File:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab = tabs[0]; // do not forget to declare "tab" variable
chrome.tabs.sendMessage(tab.id, {
greeting: "Can you hear me?"
}, function(response){});
});
message-Test.js File:
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.greeting == "Can you hear me?"){
alert("Test");
}
else{
sendResponse({});
}
});
The alert("Test") does not go off...