Install Firefox OS Apps on Any Domain


The app store models we've grown up with suck:  you have to install apps from within those stores.  With iOS you go to a site, they provide a link to install their app, and you get swapped from the browser to the App store.  What an awful user experience.  The brilliant minds at Mozilla have found the solution to this annoying problem:  an installation system via the browser.  Let me show you how you can install your Firefox app outside of the Firefox Marketplace.

Part One:  app.manifest

Every Firefox OS app requires an app.manifest file and one of the manifest keys isinstalls_allowed_from, an array of hostnames which the app may be installed from:
{
  "version": "0.1",
  "name": "My App",
  "description": "My new awesome Open Web App",
  "developer": {
    "name": "Your Name",
    "url": "http://yourawesomeapp.com"
  },
  "installs_allowed_from": [
    "https://marketplace.mozilla.org",
  "http://davidwalsh.name"
  ]
}
Add the domain(s) you'd like to the installs_allowed_from array and you're golden.  Note that if you set the value of installs_allowed_from to ["*"], the app can be installed from any domain.

Part Two:  navigator.mozApps.install

The navigator.mozApps.install method triggers an installation of a web app on desktop or mobile device:
var manifestLocation = "http://davidwalsh.name/manifest.webapp"; // your domain here
var installRequest = navigator.mozApps.install(manifestLocation);

installRequest.onsuccess = function(data) {
    // App installed successfully!
};

installRequest.onerror = function(err) {
    // App couldn't be installed!
    console.log("Install error!");
};
The install method accepts a URL to the app's manifest.  The resulting object providesonsuccess and onerror callbacks to allow developers to respond to the result (i.e. hide the install button or display the install error).
The ability to install a Firefox OS app from any domain is a bonus you haven't gotten with iOS; this META tag is the closest you'll get.  Create a compatible app.manifest file and utilize navigator.mozApps.install to install your app from any qualifying domain.  Isn't Firefox OS' app install model beautiful?
credits: David Walsh

0 comments