So I have this script that runs on a website and gathers some data based on certain parameters, which works perfectly fine by itself, but I want to be able to have a browserAction popup with a single button in it, which on click will trigger the aforementioned script.
I believe my problem is that I can't get the message to be sent via a press of the button, I don't know how to implement this, and no browserAction tutorial I've read tried to, either.
Here's my code: popup.html
<html>
<body style="width: 200px; height: 150px;">
<script src="background.js"></script>
<div id="button" style="position:absolute; left: 75px;">
<button id="mb" onclick="click()">Initialise</button>
</div>
</body>
</html>
background.js
function click() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "clicked_browser_action"});
});
}
content.js
$(document).ready(function(){
init();
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if(request.message === "clicked_browser_action"){
popup();
}
})
});
I know the rest of my code works, because I've tested it by adding
browserAction.onClick.addListener(function(tab){ ... });
in the place of
function click() { ... }
and everything worked exactly as I wanted it to.
How would I go about implementing the button correctly?