I have one extension in Firefox and one in Chrome. I want to call a javascript function when installing or uninstalling the extension. It is possible in any of those browsers?
Asked
Active
Viewed 1,157 times
1 Answers
2
Firefox
- Detecting installation is already covered in this answer: Firefox extension opening a page on install
- Sample code to listen for uninstallation of the add-on (using the
AddonManager
API)
Google Chrome
In Chrome, there are no built-in methods to detect installation or uninstallation.
One can check whether a
localStorage
flag on the background page exists, and act on that.if (!localStorage.getItem('my-extension-first-time')) { // Do something alert('Hello first timer!'); // Set flag localStorage.setItem('my-extension-first-time', true); }
- There's no way to listen for the uninstallation of itself.
- The
chrome.management
API can be used to monitor external extension (un)installations.