Rewarded Ads in a WebView: When “Dismissed” Arrives Before the Reward

Block Smash: Survival is a turn-based block breaker with roguelike runs. It has two rewarded ads, both on the game-over screen: revive, which brings the run back with 1 HP once per run, and double reward, which doubles the coins the run earned. The same React game is built for the browser, for Android and iOS through Capacitor with AdMob, and for Apps in Toss (the mini-app platform inside the Korean finance app Toss) with Toss’s own full-screen ads.

Twice, the ad code in the Toss build looked correct and still treated a player unfairly. Both times the cause was the order and timing of events crossing from the native app into the web page. This note walks through the event sequence of one rewarded ad, the two failures, how each was found and verified, and the guards that now surround every request.

Three Block Smash screens: a run with balls bouncing through numbered blocks, a level-up choice, and the game-over summary
Block Smash: a run in progress, a level-up choice, and the game-over summary where both rewarded ads are offered.

Sources: the game’s ad client code and its tests, the commits of April 15 and 16 and August 16, 2026, the Apps in Toss runtime branch map written on April 16, and the development log kept in the repository. Ad unit and ad group identifiers are left out on purpose. The browser edition on this site has no ad SDK.

The game, briefly

The board is ten columns wide and filled with numbered blocks; the number is a block’s remaining health. You aim, release a volley of balls, and watch them bounce until they come back. Then every block moves down a row and new ones appear at the top. A block that crosses the danger line costs HP, and a run starts with three. Destroyed blocks give experience, and each level offers a choice of upgrades: new ball types such as fire, lightning, ice, poison and split balls, piercing, rebounds and the like, 38 in all, plus 62 relics with stranger rules. Six characters change the starting style. Iron grows stronger as HP drops, Blaze always fights at 1 HP, Volt chains hits between blocks, Frost freezes, Viper spreads poison and Fortuna gambles on critical hits. The first boss arrives on turn 36, and the gaps between bosses grow from there.

A run ends when HP runs out. Coins from the run buy fourteen permanent upgrades between runs, which is why doubling them is worth an ad. The game is translated into 48 locales. The guides cover starter builds, the first ten turns, preparing for bosses and permanent upgrades.

Block Smash game-over summary with two ad buttons: watch an ad to revive with 1 HP, or watch an ad for 2x coins
The game-over screen offers both placements: revive with 1 HP, or double the coins from the run.

One small contract, two implementations

Game code only ever sees one small interface. There are two placements, revive and double reward. A client can say whether an ad is available, preload one, and show one. Showing always ends in exactly one of three results: rewarded with the amount the platform reported, failed with an error string, or cancelled.

The implementation is not picked with an if-statement at runtime. The Vite build configuration (Vite is the bundler) swaps five platform modules, the rewarded-ad client among them, for either a default folder or a Toss folder depending on the build mode. The Toss SDK therefore never ships inside the app-store builds, and the AdMob plugin never ships inside the Toss bundle. A map of the remaining Toss-specific branches, written on April 16, counted about two dozen direct references still left in app code, almost all of them about layout, storage and the Korean-only language policy rather than ads.

A plain browser build has no ad SDK at all. Its client reports every placement as available and answers a show request with a simulated reward after a short delay, and tests can queue any other result in advance. That stand-in turned out to matter: it lets the whole game-over flow, buttons and messages included, be tested without a phone.

The life of one rewarded ad

Seen from the game screen, a rewarded ad is a button and a spinner. Underneath, one request passes through three layers that each see a different part of it.

Swimlane diagram of one rewarded ad request in the Toss build, across the game screen, the ad client and the Toss SDK, in four stages from check to settle
One request in the Toss build, from tap to reward. Each stage has its own way to end, and the request must end exactly once.
  1. Check. When the player taps, every game-over button locks and a spinner appears on the tapped one. The client confirms that the SDK module loaded, that both full-screen ad calls are supported by this Toss version, and that the placement has an ad group.
  2. Preload. If an ad for that placement is already loaded, it is reused. If a load is already in flight, the new request joins it instead of starting a second one. A load that has not answered within ten seconds is treated as failed.
  3. Show. The loaded ad is marked as used, so it can never be shown twice, and the client starts listening. The SDK can emit requested, show, impression, userEarnedReward, dismissed and failedToShow, and it can call an error handler.
  4. Settle. The first outcome wins. Timers are cleared, the listener is removed, and the game either revives the run, doubles the coins, or returns the buttons with a message.

Everything that went wrong happened between steps three and four, in the assumption that the events arrive in the order a person would expect: the ad starts, the reward is earned, the ad is closed.

Failure 1: “dismissed” can come before the reward

Toss support was added in the early hours of April 15, 2026. That first client handled the show events the obvious way. userEarnedReward meant rewarded. dismissed meant the player closed the ad, so the result was cancelled. A 30-second timer covered the case where nothing happened at all.

The next day’s commits are a run of Toss-only fixes: the HUD overlapping Toss’s own controls, the build configuration, a missing bundle file, the game-over overlay being clipped by the platform chrome. Late that evening the ad flow joined the list. The reward event does not always arrive before the dismissal. When the player closed a fully watched ad, the request could resolve as cancelled first. The reward event that followed found a request that was already settled and was ignored. A player who had watched the whole ad got nothing, which is the one outcome a rewarded ad must never produce.

Timeline comparing rewarded ad handling before and after a grace window was added after the dismissed event
The same ad and the same event order, handled two ways. Waiting briefly after “dismissed” is what saves the reward.

The April 16 fix stopped treating dismissal as final. A dismissed event now starts a grace timer instead of ending the request. If the reward arrives inside that window, the result is rewarded. Only when the window runs out with no reward is the ad reported as cancelled. A second dismissal restarts the timer rather than stacking a new one.

The cost of the fix is visible but small. A player who really did close an ad early now waits out the grace window before the buttons come back. A few seconds of spinner on a closed ad is a much better failure than a lost reward. The window started at five seconds. On August 16 it was raised to fifteen, with a test in which the reward arrives ten seconds after the dismissal, a case the five-second window would have turned into a cancellation.

The same April commit changed how ads are warmed up. The game-over screen used to start loading both placements at once. Now it loads only the revive ad while revive is on offer, and the double-reward ad only once revive is no longer on offer, so two loads never compete for the same SDK.

Failure 2: a timeout that failed ads while they played

The 30-second timer from the first version looked like ordinary caution: if nothing happens, do not leave the player staring at a spinner forever. It started when the show call was made and did not care what happened next.

On a real device, that turned out to be wrong. Toss’s integrated ads do not always forward their start events, requested and show, to the web page. From inside the page, “the ad never started” and “the ad is playing, but nobody told us” look exactly the same. Any ad that ran longer than thirty seconds before its reward was failed while it was still on screen. At that point the timeout was not even in the “could not show” group, so the player saw the generic message that the ad had failed to load. When the ad later finished and the reward event arrived, the request had already been settled, and the reward was dropped.

Timeline showing a 30-second timeout failing an ad that was still playing, compared with a five-minute safety cap
A start timer only works if the platform reliably reports that the ad started. Here it does not.

The obvious repair is a smarter watchdog: start the clock only after the show event. That needs exactly the event that is missing. The August 16 fix took the other route, and the reasoning is written into the code: according to the platform documentation, failures are delivered through failedToShow or the error handler, so the client does not need to guess at starts. What remains is a safety cap the length of one ad, five minutes, after which the request fails with a timeout. The same commit moved that timeout into the “could not show” group, so if it ever fires, the player is told the ad could not start rather than that it failed to load.

Three new tests came with it, about 115 lines. One leaves the client in silence for 45 seconds and then delivers a reward; it must resolve as rewarded. One sends show, then dismissed, then the reward ten seconds later. The last sends nothing at all and expects a timeout at exactly five minutes.

Grid comparing five ad event orders from the unit tests against three versions of the rule, showing which ones lost the reward and which granted it
Five event orders from the tests, replayed against all three versions of the rule. Only the current one rewards every player who earned it and still gives up when nothing ever arrives.

The guards around every request

Both failures were about one question: when is a request over? The answer is now enforced in several places, each covering a different way a request can be ended by the wrong thing.

  • Settled once. Every way out of a show request goes through one finish step. It sets a flag, clears both timers, unregisters the listener and resolves the result. A reward, a late dismissal and a timeout can land within milliseconds of each other, and only the first one counts. This is also why the order mattered so much: whatever arrives first wins.
  • Flow token. The game screen keeps a counter. Each tap takes the next number, and restarting, starting a new run or returning to the menu moves it on and resets the ad state to idle. A result that comes back for an older number is ignored, so a reward that arrives late can never land in a run the player has already left.
  • Reset epoch. The ad client’s own state, the loaded ads, the loads in flight and the last error per placement, lives as long as the page. A reset counter guards it: every preload and show records the count when it starts, and anything that finishes after the count has moved ends as reset_cancelled instead of writing into fresh state. In the shipped game the count never moves: only the test harness resets the client, between cases, which is exactly where stale work leaks most easily. Inside a running game, the flow token does that job.
  • One load per placement. Concurrent preloads of the same placement share a single in-flight request.
  • Locked buttons. While an ad is loading or showing, every game-over action is disabled, including ending the run and claiming the normal reward. A test checks each one.

Errors a player can act on

Two ad SDKs report problems in different shapes: free text that depends on the phone’s language, numeric codes, and error names the client makes up itself. Showing those to players would be useless, and most of them call for the same advice. Before anything reaches the screen, every error is sorted into one of five kinds.

Diagram mapping raw ad error strings into five kinds and the message a player reads for each
Raw errors on the left, the five kinds in the middle, and the English copy a player reads on the right.

Two details are worth copying. Android’s no-fill is recognized from its stable numeric code, not from the message text, because the text changes with the system language. And the “misconfigured” kind exists mainly for me. Debug builds deliberately use test ad settings, and release builds must use configured live ones. A release check rejects a build that still carries Google’s sample identifiers or a missing one, and the native client refuses to start ads in a release build in the same situation. A configuration mistake is meant to surface as a failed build, not as a message on a player’s phone; if it ever got through, the player would only read that ads are temporarily unavailable.

Lessons from the AdMob side

The store builds went through their own round of ad problems in March, and some of the guards above came from there. The development log for March 10 records three. The game-over screen started a preload on entry, and a tap started another for the same placement, so the same native load could run twice; that is where the one-load-per-placement rule comes from. The revive button showed no loading or failure state at all, so a failed ad looked like a button that did nothing. And the Capgo AdMob plugin for Capacitor (MPL-2.0) had an Android bug in which its “is this ad loaded?” call did not return a usable true or false. A small patch now runs after every install to correct it, and the client treats any answer that is not a clear “yes” as “not loaded” and loads again.

AdMob’s events also arrive through global listeners that every ad shares, so each handler first checks that the event carries the ID of the ad it is waiting for. The AdMob client still ends a request when the ad is dismissed. The grace window lives only in the Toss client, where the ordering problem actually appeared, and I would rather add it elsewhere when a test or a device shows the need than guess.

How the timing is tested

None of these cases can be reproduced reliably by tapping through an ad on a phone, so the tests take time out of the picture. The SDK is replaced with a fake that captures the event handler the client registers. The test then emits events in any order, at any moment, while Vitest’s fake timers move the clock. A test can wait 45 seconds, or five minutes, in a few milliseconds. The three test files around the ad client hold 37 tests and run in well under a second.

The cases covered are the ones listed in this note and their neighbours: a reward 50 milliseconds after dismissal; a reward 2.5 seconds after, with a check that the request is still pending at 1.5 seconds; a reward after ten seconds; a long silent ad; complete silence; a preload that finishes after a soft reset and must not mark anything ready; a show that consumes the loaded ad so the next show loads a fresh one; debug builds that must use test ad groups and release builds that must not.

Tests only cover the orders I thought of, though. Neither failure was predicted by a test; the tests were written afterwards, to pin each fix down. The fake SDK makes each fix cheap to verify and impossible to quietly undo later, but the first sign of a timing bug is still a person watching an ad on a device.

A checklist for rewarded ads in a WebView

  • Do not treat “closed” as “not rewarded”. Wait a short, documented grace period for the reward event, and restart it if the close event repeats.
  • Do not put a timer on start events unless the platform guarantees they reach the page. Rely on the documented failure events and keep only a generous safety cap.
  • Resolve each request exactly once, and tie it to the game state it belongs to so a reset cancels it.
  • Share one in-flight load per placement, and lock every other action while an ad is pending.
  • Classify errors before showing them, and make configuration errors fail the release build instead.
  • Replay unexpected event orders with fake timers, and keep testing on a real device.