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

659 views
Skip to first unread message

mo

unread,
Nov 2, 2011, 4:25:32 AM11/2/11
to Chromium-extensions
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;
}

Ben

unread,
Nov 2, 2011, 9:14:10 PM11/2/11
to mo, Chromium-extensions
You should extend that test a bit:

if (!localStorage["isInstalled"]) {
onInstall();
localStorage["isInstalled"] = 1;

} else {
/* code to run when extension is re-enabled */
onEnable();

mo

unread,
Nov 2, 2011, 10:24:27 PM11/2/11
to Chromium-extensions
Hi Ben,
Unfortunately, onEnable() will also run when the browser is closed and
reopened in your code.

I'm wondering if it's possible to only run onEnable after the
extension has been disabled and then re-enabled again.

mo

unread,
Nov 2, 2011, 10:24:56 PM11/2/11
to Chromium-extensions
k

On Nov 2, 9:14 pm, Ben <benjo...@gmail.com> wrote:

Devin

unread,
Nov 3, 2011, 11:04:25 AM11/3/11
to Chromium-extensions
I'm planning on building easier enable/disable functionality within my
app itself - independent of chrome enable/disable functionality, you
might also be interested in this too though it is more work.

-Devin
Reply all
Reply to author
Forward
0 new messages