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

后端 未结 1 740
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 15:58

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

相关标签:
1条回答
  • 2021-01-02 16:16

    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.

    0 讨论(0)
提交回复
热议问题