I have a chrome extension where extension tabs subscribe to events emitted by the background page. The background page's eventing module therefore holds references to handler functions that belong to global contexts of extension tabs.
The problem is that extension tabs may be closed, resulting in "orphaned" handlers that still work but are useless/wasteful because they are processing events within a global context that is no longer associated with a UI. Garbage collection of the "orphaned" window object is delayed since the background page is still holding references to its functions. A similar situation occurs when an extension tab is reloaded since that creates a new global context for the tab.
What I'm basically looking for is for an eventing module to be able to identify and expire stale handler references belonging to "orphaned" global contexts.
When an extension tab's handler function is called from the background page, it executes within the context of the tab, so I can access the "orphaned" window object from within the handler. Is there anything unique about this window object that I can use to determine that it is "orphaned" when the handler executes? I'm assuming it's not possible to determine anything useful about the handler function from the background page before I call it.
FYI, I have toyed with unload and beforeunload events to give an extension tab the opportunity to unregister its handlers. This seems like the most desirable approach in theory. Unfortunately, both of these events proved unreliable.
Aucun commentaire:
Enregistrer un commentaire