简体   繁体   中英

Does chrome.runtime.onInstalled fire when loading unpacked extensions?

I'm testing out my chrome plugin and trying to test out chrome.runtime.onInstalled .

My code is as following

function installed(){
    alert("Success");
}

chrome.runtime.onInstalled.addListener(installed);

But when loading the extensions through loading unpacked extension . I don't get any alert at all. `chrome.runtime.onInstalled doesn't seem to fire. How can I test this?

The above code resides in popup.js and is called in a script tag from popup.html . The manifest.json file for that section looks like the following.

"browser_action": {
    "default_icon": {
        "19": "images/enabled-icon-19.png"
        //"38": "images/icon38.png"
    },
    "default_popup": "popup.html",
    "default_title": "mytitle"
}

For chrome.runtime.onInstalled to run you need to edit your manifest.json file and add

"background": {
    "scripts": ["background.js"]
}

Put the chrome.runtime.onInstalled.addListener(installed); line there along with all the required functions. Then it will work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM