Search code examples
google-chromegoogle-chrome-extension

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.


Solution

  • Chrome management API()'s

    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.