Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Web apps are apps built using standard Web technologies. They work in any modern Web browser, and can be developed using your favorite tools. Some characteristics that distinguish Web apps from websites: Apps are installed by a user, they are self-contained and don't always require the chrome of a browser window, and they can be built to run offline. Gmail, Twitter, and Etherpad are Web apps.

The Mozilla Open Web Apps project proposes some small additions to existing sites to turn them into apps that run in a rich, fun, and powerful computing environment. These apps run on desktop browsers and mobile devices, and are easier for a user to discover and launch than Web sites. They have access to a growing set of novel features, such as synchronizing across all of a user's devices.

Before you start

If you are a first time developer looking to write web apps then you may want to verify the implementation state of the API.

Publishing the app

The only thing you have to do to create a Web app from a Web site is to add an app manifest. This is a JSON file that describes your app, including its name, its icons, and a human-readable description.

The manifest must be hosted from the same domain as your website, and must be served with a Content-Type of application/x-web-app-manifest+json (Note: this is currently not enforced by Firefox, but it is necessary for the Firefox Marketplace). For full details about the manifest refer to the app manifest documentation. There are tools to check your manifest for validity. See Validating a manifest.

Same origin policy

It's important to note that each app should be hosted from its own domain. Different apps should not share the same domain. An acceptable solution is to host each app from a different subdomain, for example. See FAQs about apps manifests for more information on origins.

Checking whether the app is installed

When a Web browser loads the app's page, the page needs to handle the case that the user doesn't have the app installed. You can check whether the app is installed by calling checkInstalled(), like this:

var request = navigator.mozApps.checkInstalled("https://path.to/my/example.webapp");
request.onsuccess = function() {
  if (request.result) {
    // we're installed
  } else {
    // not installed
  }
};
request.onerror = function() {
  alert('Error checking installation status: ' + this.error.message);
};

For another way to check this, see Navigation.

Installing the app

You can distribute your app directly from your site. It's also a good idea to test installing from your site, just to make sure your manifest validates, before you submit it to the Firefox Marketplace.

Just construct a button or link that invokes this JavaScript:

var request = navigator.mozApps.install("https://path.to/my/example.webapp");
request.onsuccess = function() {
  // great - display a message, or redirect to a launch page
};
request.onerror = function() {
  // whoops - this.error.name has details
};

Invoking navigator.mozApps.install() causes the browser to load the manifest (i.e. example.webapp) and ask the user whether to install the application. If the user approves the installation, the app is installed into the browser. On OS X, application will be installed in the "Applications" folder.

The second parameter is an install_data argument to navigator.mozApps.install(), to persist some information into the user's installed-applications data store. This information can be synchronized to their other devices, and can be retrieved by your application using the getSelf() call (see Checking whether the app is installed). For example:

navigator.mozApps.install(
    "https://path.to/my/example.webapp",
    {
        user_id: "some_user"
    }
);

Promoting the app

Mozilla is building an app marketplace that takes care of discovery, reviews, ratings, and billing, using an open infrastructure that can be used by other third parties to create their own stores. But you're not required to list your app in a store.

If you want people to pay for your app, see Marketplace payments.

The Firefox Marketplace is expected to be available soon. You can also sign up for the Apps Developer newsletter to get news about the progress of the Firefox Marketplace, as well as tips and advice on creating apps.

Running offline and using advanced device APIs

Modern Web browsers have added a lot of great features to let your application run offline or access device capabilities. Here are some useful links:

Storing data locally

The localStorage API provides a key-value store of persistent data that you can use to keep track of user data between visits to your app. If the user has a modern browser, such as Firefox 4 or later, or Google Chrome, you can also use IndexedDB, a structured, high-performance client-side datastore.

If you have data that should be shared between instances of your app across all devices that a user uses, then you should use the install_data parameter to the install() function, as described above.

Examples

Some examples of open web apps:

See also