使用相同的页面(和 JS)作为 FireFox webextension 中的背景和弹出窗口而无需重新加载

Using the same page (and JS) as the background and the popup in FireFox webextension without it reloading

我正在为 FF 编写一个网络扩展。目前我正在使用与弹出窗口 (browser_action) 和背景相同的页面:

"background": {
    "page": "popup/index.html"
},

"browser_action": {
    "default_icon": "icons/index32.png",
    "default_title": "Indexer",
    "default_popup": "popup/index.html"
},

但据我所知,每次打开弹出窗口时页面都会重新加载,总的来说,页面加载的 JS 行为很奇怪。

有没有什么方法可以加载一次页面,并且每次用户打开弹出窗口时只显示(而不是重新加载)它?

非常感谢你们!

不,没有办法做到这一点。与网页类似,弹出范围在显示时创建,在不再可见时销毁。您将需要使用 JavaScript 来恢复您希望与上次打开时相同的任何状态。在弹出窗口被销毁后,您希望保留的任何信息都需要存储在其他地方(例如背景页面,或 StorageArea)。