Search code examples
google-chrome-extensionmanifest.json

Chrome extension alert won't fire from the background.js


Tring to run a background script to fire an alert. It's loaded successfully, but no alert.

manifest:

{
  "name": "Hello Extensions",
  "permissions": [
          "downloads","storage"
  ],
  "description" : "Base Level Extension",
  "version": "1.0",
  "browser_action": {
    "default_popup": "hello.html",
    "default_icon": "hello_extensions.png"
  },
  "manifest_version": 2,
  "background": {"persistent": true, "scripts": ["background.js"]}
}

background.js:

alert("hello");

Solution

  • Thanks @wOxxOm,

    Found that there is an option to debug the background script. In chrome://extensions/ find your extention then "Inspect views background page"

    If I click this, the alert does show up (but not if I open a new tab or a new window).

    Note: if you try to use jquery in the script it should be specified before the 'background.js' in the manifest.