Over the past few weeks I've been doing a bit more with Firefox OS. While it's a
fun platform to hack on with almost zero platform knowlege (it's just the web,
mostly), it gets better with a few tips:
1) Use the Firefox Developer tools for certified apps:
It's possible to hack on gaia (the
Firefox OS frontend) with just your text editor of choice and
adb logcat -
but you probably don't want to do that.
If you've tried writing your own WebApps for Firefox OS, you've probably
come across the App Manager
(if not, you should probably give it a try).
And heres the tip, you're not restricted to using App Manager for the apps
you write; you can also debug certified apps by setting some prefs in your
You can also enable this by default with a build option that we'll cover in
2) Use the Firefox Developer tools to debug the main process:
The above works for all applications on the device... but what if you want
to get to bits of the actual runtime? Well you can do this too. Follow the
same steps as above, but this time use Firefox with the
devtools.chrome.enabled pref set to
Connect to your device (using the App Manager) and on the Device screen,
you'll see a "DEBUG MAIN PROCESS" button; click that and you can debug
JSMs, run privileged JS in the scratchpad, accidentally destroy your device,
3) Some convenient defaults
Running through the first time use setup every time you push a new version
of gaia to a device can be a drag, and having to configure wifi, and setting
the device to debug certified apps... and turn off the lockscreen, etc.
Setting some options when you build gaia saves many of these steps. E.g:
DEVICE_DEBUG=1 NOFTU=1 make reset-gaia
will keep your wifi settings, enable debugging of certified apps, disable the
lockscreen, remove the prompt to accept debugger connections and turn off the
first time use screen.
4) Use a proxy to inspect and manipulate HTTP / HTTPS traffic
Tools like Burp and ZAP
have features which are useful if you're making or breaking stuff for the web.
There's an MDN document describing one way of doing that here
- but there's another way (yes, I'm going to update that article); Plug-n-Hack
providers (like Burp, ZAP and some others) provide manifests containing
information on how clients should configure themselves, including root
certificates to install for TLS termination, etc.
This, combined with the 'debug main process' feature of the devtools, allows
you to install your proxy's root cert onto your device by running some code
from a scratchpad.
You can then connect to your proxy in one of two ways:
You can pull the default prefs from your device, change them to add the relevant proxy prefs, put them back.
Or, you could configure your tool to proxy HTTP and HTTPS transparently
then set up iptables on your device to point to your proxy. E.g, to make
HTTPS traffic go through your proxy tool:
adb shell iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to-destination 192.168.0.14:8443
And, to reset it when you're done:
adb shell iptables -t nat -F
But, if you find yourself doing this lots, there's a way that's even more
conveient; set up a testing LAN where all traffic is proxied by default.
This way, you can turn proxying on and off just by changing which wireless
LAN you're connected to.
I built mine using a raspberry pi and steps similar to these.
I changed the iptables rules to look like this:
:INPUT ACCEPT [49:3128]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [37:3924]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
:PREROUTING ACCEPT [1:72]
:INPUT ACCEPT [1:72]
:OUTPUT ACCEPT [1:148]
-A PREROUTING -i wlan0 -p tcp -m tcp --dport 80 -j DNAT --to-destination <proxy_host>:<http_port>
-A PREROUTING -i wlan0 -p tcp -m tcp --dport 443 -j DNAT --to-destination <proxy_host>:<https_port>
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE