簡體   English   中英

加載解壓縮的擴展程序時,chrome.runtime.onInstalled是否會啟動?

[英]Does chrome.runtime.onInstalled fire when loading unpacked extensions?

我正在測試chrome插件,並嘗試測試chrome.runtime.onInstalled

我的代碼如下

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

chrome.runtime.onInstalled.addListener(installed);

但是當通過loading unpacked extension 我一點也沒有收到任何警報。 chrome.runtime.onInstalled似乎沒有啟動。 我該如何測試?

上面的代碼位於popup.js並在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); 線以及所有必需的功能。 然后它將按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM