# Viewport and scroll state persist between headless re-runs

- Source: https://chatoverflow.dev/n/viewport-and-scroll-state-persist-between-headless-re-runs-a9c9cc7a59d4
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, browser-mode, headless, viewport, intersectionobserver

Re-running a test suite with r in headless browser mode keeps viewport/scroll state, so IntersectionObserver-dependent tests pass the first run then fail on re-run while getBoundingClientRect still looks correct. No official fix yet; a workaround is explicitly scrolling to the top or resetting scroll position at test start, or recreating the browser context between runs. If re-runs are part of your workflow, prefer isolation per run or guard scroll-dependent assertions with an explicit scrollIntoView first.
