Android WebView debugging
This tutorial guides you through debugging WebView content inside Android applications with WebDebugX. You will learn how to connect an Android device, debug the WebViews inside an app, analyze performance problems, and work around the common debugging pitfalls.
Before you start
Section titled “Before you start”Before debugging an Android WebView, make sure you have:
- The latest version of WebDebugX installed
- The Android device you want to debug (phone or tablet) at hand
- The Android app containing the WebView installed
- The device and computer on the same network (if you are using WiFi debugging)
Tip: for Android WebView debugging you need USB debugging and WebView debugging enabled on the device. If you are the app developer you also need to enable WebView debugging in the app — see section 4 of How to enable Web Inspector.
Connect the device
Section titled “Connect the device”- Connect the Android device to the computer with a USB cable
- Allow USB debugging on the Android device (if prompted)
- Launch WebDebugX
- WebDebugX detects your Android device automatically
Select a WebView
Section titled “Select a WebView”- In the WebDebugX device list, click your Android device
- On the device detail page you will see the list of debuggable apps
- Find the app containing the WebView and click it
- On the app detail page you will see every WebView in that app
- Select the WebView you want to debug
Tip: if you cannot see the app’s WebViews, make sure the app has WebView debugging enabled and the WebView has actually loaded content. On Android 4.4 and above the app must call
WebView.setWebContentsDebuggingEnabled(true).
Debugging WebView content
Section titled “Debugging WebView content”Inspect the HTML structure
Section titled “Inspect the HTML structure”- In the debugging interface, click the Elements tab
- You will see the full DOM tree inside the WebView
- Click an element to view its attributes and styles
- Right-click an element to edit, delete or add elements
- Use the Select element tool (the arrow icon at the top left) to pick elements directly on the page
Debug JavaScript
Section titled “Debug JavaScript”- Click the Console tab
- Execute JavaScript in the console
- View JavaScript errors and logs
- Use
console.log(),console.error()and similar methods to output debugging information
Monitor network requests
Section titled “Monitor network requests”- Click the Network tab
- You will see every request the WebView makes
- Click a request to view details, including request headers, response headers and response content
- Use filters to narrow down specific types of requests
- Enable Preserve log to keep request records across page navigations
Debug JavaScript sources
Section titled “Debug JavaScript sources”- Click the Sources tab
- Find the JavaScript file you want to debug in the file tree
- Click a line number to add a breakpoint
- When execution reaches the breakpoint, inspect variable values and step through the code
- Use the Watch panel to track variable values
Debugging WebView–native interaction
Section titled “Debugging WebView–native interaction”Android WebViews usually need to talk to native code, and WebDebugX has dedicated tooling for those interactions.
JavaScript interface debugging
Section titled “JavaScript interface debugging”Debug the JavaScript interface between the WebView and native code:
- In the Console panel, type
windowto see all available global objects - Look for the JavaScript interface objects injected by the native code
- Try calling those interface methods and watch the console output
- Use
console.log()to output the arguments and return values of the interface methods
Tracing native method calls
Section titled “Tracing native method calls”Trace the native methods the WebView calls:
- In the debugging interface, click More tools (the three dots)
- Choose JavaScript bridge
- You will see a list of every native method the WebView has called
- Click a method to view details of the call, including arguments and return value
- Use filters to narrow down specific types of calls
Debugging WebViewClient and WebChromeClient
Section titled “Debugging WebViewClient and WebChromeClient”Debug the WebView’s lifecycle events and callbacks:
- In the debugging interface, click More tools (the three dots)
- Choose WebView events
- You will see all of the WebView’s events and callbacks
- Enable the events you want to trace
- Interact with the WebView on the Android device and watch which events fire
Performance analysis
Section titled “Performance analysis”WebView performance panel
Section titled “WebView performance panel”- Click the Performance tab
- Click Start recording
- Interact with the WebView on the Android device
- Click Stop recording when you are done
- Analyze the timeline — CPU usage, rendering events, and so on
Memory analysis
Section titled “Memory analysis”- Click the Memory tab
- Choose an analysis type (heap snapshot, allocation timeline, and so on)
- Click Start recording
- Interact with the WebView on the Android device
- Click Stop recording when you are done
- Analyze memory usage and look for possible leaks
Network performance
Section titled “Network performance”- Enable Preserve log in the Network panel
- Reload the WebView content and review every request
- Analyze load times and sizes
- Look for resources you can optimize — compress images, combine CSS / JS files, and so on
- Use network throttling to simulate different network conditions
Advanced techniques
Section titled “Advanced techniques”Simulate different network conditions
Section titled “Simulate different network conditions”- In the Network panel, open the Throttling dropdown
- Choose a preset (3G, 4G or Offline)
- Or choose Custom and set upload / download speed and latency
- Reload the WebView content and observe the loading behaviour
Debugging iframes inside a WebView
Section titled “Debugging iframes inside a WebView”- Find the iframe element in the Elements panel
- Right-click the iframe and choose Inspect iframe
- WebDebugX switches to the iframe’s context
- You can now debug the content inside the iframe
Save and restore a debugging session
Section titled “Save and restore a debugging session”- In the debugging interface, click File > Save session
- Enter a session name and pick a location
- Later, restore it via File > Open session
- This is particularly useful for long debugging runs or team collaboration
Troubleshooting
Section titled “Troubleshooting”The WebView does not appear in the device list
Section titled “The WebView does not appear in the device list”- Make sure the app has WebView debugging enabled
- Check that the device and computer are connected properly
- Restart WebDebugX and the Android device
- Make sure the Android device is unlocked and has trusted the computer
For a fuller checklist, see Device not found.
JavaScript will not execute in the WebView
Section titled “JavaScript will not execute in the WebView”- Check that JavaScript is enabled in the WebView
- Make sure no JavaScript error is blocking execution
- Try reloading the WebView content
- Check the WebView’s security settings