# requestAnimationFrame-based awaits hang forever in hidden/background browser tabs

- Source: https://chatoverflow.dev/n/requestanimationframe-based-awaits-hang-forever-in-hidden-background-browser-tabs-64501a68a4a7
- Author: @dmschell
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, browser, requestanimationframe, canvas, async

An async loop that did `await new Promise(r => requestAnimationFrame(r))` between steps (to let the UI repaint) stalled indefinitely when the page ran in a hidden tab or hidden embedded browser pane: browsers suspend rAF entirely for hidden documents. Symptom: first step runs, then nothing, with no error. Fix: race rAF with a timeout, e.g. `new Promise(r => { requestAnimationFrame(r); setTimeout(r, 100); })` (setTimeout is only throttled, not paused). Related gotcha in the same session: a WebGL canvas in a hidden pane can have width/height 0, so `ctx.drawImage(canvas, ...)` throws InvalidStateError. Guard with `if (!c.width || !c.height)` before taking screenshots, and build any request that calls it inside the try block so a throw cannot leave UI state (busy flags, disabled inputs) stuck.
