Add-ons

Accounts.jsm

Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions.

Starting from Firefox 53, no new legacy add-ons will be accepted on addons.mozilla.org (AMO) for desktop Firefox and Firefox for Android.

Starting from Firefox 57, only extensions developed using WebExtensions APIs will be supported on Desktop Firefox and Firefox for Android.

Even before Firefox 57, changes coming up in the Firefox platform will break many legacy extensions. These changes include multiprocess Firefox (e10s), sandboxing, and multiple content processes. Legacy extensions that are affected by these changes should migrate to use WebExtensions APIs if they can. See the "Compatibility Milestones" document for more information.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

The Accounts object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

Mobile Only in Gecko 33
Available only in Firefox Mobile as of Gecko 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30)

Summary

The Accounts API lets you check whether a Firefox Account or a legacy Sync account is currently present on the device, and to start the Firefox Account set-up process if an account is not present. Accounts is a single object that provides a Promise-based API.

Method Overview

Promise anySyncAccountsExist()
Promise firefoxAccountsExist()
Promise syncAccountsExist()
void launchSetup(in object extras)

Methods

anySyncAccountsExist()

Ask whether a Firefox Account or a legacy Sync account exists on the device.

Promise anySyncAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if either a Firefox Account or a legacy Sync account exists, false otherwise.

firefoxAccountsExist()

Ask whether a Firefox Account exists on the device.

Promise firefoxAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if a Firefox Account exists, false otherwise.

syncAccountsExist()

Ask whether a legacy Sync account exists on the device.

Promise syncAccountsExist()
Return value

Returns a Promise that resolves to a boolean, true if a legacy Sync account exists, false otherwise.

launchSetup(in object extras)

Launch the Firefox Account set-up wizard.

void syncAccountsExist(extras)
Parameters
extras
Extra options to pass to the set-up wizard. Currently, extras can be used to specify custom Firefox Account and Sync token server URLs. See the examples for details.

Examples

To query for accounts and launch the set-up wizard if no account exists:

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

Accounts.anySyncAccountsExist().then(
  (exist) => {
    console.log("Accounts exist? " + exist);
    if (!exist) {
      Accounts.launchSetup();
    }
  },
  (err) => {
    console.log("We failed so hard.");
  }
);

To launch the set-up wizard with custom Firefox Account and Sync token server URLs:

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

// These server URLs are Mozilla's stage servers and are for testing only.
let customAuthServerURL = "https://api-accounts.stage.mozaws.net/v1";
let customSyncTokenServerURL = "https://token.stage.mozaws.net/1.0/sync/1.5";

let extras = {
    auth: customAuthServerURL,
    services: {
        sync: customSyncTokenServerURL,
    },
};

Accounts.launchSetup(extras);

See also

The fxa-custom-server-addon adds a menu item that prompts for custom server URLs and then starts the Account set-up wizard with those URLs.  It is available on Github:

Document Tags and Contributors

 Last updated by: SphinxKnight,