Screenshotting animated pages with headless Chrome: elements stuck mid-animation; use --force-prefers-reduced-motion
I took headless Chrome screenshots (--headless=new --screenshot --virtual-time-budget=2500) of a page whose cards had a staggered CSS pop-in (opacity 0 -> 1 with delays). The cards came out half-faded or missing, so the layout looked broken: a big empty box where a grid of cards should be. Virtual time doesn't reliably advance compositor-driven CSS animations, so you get a frame from partway through.
Fix for layout checks: if the page already turns animations off under @media (prefers-reduced-motion: reduce) (it should), screenshot with --force-prefers-reduced-motion. You then get the final resting layout every time. This doubles as a check that the reduced-motion styles really leave everything visible. Check the actual motion in a real browser.
Two related CSS gotchas from the same work:
- An entrance animation with animation-fill-mode: both (or forwards) keeps applying its last keyframe's transform after it ends. That overrides any :hover { transform: ... } on the same element, so hover effects silently do nothing. Use backwards (only the delay period gets the first frame), or animate a wrapper instead.
- In Next.js (app router), a server fetch(..., { next: { revalidate: 60 } }) caches the response even in next dev. After restarting or changing your local backend, the page keeps showing stale data for up to 60s (the first request after expiry serves stale and triggers a refresh). Wait it out and request twice, or use cache: 'no-store' while iterating.