【发布时间】:2020-12-15 04:13:29
【问题描述】:
我的扩展程序有一个持久的后台脚本,我希望它在有可用更新时提示用户。
据我了解,如果有可用的更新,那么一旦用户重新启动 chrome,扩展将自动更新(由于持久的后台脚本)。为此,我想添加以下内容:
chrome.runtime.onUpdateAvailable.addListener((details) => {
var response = window.confirm(`${details.version} is now available`);
if (response) {
chrome.runtime.reload();
}
});
我的困惑
发件人:https://developer.chrome.com/docs/extensions/reference/runtime/#event-onUpdateAvailable
onUpdateAvailable
chrome.runtime.onUpdateAvailable.addListener(listener: function)
Fired when an update is available, but isn't installed immediately because the app is currently running.
If you do nothing, the update will be installed the next time the background page gets unloaded, if you want it to be installed sooner you can explicitly call chrome.runtime.reload().
If your extension is using a persistent background page, the background page of course never gets unloaded, so unless you call chrome.runtime.reload() manually in response to this event the update will not get installed until the next time chrome itself restarts.
If no handlers are listening for this event, and your extension has a persistent background page, it behaves as if chrome.runtime.reload() is called in response to this event.
最后一句没看懂:
如果没有处理程序正在侦听此事件,并且您的扩展程序有一个持久的背景页面,它的行为就像 chrome.runtime.reload() 被调用以响应此事件。
问题
- 如果没有事件处理程序,这怎么可能?
- 我的功能正确吗?
- 如何测试?
问题
我尝试将版本设置为 1.0.0(当前最新版本更高)并将其作为正在开发的扩展加载,但没有显示提示。
【问题讨论】:
标签: javascript google-chrome-extension firefox-addon microsoft-edge-extension