26
May
11

Detecting extension uninstallations on Chrome

Google Chrome, unlike Firefox, doesn’t allow to detect when the user uninstalls the extension, which is quite useful to understand user behaviour. There is a feature request on crbug.com with a discussion of this feature but it hasn’t been implemented yet.

At InvisibleHand we are really trying to understand user behaviour to improve our extension. In particular, we run A/B tests of our extension to track whether new features make the users to uninstall InvisibleHand less or more. To track the uninstallations in a fairly hacky way, we inject this piece of code as a content script into every single page:

var iFrameId = 'invisiblehand-uninstallation-notifier';
var silenceCount = 0;
var maxSilence = 3;

var timer = setInterval(function() {
  chrome.extension.sendRequest({topic: "heartbeat"}, function(reply) {
    if (reply && reply.alive)
      silenceCount = 0; // we want 3 consecutive silence events just to be sure
    else
      silenceCount++;
    if (silenceCount < maxSilence) return;
    clearInterval(timer);
    if (document.getElementById(iFrameId)) return;
    var iframe = document.createElement("iframe");
    iframe.id = iFrameId;
    iframe.src = "http://productsiframe.invisiblehand.co.uk/uninstall";
    iframe.style.display = "none";
    document.body.insertBefore(iframe, document.body.firstChild);
  })
}, 1000);

This code tries to connect to the background page every second and if it fails (when it fails, the callback is still called but the reply is undefined), we assume the extension was disabled or uninstalled, so we inject an invisible iframe into the current page to notify our server about the uninstall. It’s the server’s responsibility to count only one uninstall per user since there is a high probability that this code will be executed in every open tab. However, it’s not of utmost important to us since we’re tracking not the absolute number of uninstalls but a relative change.

However, there is a big problem with this piece of code apart from it being very hacky. Several users reported that it leaks memory and the tabs with this code running that are left open in background can leak hundreds of MBs of memory. We found it hard to reproduce it but it looks like the issue is only present on the version 11 and not present on version 12 of Google Chrome. Furthermore, some users have reported InvisibleHand crashing a lot when this code was deployed. Again, we were unable to reproduce it reliably but I tend to believe this setInterval() has something to do with memory leaks and crashes.

We usually deploy this code only for short periods of time (hours) to run a specific A/B test and roll it back (release a new version without this content script) as soon as possible. I’m really looking to the day when it’ll be possible to listen for the uninstallation event.

If you know why this code may be causing memory leaks and/or crashes, please let me know in the comments.

Advertisement

1 Response to “Detecting extension uninstallations on Chrome”


  1. 1 Andrey Vyrvich
    May 27, 2011 at 12:09 am

    at this case you can use

    var port = chrome.extension.connect();
    port.onDisconnect.addListener(function(){
    #TaDa!
    })


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.