← sources

Headless Playwright Made My Game Look Broken Because requestAnimationFrame Was Throttled

source: reddit (reddit:webdev)published 2026-06-06 17:29ingested 2026-06-07 08:48

retained text

<!-- SC_OFF --><div class="md"><p>I was writing Playwright E2E tests for a small Three.js platformer and hit a confusing issue.</p> <p>Game context: <a href="https://games.xgallery.online/forest-quest/">https://games.xgallery.online/forest-quest/</a></p> <p>The game worked in the browser. But in headless Chromium, enemies barely moved, jumps looked inconsistent, and the boss test would sometimes fail for no obvious reason.</p> <p>The problem was requestAnimationFrame throttling.</p> <p>In a headless run, the page does not always get normal frame pacing. My game loop depended on rAF, so waiting 1 second in the test did not mean the game simulation advanced like 1 second of real play.</p> <p>The fix was to expose a manual frame step in the game. The test can call a small internal function that advances one frame with a controlled timestamp.</p> <p>Then the test helper advances the game in small steps. Instead of waiting one big second, it calls that frame step about every 50ms.</p> <p>That made the tests deterministic enough to check real gameplay behavior.</p> <p>Example observations from the full run:</p> <p>L2 mushroom patrol delta: 1.071</p> <p>L6 boss HP sequence: [7, 6, 5, 4, 3, 2, 1, 0]</p> <p>Boss phase switched: true</p> <p>The funny part is that the boss model did not need to be loaded for this to work. The boss could be a Meshy model or a gray fallback box. For E2E, the important thing was the state machine, collision, HP, and portal reveal.</p> <p>I would be careful with this kind of hook in a serious public game. For this tiny project, it is a testing helper, not a scoring or account system.</p> <p>I used to think of browser game testing as screenshot-heavy. This project reminded me that sometimes the best test hook is just a safe way to drive the loop yourself.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/Top-Cardiologist1011"> /u/Top-Cardiologist1011 </a> <br /> <span><a href="https://www.reddit.com/r/webdev/comments/1tynd2m/headless_playwright_made_my_game_look_broken/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/webdev/comments/1tynd2m/headless_playwright_made_my_game_look_broken/">[comments]</a></span>

document fetched 2026-06-07 08:48