Debugging on Mobile Devices

Product(s)
Video Cloud
Role(s)
Player Developer
Topic(s)
Developer Concepts/Tools
Troubleshooting/Error Handling

In this topic, you will learn about debugging JavaScript on mobile devices. During development testing and debugging content on mobile platforms can be very challenging.

Overview

In this document you will learn how to get started with debugging on mobile devices and covers the following solutions:

  • Debugging on iOS devices
  • Debugging on Android devices
  • Using Charles on mobile devices

iOS debugging

Minimum requirements for iOS debugging

  • Safari version 6+ running on Mac MacOS
  • iPhone or iPad with iOS 6+

Note: if you are on iOS 10.3 or later, open the Settings and navigate to General > About > Certificate Trust Settings, and find the Charles Proxy certificate, and switch it on to enable full trust for it.

Using Safari Remote Debugging

Apple's iOS 6 update introduced Safari Remote Debugging, which allows you debug web pages in the Safari app on iOS devices. To get started, follow the steps below:

  1. Connect your iOS device to your machine via USB cable.
  2. On your device, open the Settings app. Select Safari, scroll down to the bottom of the page and open the Advanced menu. Enable the Web Inspector option.
    Web Inspector
    Web Inspector
  3. Still on your device, open the Safari app and browse to any web page.
  4. On your Mac, launch Safari, open the Preferences (Safari > Preferences), and navigate to the Advanced section. Enable the Show Develop menu in the menu bar option.
    Show Develop Menu
    Show Develop Menu
  5. Open the Develop menu. You will see your iOS device listed. When you mouse over your device name, you will see the URL to the site you've browsed to on your device displayed.
    Find the Device
    Find the Device
  6. Select the URL and a Web Inspector window will open, allowing you to preview, inspect, and debug content on your mobile browser from your desktop.
    Debug on Desktop
    Debug on Desktop
  7. In the Resources section, you can preview and inspect the web page. Hovering over elements in the Web Inspector will highlight the corresponding elements in the browser on your iOS device.
    Inspecting Elements
    Inspecting Elements
  8. You can also use the Debugger and Console sections to further debug your page by setting breakpoints, logging data, etc.

Android debugging

Minimum requirements for Android debugging

  • Chrome 32+ running on Mac or Windows
  • Android device with Chrome for Android 32+

Note: The steps in this section were written using a device running Android 4.3.

Enabling debugging on your device

Before you can begin debugging content on your device, you need to enable USB debugging in your device settings.

  1. If you are a running Android 4.2+, you will need to enable your device's Developer options before you can turn on USB debugging. On your device, open the Settings app and select the About phone menu. Locate your device's Build number and tap it seven times.
  2. Hit your device's Back button and you will see the Developer options menu listed in the Settings.
    Get to Developer Options
    Get to Developer Options
  3. Open the Developer options menu and check the box to enable USB debugging.
    Enable USB Debugging
    Enable USB Debugging

Remote debugging using Chrome for Android

Now that USB debugging is enabled on your device, follow these steps to start remote debugging with Chrome:

  1. On your computer, launch Chrome and browse to about:inspect. On the Devices page, enable the Discover USB devices option.
    Discover USB Devices
    Discover USB Devices
  2. Connect your device to your machine via USB cable. On your device, you will be prompted with a dialog asking if you would like to allow USB debugging. Choose OK to allow your computer to connect to your device.
    Allow Connection to Device
    Allow Connection to Device
  3. On your device, open the Chrome app and browse to a web page.
  4. Return to Chrome on your computer. On the about:inspect page, you should see your connected device. Below your device name, you will be able to see a list of all of the pages open in Chrome on your device.
    Connected Devices
    Connected Devices
  5. To begin debugging a web page, select the inspect link below the page URL. This will open Chrome's Developer Tools.
    Inspect Web Page
    Inspect Web Page
  6. To the left of the Elements tab, you can select the device icon to open DevTool's Screencast feature. This allows you to open a live preview of the content as it appears on your mobile device. For more information on how you can use screencasting to interact with your device, visit Google's documentation.

Charles for mobile

Charles is a web proxy that can be run on your own computer, allowing you to record data that is sent and received via your web browser. Visit the Charles website for more information on this application.

Minimum requirements for Charles

  • Charles is compatible with Windows, Mac and Linux
  • iOS and/or Android device

Setting up Charles on your machine

Follow the steps below to get Charles running on your machine.

  1. Download and install Charles on your machine.
  2. On your computer, run Charles. From the menu, select Proxy > Proxy Settings. Ensure a port has been assigned (e.g., 8888) and the Enable transparent HTTP proxying option is selected.
    Proxy settings
    Proxy settings
  3. Select OK to save changes and close the dialog.
  4. From the menu, select Proxy > SSL Proxy Settings. Ensure the Enable SSL Proxying option is selected.
    SSL Proxy settings
    SSL Proxy settings
  5. In the Location section, select the Add button. In the Edit Location dialog, navigate to the Port field and enter 443. Select OK to save this change.
    Location port 443
    Location port 443
  6. Select OK to close the Edit Location dialog.
    SSL settings with location
    SSL settings with location
  7. Select OK to exit the SSL Proxying Settings dialog.
  8. Navigate to Help > SSL Proxying > Install Charles Root Certificate on a Mobile Device or Remote Browser.
    Install root certificate
    Install root certificate
  9. You should see a message that identifies the local Server IP and Port number (8888) that you will use to set up the device. You should also see the URL to download and install the certificate. Copy these to your computer for later use.
    Certificate message
    Certificate message

Setting up Charles on your device

In this section, you will learn how to set up your iOS and/or Android device to work with Charles on your computer.

Setting up your iOS device

  1. On your device, make sure you are connected to the same network as your computer. You can verify this by navigating to settings > Wifi and selecting the network name to show advanced options.
    Device network
    Device network
  2. In the HTTP section at the bottom, add the Server IP and Port number (8888) that you copied from Charles in a previous step.
    Wifi details
    Wifi details
  3. On your device, open a browser and navigate to //chls.pro/ssl. You will be redirected to your device settings where you will be prompted to install the Charles Proxy Custom Root Certificate profile. Select the Install button to install the Charles certificate on your device.
    Install Charles certificate
    Install Charles certificate
  4. Follow the steps to install the Charles certificate. When complete, select Done.
    Charles profile installed
    Charles profile installed
  5. On your device, return to the browser and open any web page. Charles will alert you about the connection attempt. You should allow this.
    Allow Charles connection
    Allow Charles connection
  6. Now, you will be able to see any data sent and received in Charles.
    See Charles data
    See Charles data

Setting up your Android device

  1. On your device, open a browser and navigate to //chls.pro/ssl.
  2. You will be prompted with a Certificate name dialog. Specify a name for the certificate and set the Used for field to Wi-Fi. Select OK to install the certificate.
    Install Charles Certificate
    Install Charles Certificate
  3. Next, open the Settings > Wi-Fi menu. You will see a list of networks that you have connected to on your device. Select the wireless network that you are currently connected to. Remember, this network must match the network you are connected to on your computer.
  4. This will open a small dialog with three options—Edit, View, or Forget. Select Edit.
  5. In this dialog, scroll down to the bottom and enable the Show advanced options field. This will reveal Proxy and IP settings.
    Advanced Settings
    Advanced Settings
  6. Change the Proxy settings field to Manual.
  7. Fill out the Proxy host name field with your computer's IP address and the Proxy port field to match the port set in Charles (by default, the port is set to 8888). Select Save.
    Set IP Address
    Set IP Address
  8. In your device's default browser, navigate to a website. You will be able to see any data sent and received in Charles.
    See Data Transfer
    See Data Transfer