加载未打包的扩展时执行chrome.runtime.oInstalled fire

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

本文关键字:chrome 执行 runtime oInstalled fire 扩展 加载      更新时间:2023-09-26

我正在测试我的chrome插件,并尝试测试chrome.runtime.onInstalled

我的代码如下

function installed(){
    alert("Success");
}
chrome.runtime.onInstalled.addListener(installed);

但是当通过CCD_ 2加载扩展时。我一点也不警觉`chrome.runtime.oinstalled似乎没有启动。我该如何测试?

上述代码驻留在popup.js中,并在popup.html的脚本标记中调用。该部分的manifest.json文件如下所示。

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

要运行chrome.runtime.onInstalled,您需要编辑manifest.json文件并添加

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

chrome.runtime.onInstalled.addListener(installed);线与所有必需的功能一起放在那里。然后它将按预期工作。