• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
Add-ons
  1. MDN
  2. Mozilla
  3. Add-ons
  4. Browser extensions
  5. Comparison with XUL/XPCOM extensions

Comparison with XUL/XPCOM extensions

In This Article
  1. Manifest
  2. UI
  3. Privileged APIs
  4. Interacting with web content
  5. Localization
  6. Settings

This article is a technical comparison between the WebExtensions technology and "classic" extensions developed using direct XUL manipulation and direct access to XPCOM. It's intended to help orient people who maintain an add-on like this, and who are planning to port it to use WebExtension APIs.

This article covers both overlay extensions and bootstrapped extensions, but not extensions developed using the Add-on SDK. For the Add-on SDK, please see Comparison with the Add-on SDK.

At a very basic level, XUL/XPCOM extensions are similar to extensions developed with WebExtensions. They both include:

  • manifest files defining metadata for the extension and some aspects of its behavior.
  • JavaScript code that gets access to a set of privileged JavaScript APIs and that stays loaded for as long as the extension itself is enabled.
  • the ability to add specific UI elements, such as buttons, to the browser.

Beyond that, though, the systems are very different. In particular:

  • Compared with XUL/XPCOM extensions, WebExtensions provide much more limited options for the extension's UI, and a much more limited set of privileged JavaScript APIs.
  • WebExtensions can only access web content by injecting separate scripts into web pages and communicating with them using a messaging API (note, though, that this is also true of XUL/XPCOM extensions that expect to work with multiprocess Firefox).

Manifest

XUL/XPCOM extensions have two manifest files:

  • the install.rdf contains metadata about the extension such as its name, icons, and so on
  • the chrome.manifest, that tells Firefox where it can find the components of the extension, including XUL overlays for the extension's interface, scripts for its behavior, and files containing localized strings.

WebExtensions have a single manifest file called manifest.json, that has a similar purpose. You use it to specify the extension's name, description, icons, and so on, as well as to specify any buttons it adds to Firefox and to list scripts it needs to run. To get an overview of the components of an extension developed using WebExtension APIs, and how they are specified in manifest.json, see "Anatomy of an extension".

Learn more

  • manifest.json documentation
  • Anatomy of a extension

UI

XUL/XPCOM extensions can build their UI by directly manipulating the XUL used to specify the browser's own UI. They do this either using overlays or, in the case of bootstrapped/restartless extensions, using JavaScript to modify the XUL document. They can not only add any elements to the browser's UI, they can also modify or remove existing elements. They can also use APIs like CustomizableUI.jsm to build their UI.

Extensions built with WebExtension APIs don't get this kind of direct access. Instead, a combination of manifest.json keys and JavaScript APIs enable them to add a limited set of UI components to the browser. The available components are:

Name Description Specified using
Browser action Button in the browser toolbar, with an optional popup panel.

browser_action manifest key

browserAction API

Page action Button in the URL bar, with an optional popup panel.

page_action manifest key

pageAction API

Commands Keyboard shortcuts.

commands manifest key

commands API

Context menu Adds items and submenus to the browser's context menu. contextMenus API

Privileged APIs

Both XUL/XPCOM extensions and extensions built with WebExtension APIs can contain scripts that stay loaded for as long as the extension itself is enabled, and that have access to a set of privileged APIs. However, XUL/XPCOM extensions get access to a much wider range of APIs.

The scripts packaged with XUL/XPCOM extensions get access to the full set of XPCOM APIs and JavaScript code modules through the Components object. They also get direct access to the browser's internals through globals like gBrowser.

The equivalent WebExtension scripts are called background scripts, and they get access to a much smaller set of high-level JavaScript APIs. To see all the privileged APIs available to background scripts, see the summary API page. Background scripts also get a window global, with all the DOM objects that are available in a normal web page.

There are vastly more APIs available to XUL/XPCOM extensions than are available to WebExtensions, and for many XUL/XPCOM APIs, there isn't a WebExtensions substitute. The table below lists every API in the popular Services.jsm module, describe what the equivalent WebExtensions API would be, if there is one.

You'll see that many APIs have no WebExtensions equivalent yet. However we are intending to extend the WebExtension APIs to support the needs of add-on developers, so if you have ideas, we'd love to hear them. You can reach us on the dev-addons mailing list or #webextensions on IRC.

Services.jsm API WebExtensions equivalent
nsIAndroidBridge None
nsIXULAppInfo
nsIXULRuntime
None
nsIAppShellService None
nsIBlocklistService None
nsICacheService None
nsICacheStorageService None
nsIClipboard None
nsIConsoleService window.console
nsIContentPrefService None
nsICookieManager2 cookies
nsIMessageSender Content scripts
CrashManager.jsm None
nsIDirectoryService
nsIProperties
None
nsIDOMStorageManager None
nsIDOMRequestService None
nsIDownloadManager downloads
nsIDroppedLinkHandler None
nsIEventListenerService None
nsIEffectiveTLDService None
nsIFocusManager None
nsIIOService
nsIIOService2
None
nsILocaleService i18n
nsILoginManager None
nsIWinMetroUtils None
nsIMessageBroadcaster
nsIFrameScriptLoader
Content scripts
nsIObserverService None
nsIPermissionManager None
nsIMessageBroadcaster
nsIProcessScriptLoader
Content scripts
nsIPrefBranch
nsIPrefBranch2
nsIPrefService
See Settings.
nsIPromptService None
mozIJSSubScriptLoader None
nsIScriptSecurityManager None
nsIBrowserSearchService None
nsIAppStartup None
mozIStorageService storage
nsIStringBundleService i18n
nsIPropertyBag2 None
nsITelemetry None
nsIThreadManager None
nsIURIFixup None
nsIURLFormatter None
nsIVersionComparator None
nsIWindowMediator None
nsIWindowWatcher None

Learn more

  • JavaScript APIs available for extensions
  • Background scripts for extensions

Interacting with web content

Historically, XUL/XPCOM extensions have been able to get direct access to web content. For example, they can directly access and modify the page DOM using gBrowser:

gBrowser.contentWindow.document.querySelector("h1").innerHTML = "yadda yadda";

However, this is only possible in single-process Firefox. In multiprocess Firefox, web content and extension code run in different processes, so this direct access is no longer possible, and extensions which rely on it will break. Multiprocess Firefox is coming soon, and multiprocess compatibility will be a necessity.

XUL/XPCOM extensions can still interact with web content in multiprocess Firefox by refactoring the code that accesses web content into separate scripts called frame scripts, and using the message manager to communicate with these scripts. But this is complex and can involve deep changes to the extension's code.

WebExtensions are multiprocess-compatible by default: code that interacts with web content is factored into separate scripts called content scripts, that can communicate with the rest of the extension using a messaging API.

Learn more

  • Content scripts for extensions

Localization

In a XUL/XPCOM extension you handle localization by supplying DTD or properties for each supported language, and referring to them using locale statements inside the chrome.manifest. You can then include localized strings in UI elements or in code.

The general approach with WebExtensions is similar, but the details are all different. With WebExtensions you supply localized strings as a collection of JSON files, one for each locale.

To retrieve localized strings in extension code, use the i18n API.

WebExtensions don't have direct support for localizing strings appearing in HTML, so you have to do this yourself, using JavaScript to retrieve localized strings and to replace the HTML with the localized version.

Learn more

  • Extensions Internationalization guide.
  • Example internationalized extension.

Settings

XUL/XPCOM extensions typically store settings using the XPCOM preferences service or the inline options system.

With WebExtensions you write an HTML file that presents the settings UI, which can include a script for persisting the settings for your extension. The script gets access to all the WebExtensions APIs, and it's generally expected that you should use the storage API to persist settings.

You then assign the HTML file's URL to the options_ui key in manifest.json. Your settings page then appears in the extension's entry in the Add-ons Manager.  The options page can also be programmatically opened with an API call to browser.runtime.openOptionsPage.

Note that WebExtensions does not give you access to the Preferences API, so you can't directly get or set the browser's own preferences.

Learn more

  • Introduction to options pages
  • An example extension that has an options page

Document Tags and Contributors

Tags: 
  • WebExtensions
 Contributors to this page: andrewtruongmoz, wbamberg, Leif-AMO
 Last updated by: andrewtruongmoz, Jul 11, 2017, 4:23:20 PM
See also
  1. Browser extensions
  2. Getting started
    1. What are extensions?
    2. Your first extension
    3. Your second extension
    4. Anatomy of an extension
    5. Example extensions
  3. How to
    1. Intercept HTTP requests
    2. Modify a web page
    3. Add a button to the toolbar
    4. Implement a settings page
  4. User interface
    1. Introduction
    2. Toolbar button
    3. Address bar button
    4. Sidebar
    5. Context menu items
    6. Options page
    7. Bundled web pages
    8. Notifications
    9. Address bar suggestions
    10. Developer tools panels
  5. Concepts
    1. Using the JavaScript APIs
    2. Content scripts
    3. Match patterns
    4. Internationalization
    5. Content Security Policy
    6. Native messaging
  6. Porting
    1. Porting a Google Chrome extension
    2. Porting a legacy Firefox extension
    3. Embedded WebExtensions
    4. Comparison with the Add-on SDK
    5. Comparison with XUL/XPCOM extensions
    6. Chrome incompatibilities
    7. Differences between desktop and Android
  7. Firefox workflow
    1. Temporary Installation in Firefox
    2. Debugging
    3. Developing for Firefox for Android
    4. Getting started with web-ext
    5. web-ext command reference
    6. Extensions and the Add-on ID
    7. Publishing your extension
  8. JavaScript APIs
    1. Browser support for JavaScript APIs
    2. alarms
    3. bookmarks
    4. browserAction
    5. browsingData
    6. commands
    7. contextMenus
    8. contextualIdentities
    9. cookies
    10. devtools.inspectedWindow
    11. devtools.network
    12. devtools.panels
    13. downloads
    14. events
    15. extension
    16. extensionTypes
    17. history
    18. i18n
    19. identity
    20. idle
    21. management
    22. notifications
    23. omnibox
    24. pageAction
    25. permissions
    26. privacy
    27. proxy
    28. runtime
    29. sessions
    30. sidebarAction
    31. storage
    32. tabs
    33. topSites
    34. types
    35. webNavigation
    36. webRequest
    37. windows
  9. Manifest keys
    1. applications
    2. author
    3. background
    4. browser_action
    5. chrome_settings_overrides
    6. chrome_url_overrides
    7. commands
    8. content_scripts
    9. content_security_policy
    10. default_locale
    11. description
    12. developer
    13. devtools_page
    14. homepage_url
    15. icons
    16. incognito
    17. manifest_version
    18. name
    19. omnibox
    20. optional_permissions
    21. options_ui
    22. page_action
    23. permissions
    24. protocol_handlers
    25. short_name
    26. sidebar_action
    27. version
    28. web_accessible_resources
  10. Themes
  11. Publishing add-ons
  12. Guides
    1. Signing and distribution overview
    2. Submit an add-on
    3. Creating an appealing listing
    4. Review policies
    5. Developer agreement
    6. Featured add-ons
    7. Contact addons.mozilla.org
  13. Community and support
  14. Channels
    1. Add-ons blog
    2. Add-on forums
    3. Stack Overflow
    4. Development newsgroup
    5. IRC Channel
  15. Legacy add-ons
  16. Legacy technologies
    1. Add-on SDK
    2. Legacy Firefox for Android
    3. Bootstrapped extensions
    4. Overlay extensions