[Bug]: Agent screenshots of an unwatched desktop preview catch animations mid-way #34707
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/desktop
Steps to reproduce#
- Desktop app on macOS. An agent opens a preview tab, and the Browser panel shows another tab or is closed.
- The T3 window is covered by another app's window or minimized.
- The agent changes the page so that elements fade in (a 150 ms Web Animations opacity fade, like the sidebar's entering rows), waits 600 ms, then calls
preview_snapshot.
On current main, step 3 times out before it gets this far (#23139), so this shows once a covered-window capture fix is in. I measured it on main plus my covered-window fix (061c457f0a, data in #23139), with the screen unlocked.
Expected behavior#
The snapshot shows the page as it is 600 ms after the change: the fade has finished.
Actual behavior#
The fade is caught mid-way:
| T3 window | snapshots with the fade caught mid-way |
|---|---|
| in front | 0 of 8 |
| covered | 4 of 8 |
| minimized | 6 of 8 |
The tab was hidden (Browser panel closed) or a background tab of the panel; both behaved the same. Elements repainted synchronously or from requestAnimationFrame were always current, and so were content-visibility: auto rows. Only the compositor-driven fade was behind.
Agents judge UI state from snapshots of tabs the user isn't watching. Enter and exit transitions (sidebar rows, menus, toasts) come back half-drawn, so an agent can misread a state that has in fact settled.
Impact#
Minor bug or occasional failure
Version or commit#
main 76b3e3390e plus 061c457f0a
Environment#
macOS 27.2.1 (arm64), Electron 44.10.1, display scale 1, desktop dev build. The agent tools were driven through the dev server's MCP endpoint.
Logs or stack traces#
No response
Screenshots, recordings, or supporting files#
Workaround#
None found. Waiting before the snapshot doesn't help: 600 ms is four times the fade's length, and the fade still had not run, because it does not advance until the guest is drawn.
Cause and a possible fix#
Chromium starts a guest's compositor animations only once the guest is drawn. A guest resting off screen, or in a covered or minimized window, defers them. When the desktop host paints it for a capture, Page.captureScreenshot takes the first frame after drawing resumes. requestAnimationFrame itself kept running at about 60 fps in every state while the agent drove the tab, so the gap is drawing, not frames.
Fix: once the desktop host paints a guest for a screenshot, it waits before sending for two guest frames and the page's running finite animations (document.getAnimations()), at most 500 ms. On the same build that gave 0 of 24 snapshots mid-fade (median 144 ms, against 71 ms without the wait). On my fork, 0 of 42 were mid-fade across 21 panel, tab and window states. Infinite animations are skipped, so a spinner never holds a capture. I have this as a branch with a test and can open a PR once the direction is agreed.
Edited 11-14: corrected the macOS version. These runs were on macOS 27.2.1, not 26.5.
tanstack-source added labelsbug
Sign in to join this conversation.