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");
});