Skip to content
All writing ‹ Part 07 of 11 · Mobile Debugging: When There Is No DevTools
Engineering · 3 min read

You Cannot Edit the Code on the Phone, So Change It on the Way

When you cannot edit a script inside someone else's app, a proxy can rewrite it on the way to the phone. Two traps: cached 304 replies and minified code.

On the web, you change a line and reload. Inside someone else’s app, you cannot reload, and the script often comes from a server that you do not control. So a proxy (a server between the phone and the internet) rewrites the script on its way to the phone. Two traps wait there.

Trap 1: the phone never asks for the new copy

Conditional request with and without the fix Without the fix, the server answers 304 and the patch never runs. With the fix, the proxy strips the cache headers. The phone gets a patched 200. phone old copy proxy server Without the fix GET, If-None-Match 304, no body 304, no body The patch never runs the phone keeps the old copy With the fix GET, If-None-Match GET (1) 200, full body patched 200 (2) (1) remove If-None-Match and If-Modified-Since (2) set Cache-Control: no-store, remove ETag and Last-Modified
A cached copy turns the request into a 304 with no body, so a patch on the 200 body never runs. Strip the cache headers both ways, and the phone gets the patched copy.

A client with a cached copy sends If-None-Match with the copy’s ETag (a version tag from the server). The server answers 304 Not Modified with no body. A patch that changes the 200 body never runs. In the example, the first fix test did nothing for exactly this reason. Signal: the patch “does nothing” only on a second load, or only on one device.

Trap 2: the source code is not what the phone gets

The server sends a built, minified file (spaces removed, names shortened). A find string copied from the source is not in it.

// source
return true;
// what the phone receives
!0

Copy the find text from the captured response body, never from the source. Then report whether the patch applied, for example in a note on the recorded request. If a new build arrives, the match fails, and you see “patch not applied” instead of a silent pass.

Backend analogy: you patch the running program in the container, not the repo.

The limit

A change on the way shows what the phone does with new code. It does not show what the real system does. That limit is the topic of Changing Code on the Way Proves Only the Phone Side.

Patch what the phone receives, and make the phone receive it.

References


Related: learn to record the phone traffic and read it. See why a proxy rewrite proves only the phone side. Then read the takeaway: check one layer at a time with the right tool. Back to the series overview.

↑↓ navigate ↵ open esc close