WebExtensions:检测 FireFox 的安装事件

WebExtensions: detect installation event for FireFox

我正在开发一个使用 WebExtensions API 的 FireFox 插件。

我们希望在用户安装扩展程序时打开一个新选项卡。有一个名为 management.onInstalled(), but FireFox does not support this 的事件。

另一个事件 runtime.onInstalled 适用于高于版本 52.0 的 FireFox。是否有可靠的方法为所有 FireFox 版本实现此功能?谢谢。

好吧,我过去的做法是使用存储。因此,每次启动插件时,您都会检查本地存储中是否有名为 'hasBeenRun' 的条目。如果没有,那么您可以打开您的选项卡并将 'hasBeenRun' 设置为 true。否则你就直接忽略它。

browser.storage.local.get('hasBeenRun').then(data => {
  if (!data.hasBeenRun) {
    browser.storage.local.set({'hasBeenRun':true}).then(()=>{
    // do your tab opening magic
  }
});