简体   繁体   English

加载解压缩的扩展程序时,chrome.runtime.onInstalled是否会启动?

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

I'm testing out my chrome plugin and trying to test out chrome.runtime.onInstalled . 我正在测试chrome插件,并尝试测试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 . 但是当通过loading unpacked extension I don't get any alert at all. 我一点也没有收到任何警报。 `chrome.runtime.onInstalled doesn't seem to fire. chrome.runtime.onInstalled似乎没有启动。 How can I test this? 我该如何测试?

The above code resides in popup.js and is called in a script tag from popup.html . 上面的代码位于popup.js并在popup.js的脚本标签中popup.html The manifest.json file for that section looks like the following. 该部分的manifest.json文件如下所示。

"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 为了使chrome.runtime.onInstalled运行,您需要编辑manifest.json文件并添加

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

Put the chrome.runtime.onInstalled.addListener(installed); chrome.runtime.onInstalled.addListener(installed); line there along with all the required functions. 线以及所有必需的功能。 Then it will work as expected. 然后它将按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chrome.runtime.onInstalled不会首先触发? - chrome.runtime.onInstalled does not fire first? 如何在Chrome扩展程序中使用Require.JS时触发chrome.runtime.onInstalled - How to get chrome.runtime.onInstalled to fire when using Require.JS in Chrome extension 为什么在没有新安装的情况下会触发“chrome.runtime.onInstalled”事件? - Why does "chrome.runtime.onInstalled" event fire without new installations? chrome.runtime.onInstalled未定义 - chrome.runtime.onInstalled is undefined 在 chrome 扩展的后台脚本中,如何处理对 chrome.runtime.onInstalled 事件的 addListener() 方法的调用? - In the background script for a chrome extension, how does a call to the addListener() method for the chrome.runtime.onInstalled event get processed? 如何为 Chrome 扩展测试 chrome.runtime.onInstalled? - How can I test chrome.runtime.onInstalled for a Chrome extension? onInstalled chrome运行时调试? - onInstalled chrome runtime debugging? Chrome:运行时的消息内容脚本。onInstalled - Chrome: message content-script on runtime.onInstalled chrome.runtime.onInstalled.addListener 清单版本 3 从版本 2 迁移 - chrome.runtime.onInstalled.addListener manifest version 3 migration from version 2 chrome.runtime.onInstalled.addListener意外打开选项卡? - chrome.runtime.onInstalled.addListener unexpectedly opens tabs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM