I am trying to execute javascript on a page when I click on a button in popup.html. I tried to use such a way:
In background.js:
<
You can also use Messaging:
in popup.js
document.getElementById("clicked-btn").addEventListener("click", function(e) {
chrome.runtime.sendMessage({'myPopupIsOpen': true});
});
in background.js
chrome.runtime.onMessage.addListener(function(message, sender) {
if(!message.myPopupIsOpen) return;
// Do your stuff
});
Not tested but should works, further informations about Messaging.