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.

Marketplace feature removal
The functionality described on this page no longer works — Firefox Marketplace has discontinued support for Android, Desktop, Tablets, and payments (and other related functionality). For more information, read the Future of Marketplace FAQ.

Summary

Returns information about the calling app, if any. You can use this to determine if an app is installed (i.e. if it is running in the browser, or in a separate app context.)

Note: Installable open web apps used to have a "single app per origin" security policy, but this was lifted as of Firefox 34/Firefox OS 2.1 (read this FAQ entry for more information). If you still need to support older versions, consider hosting your apps at separate origins; one strategy is to create different subdomains for your apps.

Syntax

var request = window.navigator.mozApps.getSelf();

Return value

getSelf() returns a DOMRequest object. When the success event is fired against the DOMRequest the DOMRequest.result field contains either an App object representing the current app, or a null if getSelf() was called outside of an app (meaning the app is not installed). Before the operation is finished, DOMRequest.result is null.

If the call is not successful, an error event is fired against the DOMRequest and DOMRequest.error contains a DOMError object, which has information about the error.

Example

An example that shows how to use getSelf() with the DOMRequest.onsuccess and DOMRequest.onerror callback properties.

var request = window.navigator.mozApps.getSelf();
request.onsuccess = function() {
  if (request.result) {
    // Pull the name of the app out of the App object
    alert("Name of current app: " + request.result.manifest.name);
  } else {
    alert("Called from outside of an app");
  }
};
request.onerror = function() {
  // Display error name from the DOMError object
  alert("Error: " + request.error.name);
};

If the call is successful an App object is returned in the result property of the returned object. In this example this is request.result. If request.result is null, you know the app is not installed.

If your app changes its protocol between HTTP and HTTPS, then it is better to use navigator.mozApps.checkInstalled() to check if it is installed.

Document Tags and Contributors

 Last updated by: chrisdavidmills,