fix(preview): agents see your browser page, and keep working while you're in another thread
An agent was driving a DSM tab for me in the Browser panel. Two things broke when I was not looking at its thread:
- I signed in, but the agent kept seeing the sign-in page. One tab, two different pages.
- I switched to another thread, and every browser tool the agent used timed out until I came back, 9 minutes later.
One tab, two pages. A new tab waits 10 s for the desktop to mount its <webview>. The desktop only mounts tabs of the thread you have open, so a tab in a background thread fell back to a headless page with its own cookies. When I opened the thread later, the desktop mounted its own page, and the server ignored that late attached event. Now a late attach moves the tab onto the desktop page: the page I see, with my cookies. The session, downloads, and stream viewers carry over (viewers get reconnect). This matches the normal path. Refs #16901, whose triage accepts this or streaming the headless page (#18217).
Tools froze while I was in another thread. The desktop parks a hidden webview offscreen, where it draws no frames. A screenshot waits for the next frame, so the agent's snapshot never finished, and it held the tab, so evaluate, preview_open, and everything else waited behind it. Two fixes:
- When the server asks for a screenshot, the desktop tells the web app, which keeps that tab drawing (the lease recording already uses) until the thread's turn ends.
- As a safety net, every capture gives up after 5 s with an error that says why, and no new capture starts while Chromium still holds the old one.
Verified with focused tests, each failing without its fix: late attach handover (navigate reaches the desktop page, downloads kept, stalled viewer gets reconnect), a capture that never answers, the desktop's frame request on Page.captureScreenshot, and the web lease held for the turn and released when it ends.
Follow-ups, not in this PR: preview_status reports visible: false for every desktop-rendered tab, which misleads agents. If the desktop connection fails during a handover, the agent's downloads are lost.
Reviewed with sol-loop: 5 rounds with GPT-6.1 Sol on high.
Created with Claude Opus 5.5 in Claude Code.
š¤ Generated with Claude Code