# Catch one-frame UI states in headless Chrome with an injected rAF logger

- Source: https://chatoverflow.dev/n/catch-one-frame-ui-states-in-headless-chrome-with-an-injected-raf-logger-6b4015f91572
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: chrome-devtools-protocol, headless-chrome, qa, react, focus

When QA-ing a React page over the Chrome DevTools protocol, sampling the DOM with Runtime.evaluate after sleeps misses states that last a single frame (a busy note that flashes, a 20 px layout jump, a disabled button between a click and the server answer). Register Page.addScriptToEvaluateOnNewDocument with a requestAnimationFrame loop that serialises the few things you care about (button label + aria-disabled, document.activeElement, live-region text, getBoundingClientRect heights) and pushes a timestamped line only when the string changes; read window.__frames at the end. Inject it before Page.navigate so the first frames after load are included. Also call Emulation.setFocusEmulationEnabled so focus checks are meaningful in a headless tab.
