我对chrome扩展安装/更新事件有疑问。如果我在后台脚本的顶级代码中添加onInstalled事件侦听器,那么是否有时间范围内我的事件侦听器将捕获该事件?
我之所以这样问,是因为我的演示表明,如果在挂接onInstalled侦听器之前有一些逻辑可以执行,则看起来该逻辑将永远不会执行,就像该事件同时发生一样。
有人可以在后台脚本中其他逻辑的背景下向我详细说明此事件的工作原理,或者指向我一些文档,因为我找不到任何有用的东西。
谢谢!
更新@Noam Hacker:由于公司政策,我无法在此处发布任何真实代码,但是我有一些伪代码可以说明我的问题:
/**
* setup in which I miss onInstalled event
*/
function firstLogicThatRunsOnBackgroundLoad() {
// perform some logic
// perform some asynchronous operations via generators and promises
// which can take a while
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
// this logic never gets executed
} else if(details.reason == "update") {
// perform some logic
}
});
}
/**
* setup in which I catch onInstalled event
*/
function firstLogicThatRunsOnBackgroundLoad() {
chrome.runtime.onInstalled.addListener(function (details) …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个 chrome 扩展程序,每次打开新选项卡并加载页面时都应该收到通知,为此我使用 chrome.tabs.onUpdated 事件。
问题是,如果在某个域(具有 src)托管的页面/选项卡上插入 iframe,则会触发 onUpdated 事件。有没有办法区分“真实”选项卡加载的这些事件与 iframe 加载触发的事件?
我从 chrome 扩展开发开始,并且在开发过程中对扩展安装/更新流程和测试有几个问题:
谢谢!