Remote debug Android devices

Sofia Emelianova
Sofia Emelianova

Remote debug live content on an Android device from your Windows, Mac, or Linux computer. This tutorial teaches you how to:

  • Set up your Android device for remote debugging, and discover it from your development machine.
  • Inspect and debug live content on your Android device from your development machine.
  • Screencast content from your Android device onto a DevTools instance on your development machine.

Remote debugging diagram

Step 1: Discover your Android device

The workflow below works for most users. SeeTroubleshooting: DevTools is not detecting the Android devicefor more help.

  1. Open theDeveloper Optionsscreen on your Android. SeeConfigure on-device developer Options.
  2. SelectEnable USB Debugging.
  3. On your development machine, open Chrome.
  4. Go tochrome://inspect#devices.
  5. Make sureCheckbox.Discover USB devicesis enabled.

    The Discover USB Devices checkbox is enabled.

  6. Connect your Android device directly to your development machine using a USB cable.

  7. If you are connecting your device for the first time, the device will show up as "Offline" and pending authentication.

    Offline device pending authentication.

    In this case, accept the debugging session prompt on your device's screen.

  8. If you see the model name of your Android device, DevTools has successfully established the connection to your device.

    A successfully connected device designated with a model name.

  9. Continue toStep 2.

Troubleshooting: DevTools is not detecting the Android device

Make sure that your hardware is set up correctly:

  • If you're using a USB hub, try connecting your Android device directly to your development machine instead.
  • Try unplugging the USB cable between your Android device and development machine, and then plugging it back in. Do it while your Android and development machine screens are unlocked.
  • Make sure that your USB cable works. You should be able to inspect files on your Android device from your development machine.

Make sure that your software is set up correctly:

If you don't see theAllow USB Debuggingprompt on your Android device try:

  • Disconnecting and then re-connecting the USB cable while DevTools is in focus on your development machine and your Android home screen is showing. In other words, sometimes the prompt doesn't show up when your Android or development machine screens are locked.
  • Updating the display settings for your Android device and development machine so that they never go to sleep.
  • Setting Android's USB mode to PTP. SeeGalaxy S4 does not show Authorize USB debugging dialog box.
  • SelectRevoke USB Debugging Authorizationsfrom theDeveloper Optionsscreen on your Android device to reset it to a fresh state.

If you find a solution that is not mentioned in this section or inChrome DevTools Devices does not detect device when plugged in,please add an answer to that Stack Overflow question, oropen an issue in the developer.chrome repository!

Step 2: Debug content on your Android device from your development machine

  1. Open Chrome on your Android device.
  2. Inchrome://inspect/#deviceson your development machine, you see your Android device's model name, followed by its serial number. Below that, you can see the version of Chrome that's running on the device, with the version number in parentheses.

    The version of Chrome that runs on the device.

  3. In theOpen tab with urltext box, enter a URL and then clickOpen.The page opens in a new tab on your Android device.

    A remote tab listed in a section.

    Each remote Chrome tab gets its own section inchrome://inspect/#devices.You caninteract with that tabfrom this section. If there are any apps usingWebView,you see a section for each of those apps, too. In this example, there's only one tab open.

  4. ClickInspectnext to the URL that you just opened. A new DevTools instance opens.

A new DevTools instance for the remote tab.

The version of Chrome running on your Android device determines the version of DevTools that opens on your development machine. So, if your Android device is running a very old version of Chrome, the DevTools instance may look very different than what you're used to.

More actions: pause, focus, reload, or close a tab

Below the URL you can find a menu to pause, focus, reload or close a tab.

The menu for pausing, reloading, focusing, or closing a tab.

Inspect elements

Go to theElementspanel of your DevTools instance, and hover over an element to highlight it in the viewport of your Android device.

You can also tap an element on your Android device screen to select it in theElementspanel. ClickSelect ElementSelect Elementon your DevTools instance, and then tap the element on your Android device screen. Note thatSelect Elementis disabled after the first touch, so you need to re-enable it every time you want to use this feature.

Screencast your Android screen to your development machine

ClickToggle Screencast Toggle Screencastto view the content of your Android device in your DevTools instance.

You can interact with the screencast in multiple ways:

  • Clicks are translated into taps, firing proper touch events on the device.
  • Keystrokes on your computer are sent to the device.
  • To simulate a pinch gesture, hold Shift while dragging.
  • To scroll, use your trackpad or mouse wheel, or fling with your mouse pointer.

Some notes on screencasts:

  • Screencasts only display page content. Transparent portions of the screencast represent device interfaces, such as the Chrome address bar, the Android status bar, or the Android keyboard.
  • Screencasts negatively affect frame rates. Disable screencasting while measuring scrolls or animations to get a more accurate picture of your page's performance.
  • If your Android device screen locks, the content of your screencast disappears. Unlock your Android device screen to automatically resume the screencast.

Debug manually through Android Debug Bridge (adb)

In some rare cases, an alternative method of remote debugging may be useful. For example, you may want to connect directly to theChrome DevTools Protocol(CDP) of your Chrome on Android.

To do this, you can use theAndroid Debug Bridge (adb):

  1. Make sure to enableDeveloper optionsandUSB debuggingon your Android device.
  2. Open up Chrome on your Android Device.
  3. Connect the Android device to your development machine through:

  4. In your development machine's command line, runadb devices -land check if your device is present in the list.

  5. Forward the CDP socket on the device to your machine's local port, for example,9222.To do this, run:

    adbforwardtcp:9222localabstract:chrome_devtools_remote
    
  6. Once successfully connected, see that:

    • http://localhost:9222/jsonlists yourpagetargets.
    • http://localhost:9222/json/versionexposes thebrowsertarget endpoint, as theCDP documentationindicates.
    • chrome://inspect/#devicesis populated, even without theDiscover USB devicessetting checked.

For troubleshooting, see: