So I have been having trouble getting the message system to work. I made a simple example to try to get the text of the first header on my site, send it to the popup window, and have the window display it. Here are my three files in the extension:
popup.html
<html>
<head>
<script src=populatePopup.js></script>
</head>
<body>
<p id="fillMe"></p>
</body>
</html>
getInfo.js (content script)
var title = document.querySelector("h3");
chrome.runtime.sendMessage(title);
console.log("Sent message!");
populatePopup.js
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
if(message) {
console.log("Got message!");
var fill = document.getElementById("fillMe");
fill.innerHTML = "The first h3 found was " + message.innerHTML;
return true;
}
});
However, my popup never displays anything. How can I get this to work? Thanks!