Developing for Firefox Mobile

Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions.

Starting from Firefox 53, no new legacy add-ons will be accepted on addons.mozilla.org (AMO) for desktop Firefox and Firefox for Android.

Starting from Firefox 57, WebExtensions will be the only supported extension type. Desktop Firefox and Firefox for Android will not load other extension types.

Even before Firefox 57, changes coming up in the Firefox platform will break many legacy extensions. These changes include multiprocess Firefox (e10s), sandboxing, and multiple content processes. Legacy extensions that are affected by these changes should migrate to WebExtensions if they can. See the "Compatibility Milestones" document for more information.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

See Developing WebExtensions for Firefox for Android to learn more about development of WebExtensions for Firefox for Android.

To follow this tutorial you'll need to have learned the basics of jpm.

Firefox for Android implements its UI using native Android widgets instead of XUL. With the add-on SDK you can develop add-ons that run on this new version of Firefox Mobile as well as on the desktop version of Firefox.

You can use the same code to target both desktop Firefox and Firefox Mobile, and use jpm-mobile instead of the normal jpm.

Right now not all modules are fully functional, but we're working on adding support for more modules. The tables at the end of this guide list the modules that are currently supported on Firefox Mobile.

This tutorial explains how to run SDK add-ons on an Android device connected via USB to your development machine. We'll use the Android Debug Bridge (adb) to communicate between the Add-on SDK and the device.

It's possible to use the Android emulator to develop add-ons for Android without access to a device, but it's slow, so for the time being it's much easier to use the technique described below.

Setting up the Environment

First you'll need an Android device capable of running the native version of Firefox Mobile. Then:

On the development machine:

  • install version 1.5 or higher of the Add-on SDK
  • install the correct version of the Android SDK for your device
  • using the Android SDK, install the Android Platform Tools

Next, attach the device to the development machine via USB.

Now open up a command shell. Android Platform Tools will have installed adb in the "platform-tools" directory under the directory in which you installed the Android SDK. Make sure the "platform-tools" directory is in your path. Then type:

adb devices

You should see some output like:

List of devices attached
51800F220F01564 device

(The long hex string will be different.)

If you do, then adb has found your device and you can get started.

Running Add-ons on Android

You can develop your add-on as normal, as long as you restrict yourself to the supported modules.

When you need to run the add-on, first ensure that Firefox is not running on the device. Then execute jpm-mobile run with some extra options:

jpm-mobile run --adb /path/to/adb

In the command shell, you should see something like:

Launching mobile application with intent name org.mozilla.fennec
Pushing the addon to your device
Starting: Intent { act=android.activity.MAIN cmp=org.mozilla.fennec/.App (has extras) }
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
Could not read chrome manifest 'file:///data/data/org.mozilla.fennec/chrome.manifest'.
info: starting
info: starting
zerdatime 1329258528988 - browser chrome startup finished.

This will be followed by lots of debug output.

On the device, you should see Firefox launch with your add-on installed.

console.log() output from your add-on is written to the command shell, just as it is in desktop development. However, because there's a lot of other debug output in the shell, it's not easy to follow. The command adb logcat prints adb's log, so you can filter the debug output after running the add-on. For example, on Mac OS X or Linux you can use a command like the one below to filter only the lines of console output:

adb logcat | grep console

You can experiment with different filter strings on adb logcat to focus in on the lines relevant to you.

Running jpm-mobile test is identical:

jpm-mobile test --adb /path/to/adb

Packaging Mobile Add-ons

To package a mobile add-on as an XPI, use the command:

jpm xpi

Actually installing the XPI on the device is a little tricky. The easiest way is probably to copy the signed XPI somewhere on the device:

adb push my-addon.xpi /mnt/sdcard/

Then open Firefox Mobile and type this into the address bar:

file:///mnt/sdcard/my-addon.xpi

The browser should open the XPI and ask if you want to install it.

Afterwards you can delete it using adb as follows:

adb shell
cd /mnt/sdcard
rm my-addon.xpi

Module Compatibility

Modules not supported in Firefox Mobile are marked in the tables below.

High-Level APIs

addon-page Not supported
base64 Supported
clipboard Not supported
context-menu Not supported
hotkeys Supported
indexed-db Supported
l10n Supported
notifications Supported
page-mod Supported
page-worker Supported
panel Not supported
passwords Supported
private-browsing Not supported
querystring Supported
request Supported
selection Not supported
self Supported
simple-prefs Supported
simple-storage Supported
system Supported
tabs Supported
timers Supported
ui Not supported
url Supported
widget Not supported
windows Supported

Low-Level APIs

/loader Supported
chrome Supported
console/plain-text Supported
console/traceback Supported
content/content Supported
content/loader Supported
content/mod Supported
content/worker Supported
core/heritage Supported
core/namespace Supported
core/promise Supported
event/core Supported
event/target Supported
frame/hidden-frame Supported
frame/utils Supported
io/byte-streams Supported
io/file Supported
io/text-streams Supported
lang/functional Supported
lang/type Supported
loader/cuddlefish Supported
loader/sandbox Supported
net/url Supported
net/xhr Supported
places/bookmarks Not supported
places/favicon Not supported
places/history Not supported
platform/xpcom Supported
preferences/service Supported
stylesheet/style Supported
stylesheet/utils Supported
system/environment Supported
system/events Supported
system/runtime Supported
system/unload Supported
system/xul-app Supported
tabs/utils Supported
test/assert Supported
test/harness Supported
test/httpd Supported
test/runner Supported
test/utils Supported
ui/button/action Not supported
ui/button/toggle Not supported
ui/frame Not supported
ui/id Supported
ui/sidebar Not supported
ui/toolbar Not supported
util/array Supported
util/collection Supported
util/deprecate Supported
util/list Supported
util/match-pattern Supported
util/object Supported
util/uuid Supported
window/utils Supported

 

Document Tags and Contributors

Tags: 
 Contributors to this page: Rob W, wbamberg, creesch, carlsmith, maybe, jsantell, Canuckistani
 Last updated by: Rob W,