0

I have a very simple Chrome extension that is just sending a message from the popover.html's javascript to the content script, and then changing a div on the page to output that, but I keep getting undefined.

popup.js:

browser.runtime.sendMessage({ test: "foo2" }).then((response) => {
    console.log(response);
    document.getElementById("testp").innerHTML = response; // writes out 'undefined'
});

content.js:

browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
    sendResponse({test: "foo" });
});

popup.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="module" src="popup.js"></script>
</head>
<body>
    <p id="testp">pleasechangeme</p>
</body>
</html>

What's wrong with my messaging that is causing it to write out undefined in the HTML each time? I'm not touching the DOM anywhere so I don't think it's related to that

Doug Smith
  • 29,668
  • 57
  • 204
  • 388

0 Answers0