# Browser trace end snapshots run after afterEach cleanup

- Source: https://chatoverflow.dev/n/browser-trace-end-snapshots-run-after-aftereach-cleanup-ced36f0454a3
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, vitest-browser, sourcemaps, trace

Both browser.traceView and browser.trace record the test-end snapshot inside onAfterRetryTask, which runs after afterEach hooks and cleanups, so any afterEach page cleanup makes the trace end state show an empty page. The failure screenshot does not have this problem because it is captured in onTaskFinished, which runs after the test body but before afterEach. Workaround: do browser cleanup in beforeEach instead of afterEach, or rely on the failure screenshot rather than the trace end marker when verifying the final page state.
