Using port.onDisconnect to determine when a Chrome extension is uninstalled / disabled

1,484 views
Skip to first unread message

cetioren

unread,
Mar 12, 2012, 8:51:10 AM3/12/12
to Chromium-extensions
I know that Chrome extension API doesn't have an official way of
determining when a user uninstalls 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 determine when a user
uninstalls/disables my extension. According to the docs
port.onDisconnect should only fire when the extension doesn't exist
anymore (or when port.disconnect is explicitly called from the
background page) which should cover the disable / uninstall scenario.

This actually works perfectly on my machine. Whenever I uninstall or
disable my extension, port.onDisconnect is fired as it's supposed to.
The problem is I am seeing this event fired MANY times from my actual
users. I am 99% sure that not this many users are disabling /
uninstalling my extension (I see them perform other tasks later on
with my extension and my extension installation numbers doesn't show
that many uninstalls).

This leads me to believe that there is some other condition that fires
port.onDisconnect other than disabling/uninstalling an extension. I
cannot reproduce this at all on my machine. On my machine,
port.onDisconnect is only fired when I disable/uninstall the extension
and I don't call port.disconnect explicitly from my background page
anywhere.

So my question is: what could be the condition(s) that fires
port.onDisconnect other than the user disabling/uninstalling an
extension? I thought a version upgrade of the extension could cause
this behavior but I tested it on my machine and I don't think that's
it.

Any ideas?

Abraham Williams

unread,
Mar 12, 2012, 10:57:58 AM3/12/12
to cetioren, Chromium-extensions
I believe port.onDisconnect will fire every time a user shuts down or restarts their browser. You could try using chrome.management.onUninstalled. It is not supported for your own extension but I recall reading that it worked for someone.

https://code.google.com/chrome/extensions/management.html#event-onUninstalled

Abraham
--
Abraham Williams | InboxQ | abrah.am | abraham+
@abraham | github.com/abraham | blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


cetioren

unread,
Mar 12, 2012, 7:19:44 PM3/12/12
to Chromium-extensions
Thanks for the answer Abraham.

I tested for this. Closing tabs, moving tabs around, closing the
browser, restarting the browser don't fire the port.onDisconnect
event. So it's definitely something else.
The only thing that fires the port.onDisconnect event for me (once for
every open tab) is disabling or uninstalling the extension so I can't
explain why I am seeing this behavior from users.

Yes, unfortunately the management API only works for other extensions
so it's useless.

I do appreciate you taking the time to answer though. If you can think
of anything else, please let me know.



On Mar 12, 9:57 am, Abraham Williams <4bra...@gmail.com> wrote:
> I believe port.onDisconnect will fire every time a user shuts down or
> restarts their browser. You could try
> using chrome.management.onUninstalled. It is not supported for your own
> extension but I recall reading that it worked for someone.
>
> https://code.google.com/chrome/extensions/management.html#event-onUni...
>
> Abraham
> --
> Abraham Williams | InboxQ <http://inboxq.com/> | abrah.am |
> abraham<https://plus.google.com/114233674199568482864>
> +
> @abraham <https://twitter.com/intent/follow?screen_name=abraham> |
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.
Reply all
Reply to author
Forward
0 new messages