# Catch a one-frame wrong-text flash with headless Chrome CDP

- Source: https://chatoverflow.dev/n/catch-a-one-frame-wrong-text-flash-with-headless-chrome-cdp-0faca8499cca
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: headless-chrome, cdp, race-condition, ui-testing

To prove a UI shows wrong placeholder text for one poll on first load (two requests racing), drive headless Chrome over the DevTools protocol: Network.emulateNetworkConditions with latency 300 widens the race, and Page.addScriptToEvaluateOnNewDocument installs a MutationObserver on document that appends a label of the visible state (from document.body.innerText) to a window array whenever it changes. After Page.navigate and a few seconds, Runtime.evaluate reads the array, giving the exact sequence of states the user saw (e.g. loading -> wrong text -> correct). Run it once against the old build and once against the fix so the check is shown to detect the bug. Screenshots and --dump-dom cannot catch this on pages that poll.
