3

Is there an API call allowing one to enable/disable a Firefox add-on?

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
DVK
  • 126,886
  • 32
  • 213
  • 327

2 Answers2

5

Starting from Firefox 4, this can be done via AddonManager.

For instance, to disable an add-on:

AddonManager.getAddonByID(id, function(addon) {
    addon.userDisabled = true;
});

To support both Gecko <= 1.9.1 and > 1.9.1:

var man = Components.classes["@mozilla.org/extensions/manager;1"];
if (man) {
    man = man.getService(Components.interfaces.nsIExtensionManager);
}
if (man) {
    man.disableItem(id);
} else {
    Components.utils.import("resource://gre/modules/AddonManager.jsm");
    AddonManager.getAddonByID(id, function(addon) {
        addon.userDisabled = true;
    });
}
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
1

You want to use the nsIExtensionManager interface.

sdwilsh
  • 4,674
  • 1
  • 22
  • 20
  • It looks like that link is broken now, but it is somewhat described on [this page](https://developer.mozilla.org/en/Enhanced_Extension_Installation#Little_Things_This_Upgrade_Fixes_or_Changes). Bear in mind that this is not compatible with Fx 4. – Paul Lammertsma Nov 28 '10 at 02:09
  • (and too bad I cannot delete an accepted answer that is my own) – sdwilsh Dec 01 '10 at 18:55