You can use the Firefox developer tools on your desktop to debug code running remotely: in a different process on the same device or on a completely different device.
This guide explains how to get set up to debug code running in Firefox for Android over USB. The other main application for remote debugging is to debug code running in the Firefox OS Simulator, but that's covered separately, in the Firefox OS Simulator documentation.
This guide's split into two parts: the first part, "Prerequisites" covers stuff you only need to do once, while the second part, "Connecting", covers stuff you need to do each time you connect the device.
First, you'll need:
- a desktop or laptop computer with Firefox running on it
- an Android device capable of running Firefox for Android with Firefox for Android running on it
- a USB cable to connect the two devices
Next, you'll need to get the desktop and the Android device talking to each other using the adb command-line tool.
On the Android device
- Enable USB debugging (step 2 of this link only).
- Attach the device to the desktop via USB.
On the desktop
- Install the correct version of the Android SDK for your device.
- Using the Android SDK, install the Android Platform Tools.
- Android Platform Tools installs 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.
To check it worked, open up a command shell on the desktop and type:
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've successfully set up ADB.
Enable remote debugging
Next, you need to enable remote debugging on both the Android device and the desktop.
On the Android device
To enable remote debugging on the device, you need to set the
devtools.debugger.remote-enabled preference to
about:config in Firefox for Android, type "devtools" into the search box and press the Search key. You'll see all the devtools preferences:
devtools.debugger.remote-enabled preference, and press "Toggle":
On the desktop
On the desktop, remote debugging is enabled by a setting in the Toolbox:
- Restart the browser.
You'll see a new option in the Web Developer menu labeled "Connect...":
Now you can connect the remote debugging tools to the device. First, attach the device to the desktop with a USB cable, if you haven't already.
Go to a command prompt, and type:
adb forward tcp:6000 tcp:6000
(If you've changed the value the Android device uses for a debugging port, you'll need to adjust this accordingly.)
You'll need to reissue this command each time you physically attach desktop and device with the USB cable.
Then go to the Web Developer menu on Firefox, and select "Connect...". You'll see a page that looks like this:
Unless you've changed the port numbers, choose 6000 and press the "Connect" button.
Next you'll see a dialog on the Android device asking you to confirm the connection:
Press "OK". The desktop waits for a few seconds to give you time to acknowledge this dialog: if it times out, just press "Connect" in the desktop dialog again.
Next, the desktop shows you a dialog that looks something like this:
This is asking whether you want to debug web content running in a browser tab, or to debug the browser code itself.
- You'll see one entry under "Available remote tabs" for each open tab, and clicking it will attach the debugging tools to the web content hosted by that tab. If you want to debug your web content, you'll choose the relevant content tab.
- You'll see one entry under "Available remote processes": this is the browser process itself. You'll choose this option if you want to debug the browser's own code.