0

So I need to send a message when the popup in my extension is opened, I cant' use the onClick method because I'm using a popup, so I'm trying to send a message with a boolean true to the background when the popup opens, but the message never comes. Here are the background and the popup:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="CSS/toggle_bar.css">
        <meta charset="UTF-8"/>
        <script src="message.js"></script>
    </head>
    <body>

        <h2 align="center">
            CTRL
        </h2>

        User: <input type="text" id="User" placeholder="User"><br>
        Password: <input type="text"  placeholder="Password" id="Password" ><br>
        <button type="submit"  id='boton'>ENVIAR</button>
        <script src="popup.js"></script>
    </body>
</html>
    chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
        console.log("Mensaje: "+message);
        if(message.popupOpen) {
          console.log('popup is open');
        }
      });

message.js:

chrome.runtime.sendMessage({popupOpen: true},function(){
    console.log("Mensaje enviado");
}); 

  • Chrome doesn't run inline code in html script tags. You must supply a javascript file in your ` – Javier Silva Ortíz Oct 25 '19 at 03:22
  • Possible duplicate of [Where to read console messages from background.js in a Chrome extension?](https://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension) – wOxxOm Oct 25 '19 at 05:44

0 Answers0