Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if a Chrome Extension has been enabled (after having been disabled)

Let's say a user disables my extension and then later enables it.

How can I run a function when the extension gets re-enabled?

I tried doing something akin to running a function on-extension-install, using localStorage, but it does not appear to work for this on-extension-reenabled case because localStorage doesn't get cleared for the background-page when it is disabled.

if (!localStorage["isInstalled"]) {
onInstall();
localStorage["isInstalled"] = 1;
}
like image 899
Robert Bana Avatar asked Nov 02 '11 08:11

Robert Bana


People also ask

Can Chrome extensions be tracked?

A researcher has found a way to generate a fingerprintof your device from your installed Google Chrome extensions, and then use that fingerprint to track you online. Fingerprinting is a way of figuring out what makes your device unique and then using that to identify you as you move around the internet.


2 Answers

An extension on its own can't monitor when it gets disabled. You'd need a second extension to monitor this.

As a slight alternative, you could use sessionStorage["isInstalled"] = 1;, which would get cleared if the extension was disabled, but this would also be cleared if the user exited Chrome.

like image 191
Chris McFarland Avatar answered Nov 03 '22 17:11

Chris McFarland


Have a look at the management API, which lets you respond to events like onEnabled, firing when an app or extension has been enabled.

like image 24
Boris Smus Avatar answered Nov 03 '22 17:11

Boris Smus