How to trap extension disable of uninstall (on Firefox)?


(Sxilderik) #1

I’m writing a Web Extension (on Firefox first).

I’m facing a case where I need to know when my extension is being disabled. I understand that management.onDisabled.addListener is not implemented yet on Firefox, and that it probably will never be, because

The only extensions we found in the list of popular extensions that use these API events seem to use them in a questionable way.

So, I guess that trying to monitor when my extension is disabled or uninstalled is not the right thing to do?

Still, I need to release resources when that happens: how can I achieve that, is there another event I should listen to?

Thanks for your help!


(Martin Giger) #2

It’s very hard to listen for your extension to be shut down, let alone uninstalled or disabled, since the pages are force-unloaded. You can try to start actions from window unload listeners and similar, but I doubt you’ll have much success with that. It’s probably easier to look for a different way of figuring out if you can free your resources.

Another approach would be to open a websocket connection to the other end that manages those resources and free them when the connection is closed, for example.


(Sxilderik) #5

Well, thanks…

I said I had to release resources just as a quick example of a general use case.

My actual situation is that I have to trap the disable (or uninstall) event so that I could close an iframe I created dynamically in the page, because when the extension is disabled the script behind the [close] button is no longer there, and the user can not close it, but by reloading the page, which is not cool.

I’m still not sure why Chrome implements that API when Mozilla choses not to, but I still hope I can find a workaround somehow.
Hope is “growing” fainter though…

Thanks