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

72 views Asked by At

I'm coding a web extension for FF. Currently I'm using the same page as the popup (browser_action) and the background:

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

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

but as far as I can tell, the page reloads every time I open the popup, and overall, the behavior of the JS loaded by the page is weird.

Is there any way to load the page once, and only show (and not reload) it each time the user opens the popup?

Thanks a lot guys!

1

There are 1 answers

1
Makyen On BEST ANSWER

No, there is no way to do that. Similar to a web page, the popup scope is created when it is shown and destroyed when it is no longer visible. You will need to use JavaScript to restore any state which you desire to have be the same as the last time it was opened. Any information which you desire to persist after the popup is destroyed, you will need to store somewhere else (e.g. the background page, or a StorageArea).