port.onDisconnect isn't fired when extension is disabled/uninstalled
Categories
(WebExtensions :: General, defect, P3)
Tracking
(Not tracked)
People
(Reporter: maciej.cwiek9, Assigned: zombie)
References
Details
(Whiteboard: [runtime] triaged)
Updated•9 years ago
|
Updated•9 years ago
|
Updated•9 years ago
|
Updated•9 years ago
|
Updated•9 years ago
|
Comment 1•8 years ago
|
||
Updated•8 years ago
|
Updated•8 years ago
|
Comment 2•7 years ago
|
||
Assignee | ||
Comment 6•7 years ago
|
||
Comment 7•7 years ago
|
||
Assignee | ||
Comment 8•7 years ago
|
||
Comment 10•7 years ago
|
||
Assignee | ||
Comment 11•7 years ago
|
||
Comment 12•7 years ago
|
||
Comment 13•7 years ago
|
||
Comment 14•7 years ago
|
||
Comment 15•7 years ago
|
||
Comment 16•7 years ago
|
||
Updated•6 years ago
|
Comment 17•6 years ago
|
||
Comment 18•6 years ago
|
||
Comment 19•5 years ago
|
||
+1
Assignee | ||
Comment 20•5 years ago
|
||
Might look into as part of bug 1583484.
Comment 21•4 years ago
|
||
Is there any news on this? I was hoping there would be a way to detect disable/uninstall from a background script alone. My extension has content scripts, but they're not loaded 100% of the time. They're only loaded on certain URLs. They receive messages from the background script and send messages back, and it's a long story to explain what exactly the purpose is, but they end up setting some global "variables" that are used by other extensions too. It's important that everything goes back to normal when the extension is updated, disabled, or uninstalled, regardless of the conditions under which the background script "disconnected."
There are a lot of things I've done to try to ensure that the variables are cleaned up when content scripts are unloaded or websockets are closed, but I'm trying to solve edge cases like the extension being disabled, uninstalled, or updated. In this case it wouldn't actually be enough to allow content scripts to receive events on disconnect from the background script, or even vice versa. A certain amount of jankiness is tolerable of course, but it would be ideal to have an event like "beforeOnDisconnect" which, like the name implies, fires once, just before an extension is disabled/uninstalled/updated. That way the background script itself can listen to the event (in cases where it is the ONLY script running in the extension) and execute its own cleanup.
I get that that could get pretty complicated — like, does allowing it to execute cleanup behavior mean allowing it to block the whole uninstall/disable/update process? That seems pretty dirty and even prone to abuse by malicious extensions, and would probably be an onerous burden to implement. I don't know how silly any of this sounds so bear with me lol. Maybe scrap the blocking but just allow the extension half a second to clean up? It'd be inconsistent but in my case, this would be just fine, since all that needs to happen on disconnect are a few assignments and messages. I think it'd be better than nothing. Alternatively, maybe the blocking could be implemented but limited to some given duration.
This would be much more restrictive, but it's just an idea: what if instead of executing its own cleanup, an extension could define some cleanup function in its manifest.json, and when the extension is initialized, that code is delivered to some internal module. It wouldn't share scopes or execution contexts with the extension so its functionality would be limited, but again, still way better than nothing at all. Basically save the code in some kind of special sandbox so the browser can execute it, even after (or while) the extension's contexts are popping off the stack.
Updated•2 years ago
|
Description
•