以编程方式显示 firefox 扩展弹出窗口

Display firefox extension popup programmatically

我正在开发一个 Firefox 扩展,我一直在寻找一种在特定条件下自动显示它的方法(JavaScript),就好像用户点击了图标一样。

我知道这是可能的,因为一些扩展已经做到了(比如 Wanteeed,见下图)

我的 javascript 获得了我想要的所有信息,我知道当我的情况好时我现在唯一需要的是让我的小扩展 'popup' 神奇地出现的方法

我已经尽我所能寻找答案,我希望我没有错过一个已经存在的 post,如果我错过了,非常抱歉,非常感谢您的回答!

您使用的是最新的吗WebExtensions format? If so, then you can't just open the popup page programmatically, this is for security reasons. From the MDN web docs:

When the user clicks the button, the popup is shown. When the user clicks anywhere outside the popup, the popup is closed. The popup can be closed programmatically by calling window.close() from a script running in the popup. However, you can't open the popup programmatically from an extension's JavaScript: it can only be opened in response to a user action.

另一种方法是使用内容脚本将 position:fixed div 附加到当前页面,然后使用 CSS 对其进行样式设置以匹配弹出式样式。这可能就是您引用的扩展正在做的事情。