iOS WebView debugging
This tutorial guides you through debugging WebView content inside iOS applications with WebDebugX, covering both WKWebView and UIWebView. You will learn how to inspect the HTML, CSS and JavaScript inside a WebView, and how to solve the common WebView debugging problems.
Before you start
Section titled “Before you start”Before debugging an iOS WebView, make sure you have:
- The latest version of WebDebugX installed
- The iOS device you want to debug (iPhone or iPad) at hand
- The iOS app containing the WebView installed
- The device and computer on the same network (if you are using WiFi debugging)
Tip: for iOS WebView debugging the app itself must have Web Inspector enabled. If you are the app developer you need to add that configuration — see section 4 of How to enable Web Inspector.
Connect the device
Section titled “Connect the device”- Connect the iOS device to the computer with a USB cable
- Trust the computer on the iOS device (if prompted)
- Launch WebDebugX
- WebDebugX detects your iOS device automatically
Select a WebView
Section titled “Select a WebView”- In the WebDebugX device list, click your iOS 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 Web Inspector enabled and the WebView has actually loaded content.
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
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
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
WKWebView vs UIWebView
Section titled “WKWebView vs UIWebView”iOS has two main WebView components, and they differ in what you can debug.
WKWebView
Section titled “WKWebView”WKWebView is Apple’s recommended modern WebView component, with better performance and capabilities:
- Supports more modern web features
- Better JavaScript performance
- Supports more debugging features
- Shown as WKWebView in WebDebugX
UIWebView
Section titled “UIWebView”UIWebView is the older component. It is deprecated, but some apps still use it:
- Relatively limited features
- Poorer JavaScript performance
- Fewer debugging capabilities
- Shown as UIWebView in WebDebugX
Tip: if you are the app developer, migrate from UIWebView to WKWebView — Apple has marked UIWebView as deprecated and it is no longer recommended for new apps.
Common WebView debugging scenarios
Section titled “Common WebView debugging scenarios”Debugging WebView load failures
Section titled “Debugging WebView load failures”If the WebView will not load content correctly:
- Check in the Network panel whether the requests succeeded
- Verify the request URLs are correct
- Look at the response status codes and bodies
- Check the Console panel for JavaScript errors
Debugging WebView–native interaction
Section titled “Debugging WebView–native interaction”If the interaction between the WebView and native code is broken:
- In the Console panel, check whether the JavaScript bridge object was injected correctly
- Use
console.log()to output the arguments passed to bridge methods - Add logging in the native code to confirm the method is being called
- Check that the data format is correct (JSON parse errors, for instance)
Optimizing WebView performance
Section titled “Optimizing WebView performance”- Use the Performance panel to analyze load and rendering performance
- Check JavaScript execution time
- Analyze network request load times
- Optimize the order and size of resource loading
Advanced techniques
Section titled “Advanced techniques”Simulate different network conditions
Section titled “Simulate different network conditions”- In WebDebugX, open the Throttling dropdown in the Network panel
- 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”If the WebView contains iframes, you can debug them separately:
- 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 Web Inspector enabled
- Check that the device and computer are connected properly
- Restart WebDebugX and the iOS device
- Make sure the iOS device is unlocked and has trusted the computer
JavaScript will not execute in the WebView
Section titled “JavaScript will not execute in the WebView”- Check that JavaScript is enabled in the WebView
- Confirm the WebView has fully loaded
- Try reloading the WebView content
- Check whether a JavaScript error is blocking execution
The WebView content renders incorrectly
Section titled “The WebView content renders incorrectly”- Check that the CSS loaded correctly
- Look in the Network panel for failed resource loads
- Check that the WebView’s viewport settings are correct
- Try clearing the WebView cache and reloading