Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension : How to handle disable and enable event from browser

Is there a way to run a callback after extension is disabled/enabled from chrome browser.

like image 889
Raghvendra Parashar Avatar asked Dec 20 '12 20:12

Raghvendra Parashar


1 Answers

Chrome management API()'s

  • chrome.management.onEnabled.addListener(function(ExtensionInfo info) {})

  • chrome.management.onDisabled.addListener(function(ExtensionInfo info) {})

notifies changes of enable and disable of extensions.

Ensure you have

"permissions": [
    "management"
  ],

in your manifest.json

Sample Demonstration

chrome.management.onDisabled.addListener(function(ExtensionInfo) {
    console.log(JSON.stringify(ExtensionInfo));
});

P.S : An extension on its own can't monitor when it gets disabled. You'd need a second extension to monitor this. From extension's and user's perspectives, disabling extension has exactly the same effect as closing a browser.

For more information refer documentation.

like image 68
Sudarshan Avatar answered Sep 25 '22 01:09

Sudarshan