Install Firefox OS Apps on Any Domain

By  on  

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:  manifest.webapp

Every Firefox OS app requires an manifest.webapp file and one of the manifest keys is installs_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",
  "https://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 = "https://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 provides onsuccess 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 manifest.webapp file and utilize navigator.mozApps.install to install your app from any qualifying domain.  Isn't Firefox OS' app install model beautiful?

Recent Features

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    Add Site Screenshots for External Links Using MooTools Tooltips

    Before you send your user to an unknown external website, why not provide them a screenshot of the site via a tooltip so they may preview the upcoming page? Here's how you can do just that using MooTools. The MooTools JavaScript The first step is to grab...

  • By
    PHP IMDB Scraper

    It's been quite a while since I've written a PHP grabber and the itch finally got to me. This time the victim is the International Movie Database, otherwise known as IMDB. IMDB has info on every movie ever made (or so it seems). Their...

Discussion

  1. Bob

    I think you’re trying to hard to sell us on this.

  2. bobby

    Bob it a little thing called passion. Don’t worry its a new concept, you’ll pick up on it sooner or later.

  3. If your app is not paid-for, then you should allow it to spread and be incorporated into other app stores and platforms in the open ecosystem by setting install_allowed_from to * or omitting it entirely.

    Gerv

  4. Tiago Celestino

    Can I develop app in localhost? How to config .manifest?

  5. Note that at least for free apps, the official advice is nowadays to omit “installs_allowed_from” completely, which implied the [“*”] setting. Why specify it when you allow everyone to install it freely? ;-)

  6. I would like to ask where is the best location to put the “navigator.mozApps.install” method? Let just say I have 15 static page, do I have to insert the “navigator.mozApps.install” method on every page?

  7. You can place that in an external “.js” file and include that on every page.

    • Hi David, I don’t really get part 2. Could you make a demo out of it? Will be a great help for me. Thanks.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!