How to Debug on Mobile, and How It Differs from the Web
How debugging on a phone differs from the web: no DevTools, an app around your page, and an OS around the app. Terms, a route map, and 11 parts.
On the web, you debug a page. On a phone, you debug the page, the app around it, and the OS around the app.
Terms used in this series
Each essay also defines these at first use.
| Term | Meaning |
|---|---|
| click script | the ad’s JavaScript that records the tap and opens the ad’s page. |
| click tracker | a server that gets a short message for each tap and adds one to a count. |
| device log | the phone’s system log, read from a computer with idevicesyslog (iOS) or adb logcat (Android). |
| feed | the scrolling list of posts and ads inside an app. |
| HAR | a file that records every request the phone sent and every reply. |
| landing page | the page or app that the ad promises to open. |
| ping | a background request that only reports an event. |
| proxy | a server between the phone and the internet that relays its traffic. |
| SDK | a code library that an app builds in. Here, it shows ads. |
| WebView | a browser engine inside an app, with no tabs or address bar. |
The question
On the web, debugging starts with one shortcut: open DevTools. The console shows your logs. The Network panel shows every request. You change a line and reload.
Then your code runs on a phone. It can run in a mobile browser, in a WebView inside an app, or inside an app that another company builds. You want the same view as on the web: what ran, what was sent, and what opened. But the phone has no DevTools button, and an app does not let you in by default.
So on mobile, you do not start with the bug. You start with this question: how do I see what happens, the way I do on the web?
The running example
Each essay uses one case to show the idea. Users tap an ad inside an app, and nothing opens. The same ad works in Safari on the same phone.
Web vs mobile: what changes
| What you need | On the web | On a phone, inside another app |
|---|---|---|
| See the code run | DevTools on the same machine | The host app (the app that holds the page) owns the WebView (a browser engine inside an app). No DevTools unless the app turns on inspection |
| See the network | The Network panel | A proxy between the phone and the internet records a HAR (a file of every request and reply) |
| See what the OS did | The OS log is on the same computer (macOS Console app, Windows Event Viewer). You rarely need it, because a link opens in a tab | The log is on another device. Read it from a computer with idevicesyslog or adb logcat. You often need it, because an app opening is not a request |
| Change the code | Edit and reload | You do not own the build. Rewrite the response on its way to the phone, and stop the phone from using its old cached copy |
| Trust a test | The test runs where the user runs | A proxy test changes only what the phone receives |
| Find the layer | Usually one page | App, SDK (the ad library inside the app), WebView, page, iframe (a page inside a page), ad: each one can stop the tap |
Each row is one or two essays in this series.
Route map
1: What a tap does
- The Data Says Clicked, the User Says Nothing Happened: a recorded click and an opened page are two events.
- When the Page Closes, Does the Request Still Arrive?: keepalive and sendBeacon, useful on any website.
2: The app around the page
- Same Code, Put It in an App, and It Behaves Differently: why
window.open()returnsnullin an app. - Three Ways an iOS App Can Open a Link: WebView, in-app Safari, or another app.
3: See what happened
- Record the Phone Traffic, Then Read It: every request, and which code sent it.
- Where Did It Fail? The Device Log and the Network Log Each See Half: the second recorder.
4: Change what the phone runs
- You Cannot Edit the Code on the Phone, So Change It on the Way: the cache trap and the minified file.
- Changing Code on the Way Proves Only the Phone Side: what a rewrite cannot prove.
5: Find the cause
- One Tap Passes Six Layers: Remove One Layer per Test: remove one layer per test.
- Experiment Mindset: Try to Disprove Your Own Guess First: a guess that fits everything can still be wrong.
- Takeaway: Check One Layer at a Time, and Test Each Guess with the Right Tool: which tool for which layer, and how to test a guess.
Who this is for
- Web or backend engineers who never debugged code inside a phone app
- Anyone who ships JavaScript that runs inside other companies’ apps: ads, widgets, embedded checkouts
What you will take away
- Which recorder proves which claim: the HAR for the network, the device log for the OS
- How to change code that you do not own, on a phone that you cannot open DevTools on
- A method to find the failing layer: one control per layer, and one test per guess
References
- MDN: Window.open()
- MDN: Sec-Fetch-Mode
- Apple: Supporting universal links in your app
- WebKit: Enabling the inspection of web content in apps
- HAR 1.2 specification
Start here: The Data Says Clicked, the User Says Nothing Happened.