Is there a way for a Safari browser extension to detect its own uninstallation?
I would like to send an event to Google Analytics to keep track of the uninstallment rate of my extension.
Is there a way for a Safari browser extension to detect its own uninstallation?
I would like to send an event to Google Analytics to keep track of the uninstallment rate of my extension.
After crawling around on the development forums, I found out that apparently Safari has no such events (unlike Chrome) or if there are any, they are undocumented (and therefore not meant to be used). I think your best bets are:
a) Request the feature via Apple's bug-reporting and feature-requesting site
b) Set up an external service that can monitor ~/Library/Safari/Extensions or the Extensions.plist file for deletion (which is probably enormously difficult, considering the security risks)
c) Keep track of the active user base instead by pinging an external service once a day or on some other interval. The deletion/inactivity rate can then be estimated by drops in activity.
You can register the window.onunload event in the global file script to detect when extension is uninstalled. Better to use addEventListener() with 'unload' as safari could be using the event to clear extension storage. Also make sure to detect if the event is firing in case of extension update or reload because in these cases the global page is unloaded as well.
window.addEventListener("unload", function() {
//handle uninstall event
});