Add-on Manager

The Add-on Manager is responsible for managing all of the add-ons installed in the application. Through its APIs information about all installed add-ons can be retrieved and new add-ons can be installed. The APIs are designed to be generic and support many different types of add-ons.

Many functions in the Add-on Manager interface operate asynchronously returning results through callbacks passed to the functions. The callbacks may be called immediately while the initial function is still executing or shortly after, depending on when the requested data becomes available.

Accessing installed add-ons

Information about installed add-ons can be retrieved through the main AddonManager API. All of its functions are asynchronous, meaning that a callback function must be passed to receive the Addon instances. The callback may well only be called after the API function returns. For example:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getAllAddons(function(aAddons) {
  // Here aAddons is an array of Addon objects
});
// This code will execute before the code inside the callback

Notifications about changes to installed add-ons are dispatched to any registered AddonListeners. They must be registered through the AddonManager.addAddonListener() method.

Installing new add-ons

New add-ons can be installed by using the AddonManager.getInstallForFile() or AddonManager.getInstallForURL() methods on the AddonManager object. These will pass an AddonInstall instance to the callback, which can then be used to install the add-on:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getInstallForURL("http://www.foo.com/test.xpi", function(aInstall) {
  // aInstall is an instance of AddonInstall
  aInstall.install();
}, "application/x-xpinstall");

The progress of AddonInstalls can be monitored using an InstallListener. A listener can be registered either for a specific install using the AddonInstall.addListener() method or for all installs using the AddonManager.addInstallListener() method.

Finding updates

Add-ons can be checked for updates using the Addon.findUpdates() method. It must be passed an UpdateListener to receive information about compatibility information and new update information. Any available update is returned as an AddonInstall which is ready to be downloaded and installed.

(Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)

Detecting add-on changes

You can also get lists of add-ons that, at startup, were changed in various ways. The AddonManager.getStartupChanges() method lets you find out which add-ons were installed, removed, updated, enabled, or disabled at application startup.

For example, to take a look at the add-ons that were disabled at startup:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

let addonIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_DISABLED);
if (addonIDs.length > 0) {
  // addonIDs is now an array of the add-on IDs that have been disabled
alert("Note: " + addonIDs.length + " add-ons have been disabled.");
} 

Open Add-on Manager Tab

The add-on manager tab can be opened programatically with the function BrowserOpenAddonsMgr which is availble on chrome window of "navigator:browser" type. You can pass the url to a page in the add-on manager tab to load that page.

Read more about it at this topic here on Mozilla Add-ons Forum :: How to open an add-on's preference panel? and also here MDN :: Inline options - Opening Inline Options in Add-on Manager. These pages show you how to load pages such as services page etc.

See also

Document Tags and Contributors

Last updated by: SandyZoo,
Hide Sidebar