Firefox OS – A primer

I’ve decided that for those of you who are interested, and perhaps those of you considering a new project for your subsequent releases, I’ll be writing a brief summary of the Firefox OS project, the various components thereof, and how to set up the test environment for each relevant platform (I’ll be using an x86 Boot2Gecko emulator on Windows, a Firefox browser extension, and the “Keon” developer preview phone). I’ve also got some bad news to relate about the status of one of my bugs! It’ll serve as a warning to those of you that like leaving assignments to the last minute 😛

Firefox OS is an open source mobile operating based on the Linux kernel and Mozilla’s Gecko web rendering engine. Essentially, the entire OS is contained in a stripped down web browser, which means that FFOS applications are coded using web standards like HTML5 and JavaScript in patterns that should be familiar to web developers. What are the benefits to this approach? Rapid iteration and prototyping spring to mind immediately; using a JavaScript interpreter of course means that there is no compilation process that needs to take place before an application is run. Like web development, changes to views can be evaluated almost instantly. Another benefit to this approach is, similar to Java, very portable code. JavaScript virtual machines need to be tailored to individual processor implementations, but the application code is identical across platforms (more or less, since styling may need to be device specific).

Firefox OS has two main repositories: the Boot2Gecko rendering engine implementation, and the “Gaia” OS UI, which is of course written in HTML5 and JS. There are also a number of device specific B2G repos and dev tool repos available through Mozilla’s mozilla-b2g GitHub profile.

Because of this system architecture, we’re able to test FFOS applications within the Firefox browser! There is an extension named Firefox OS Simulator (the latest version can be found here) which allows developers to test their apps in browser on any operating system capable of running Firefox 26. This simulator is compatible with Firefox’s web development tools, and actually includes a few features (such as the screen orientation and geolocation buttons) which are not available on the usual desktop build of B2G. Simply install the .xsi file at the link above to install the add-on; navigate to about:app-manager and the “Start simulator” button should be visible at the bottom of the page.

The app manager page

The app manager page

After starting the simulator, start the appropriate build (only 1.2 is stable at the moment)…

Button to start simulator

…circled above…

…and the simulator should be up and running.

Firefox OS Simulator screen-cap

It’s beauuuuuuutiful.

The simulator’s actually pretty interesting. The App list can be populated by hosted applications (using a URL) or by packaged applications (using a local directory identifier). Sadly, the simulator can only be used to test applications; testing Gaia requires either Firefox Nightly with the appropriate profile or…. drum roll please….. an x86 B2G emulator!

Nightly builds of B2G desktop can be found here. I’m going to be using the Linux 64bit version, as getting anything related to FFOS working under Windows was a supreme headache, and frankly was not worth the effort. To make a long story short, the make commands in Cygwin and MinGW are nowhere near as flexible as the make command under Linux, in that they were unable to work with the heavy use of JS within Gaia’s makefile. Anyway, once you’ve downloaded the appropriate version (depends on which release you want to debug – I have a bug that I’m working on which is 1.1 specific), simply extract the folder and run the b2g binary. By default, the version of Gaia included in the archive will be used, but the binary takes a command line argument which will target another local copy of the Gaia directory (more on that later). Otherwise, the emulator is ready to go!

Finally, Firefox Nightly can be configured to run a local Gaia profile for quick testing and debugging. This works in a similar manner to the above B2G emulator retarget. In both cases, navigate to the root of the Gaia directory that you’re working on, and run the command “DEBUG=1 make” for Firefox Nightly or “DEBUG=1 DESKTOP=0 make” for B2G desktop. This creates a profile folder that can be used by both Firefox Nightly and B2G Desktop (the path is the same for both makes, and is displayed right at the end of the command’s output); the next step in both cases is to start the respective binaries with the argument “-profile /path/to/profile”, and your changes should be visible as you navigate the UI.

Finally, a warning: Firefox OS moves quickly. In a matter of days, my first assigned bug was incidentally resolved by someone else’s work on another, lower-level problem (my original bug, and the one that invalidated it). Work fast if you want your contributions to be valid/noticed! On a lighter note, I’ll be following this up shortly with my first release post!

6 thoughts on “Firefox OS – A primer

    • I may be wrong, but I don’t think screen rotation is supported in B2G Desktop at the moment. You’ll either have to use the Simulator add on, or test on an actual device.

      • Thanks. Today I found a way to emulate different screens.
        ./b2g-bin –profile ./gaia/profile/ –screen=ipad
        You have to use a profile and the b2g-bin command instead of b2g alone

Leave a comment