Disclosure: I'm the developer of RKMovies, a small 4K media player client. It ships as a 1.17 MB APK and a 29.5 MB Windows installer. The web app lives at this little player of mine, with the android apk download page and the windows desktop build page.
The app shows one short ad before playback, from mainstream family safe networks. Keeping that gate working this week turned into a debugging war, so here are the actual bugs.
The empty VAST
We fetch a VAST XML tag from the ad network and play whatever it returns. Suddenly, desktop user agents from many IPs got an empty VAST back (no ads at all) while mobile UAs got full inventory from the same IP. Same request, same IP, only the User-Agent string differed. The fix was one line: fetch the VAST tag with a mobile UA. It feels wrong, but it works and it's still in the code.
The dead CDN
Then the CDN the VAST pointed at turned out to be publicly unresolvable. Ad media 403'd and 502'd and the gate looped forever. The fix: the ad media allowlist now self heals from the hosts the served VAST actually uses, instead of a hardcoded list. When the network rotated CDNs, the next VAST response told us the new host and the allowlist learned it.
Count bytes, don't trust the player
"Did the ad play?" is a question the video element answers with a lie. Stalled streams, errored media, a 30 second chip spinning on nothing. So the proxy and the Android shell count actual ad bytes (more than 1 MB and at least 95% of the stream) through /api/admedia, and only then issue a one time token. The play and download endpoints return 4030 without it. The 12 hour unlock now survives app and proxy restarts. Before, it lived in memory only.
The watchdog
The connect timeout on ad media used to be 300 seconds, so one dead CDN hung requests for minutes. Now it's 6 seconds, plus a client side watchdog that fails non loading ad media immediately, and 6 consecutive video errors stop the pod loop and show the unlock instead of resetting the countdown. The countdown state is shared across the whole ad pod now, so the second ad no longer restarts at 30 seconds.
What I learned: ad networks assume you are a big app whose browser fingerprint matches your traffic. A 1.17 MB webview app does not get to make those assumptions. Feature detect everything, count bytes yourself, and never trust a 200.
Top comments (5)
The mobile UA spoofing is painfully relatable—classic ad-tech logic assuming a 1.17 MB webview is a massive native app. But your byte-counting proxy to issue the unlock token is a brilliant workaround. Never trust the video element to tell you the truth! Great debugging war stories.
haha yeah, the webview-is-a-native-app assumption is wild. byte counting ended up the simplest reliable unlock check
Assuming a WebView has the same footprint as a native app is hilarious. But yeah, byte counting is the ultimate "trust no one" fix—if the data didn't transfer, the ad didn't play.
yeah same. Assuming a WebView has the same footprin is the bit nobody talks about until it bites them mid-session
You're spot on. The RAM footprint of a WebView compared to a native player is a completely different beast. It might look fine on paper, but once the user is deep into a session and the cache starts building up, the OS quickly comes knocking to kill the process. The "mid-session bite" is a very real (and painful) lesson.