Chrome.browserAction.onClicked.addListener Not working

I am creating a chrome extension, but my browser action is not working.

My Manifest.jason

 {
    "name": "TypoSaurus",
    "version": "0",
    "description": "TypoSaurus extension",
    "background": {
        "page": "background.html"
    },
    "manifest_version": 2,
    "browser_action": {
        "name": "TypoSaurus",
        "icons": ["icon.png"],
        "default_icon": "icon.png"
    },
    "content_scripts": [{
            "js": ["jquery-2.0.2.min.js", "background.js"],
            "css": ["customStyles.css"],
            "matches": ["http://*/*", "https://*/*"]
        }],
    "permissions": ["<all_urls>"]
}

and my background.js

function typo (tab) {

  alert('test');
}

chrome.browserAction.onClicked.addListener(typo);

The error I get is

Uncaught TypeError: cannot read property "onClicked" from undefined

+4
source share
1 answer

Naming the script background.jsdoes not magically make it the background of the script!

It is still defined as the content script in your manifest, and in the content scripts there is strictly limited access to the Chrome API . This causes the error you encountered.

, , ; (, ). script , .

, , , .

+8

All Articles