DEV Community

Eka Putri
Eka Putri

Posted on

The Back Gesture That Ends the Game: Android History in H5 Builds

A player messaged me last week about an H5 game that closed itself every time he swiped back from the edge of the screen. Nothing in the code said exit. The browser was only following history, and the game had left the stack with nowhere to go except the tab that opened it.

This never shows up in a desktop test. On Android, the back gesture, the key on older handsets and the edge swipe all feed the same navigation stack, and a page that pushes a state on boot without listening for popstate can walk straight out of a session. I keep a few builds around for checking exactly this, because the handling differs page by page. zk988 intercepts the gesture and asks before leaving, while h5.maha24 drops the player back to the last checkpoint instead of closing the tab, which feels far less abrupt on a small screen.

The build I use to test a cold entry from a shared link is the download vegas 777 sr6666 page, since it opens directly into a round with no lobby in between. One state goes on the stack, popstate gets a listener, and the leave decision becomes explicit rather than accidental.

What I check now is narrow: push a single guard state on boot, stop the audio context when popstate fires, and do not trust beforeunload, which phones frequently skip. If the swipe still escapes the game, the cause is usually an earlier history.replaceState that already spent the entry. hot985 and b8vip are the two where that guard state survived a full round on a 4 GB phone, and that is the behaviour I copy now. A back gesture that asks once is cheaper than a support thread about a game that quits on its own.

Top comments (0)