I just made a Chrome extension. I followed this tutorial to get a nice button in my toolbar. Now if I load a page, the javascript in my extension gets executed.
Unfortunately, if I click the extension’s button in my toolbar, nothing happens.
Question: How do I make the js get executed when I click the extension’s button in my toolbar?
Thanks for your help.
Edit
I added background.html and it still doesn’t work:
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "javascript:mathjax.js";
chrome.tabs.update(tab.id, {url: action_url});
});
</script>
</head>
</html>
You have two options. Either, you can specify a
"popup": "popup.html"in yourmanifest.json, then put the code inpopup.html. In this case, the code will get executed in the popup (though of course you can communicate with your background page or anything else).Probably better would be to put a callback in
background.htmlby attaching a listener to chrome.browserAction.onClicked.