chrome.runtime.onStartup永远不会触发? [英] chrome.runtime.onStartup never fires?

查看:460
本文介绍了chrome.runtime.onStartup永远不会触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下Chrome扩展程序:

manifest.json



  {
name:Test onStartup,
version:0.0.0,
manifest_version:2,
background:{
persistent:false,
scripts:[eventPage.js]
},
permissions:[storage]
}



eventPage.js



  console.log(I started up!); 
chrome.storage.local.set({startedUp:true} );
});

chrome.runtime.onStartup 被记录为当第一次安装此扩展的配置文件启动时触发,而且我会怀疑它在重新加载扩展时也会触发。但是,重新启动浏览器或重新加载扩展后,我在 _generated_background_page.html console.log 消息>的控制台,
chrome.storage.local.get(startedUp,function(v){console.log(v)})结果,所以我怀疑这个监听器没有被调用。



我是否误解了这个事件被触发或绑定到了什么地方?是否在Linux上使用Chrome 28.0.1500.71?

解决方案

当您关闭chrome时,它的后台进程会继续运行。确保在再次启动chrome之前终止名为 chrome 或类似命名的所有进程。

Consider the following Chrome extension:

manifest.json

{
    "name": "Test onStartup",
    "version": "0.0.0",
    "manifest_version": 2,
    "background": {
        "persistent": false,
        "scripts": ["eventPage.js"]
    },
    "permissions": ["storage"]
}

eventPage.js

chrome.runtime.onStartup.addListener(function() { 
    console.log("I started up!");
    chrome.storage.local.set({"startedUp": true});
});

chrome.runtime.onStartup is documented as firing "when a profile that has this extension installed first starts up", and I would've suspected that it also fires upon reloading the extension. However, upon restarting the browser or reloading the extension, I do not see the console.log message in the _generated_background_page.html's console, and chrome.storage.local.get("startedUp", function(v) { console.log(v) }) yields no results, so I suspect that the listener was not called.

Am I misunderstanding when this event is triggered or binding to it incorrectly or anything like that? Is it an issue with Chrome 28.0.1500.71 on Linux?

解决方案

When you close chrome its background process keep on running. Make sure to kill all the process named as chrome or similar before starting chrome again.

这篇关于chrome.runtime.onStartup永远不会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆