Using port.onDisconnect to detect when a Chrome extension or uninstall is removed

I know the Chrome Extension API has no official way of detecting when a user deletes your extension (which is a shame).

I am using the port.onDisconnect listener from my content-script page after connecting to the background page to detect when the user disables / disables my extension. According to the doc, port.onDisconnect should only fire when the extension no longer exists (or when port.disconnect is explicitly called from a background page), which should cover the disconnect / delete scenario.

This works really great on my machine. Whenever I remove or disable an extension, port.onDisconnect runs as intended (once per open tab). The problem is I see this event being fired from MANY of my real users. I'm 99% sure that not many users have disabled / uninstalled my extension (I see them doing other tasks later with my extension, and my extension installation numbers don't show that many have been removed).

This leads me to think there is another condition that calls port.onDisconnect besides disabling / removing the extension. I cannot reproduce this at all on my machine. On my machine, port.onDisconnect is only triggered when the extension is disconnected / removed, and I don't call port.disconnect explicitly from my background page anywhere.

So my question is, what could be the condition (s) that trigger port.onDisconnect, other than that the user disables / removes the extension? I thought that updating the version of an extension might cause this behavior, but I tested it on my machine and I don't think it will.

Any ideas?

+3


source to share


1 answer


If you're happy with the script, add a listener every time it is injected, the listeners of every open page / tab that this script was run on will be executed.

One user can uninstall or disable an extension, but 10 vulnerable pages / tabs may have opened, so it might seem like 10 users did it.



I'm not sure what is the best way to get around this, if any, since what you are trying to achieve is not actually supported.

0


source







All Articles