Google-chrome – Run script each time Chrome extension icon clicked

google-chromegoogle-chrome-extension

How do I write a chrome extension such that every time a user clicks the icon, my script is run but no popup is opened? (I would look this up in the docs myself but for whatever reason they suddenly stopped working, 404ing every page, as I got to this point).

I'm assuming it's just setting up the manifest correctly. Here's what I have now:

{
  "name": "My Extension",
  "version": "0.1",
  "description": "Does some simple stuff",
  "browser_action": {
    "popup" : "mine.html",
    "default_icon": "logo.png"
  },
  "permissions": [
    "notifications"
  ]
}

Best Answer

Remove popup from your browser_action section of the manifest and use background pages along with browser Action in the background script.

chrome.browserAction.onClicked.addListener(function(tab) { alert('icon clicked')});
Related Topic