Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: New desktop browser tabs can hang every wait, click and snapshot for good #32848

ClosedEntrpi(GitHub profile, opens in a new tab) opened this issue 1 comment

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

The bug is a timing race, so one try does not always show it. It shows more often when the machine is busy.

  1. Open the desktop app. Start a thread with any provider.
  2. Ask the agent to open a new Browser panel tab with no URL (preview_open, no url). An Incognito tab behaves the same.
  3. Ask the agent to run preview_wait_for with selector body, then preview_snapshot.
  4. Repeat with fresh tabs until one fails. On a loaded machine this took a handful of tries.

A reproduction that does not need an agent: an Electron 44 harness that runs the real DesktopBrowserHost, attaches a fresh <webview>, and connects Playwright through the relay when the host announces the guest. That is the same moment the server's awaitAttached connects. I can attach the harness if it helps.

Expected behavior

A fresh tab answers waits, locator actions and snapshots, like any other tab.

Actual behavior

On some fresh tabs, everything that uses Playwright's utility world never answers:

  • preview_wait_for with a selector never returns, and it holds the tab's action queue.
  • Locator-based preview_act calls hang.
  • preview_snapshot fails after about 8 s with "The page was too busy to capture".

Main-world preview_evaluate, raw CDP and screenshots still work on the same tab. An about:blank tab never navigates again by itself, so it stays broken.

A second form: when the first page commits while Playwright is still connecting, connectOverCDP fails with "Protocol error (Browser.setDownloadBehavior): Not attached to an active page".

Cause, from a protocol trace and the harness: the desktop announces the tab ("attached") as soon as the <webview> registers, before the guest has committed its first page. Electron guests are not paused for a debugger, so Playwright's ~100 ms setup can overlap the first commit. When setup finishes just before the commit, Playwright creates its utility world in the blank placeholder page. Then the first page commits (Runtime.executionContextsCleared), new main-world contexts arrive, and no utility context is created again. Connecting well before the commit, or after it, works.

Harness rates on main, Electron 44.10.1:

  • Fresh about:blank tabs, under CPU load: 2/126 rounds lost the utility world across two runs, and 13/80 in an earlier, more heavily loaded run. At idle: 1/87.
  • A targeted sweep that times the first response into the connect window: 14/21 (and 17/21 in an earlier run) failed with "Not attached to an active page". This sweep reproduces the mechanism. It is not a live rate.
  • Controls with no failures: connecting after the guest's first dom-ready (0/12), and the bare relay without DesktopBrowserHost (0/32).

Related, with the same symptom from other causes:

  • #24812 and #24829: after a relay reconnect to a guest that is already loaded, Runtime.enable replays no contexts, so the main-world context is missing. #24829 resets Runtime before a reconnect's first enable. That does not cover this case, a first connection whose utility world is created in the placeholder page. A fix for this case does not cover reconnects either.
  • #23936 and #32410: the screenshot never answers (hidden guest, legacy capture path). Here the screenshot works and the utility world is missing.

Impact

Major degradation or frequent failure

When it hits, that tab is unusable for the agent for good. Because the stalled wait holds the tab's queue, every later action on the tab also times out. An agent with no user present cannot recover by itself.

Version or commit

main @ a1af1841ed. The harness ran on a9e709f15f, which has the same desktop and server preview code, and the desktop preview code is unchanged on main @ 09a54f01bc. Also seen on the desktop Nightly 0.1.8-nightly.20261105.4205.

Environment

macOS, T3 Code desktop (Electron 44.10.1), Playwright 1.60, any provider

Logs or stack traces

# Harness, main, about:blank under load (one failing round)
connected 58 ms after attach, first commit at 59 ms
main-world evaluate: ok  raw CDP evaluate: ok
locator count: HUNG >3000ms
snapshot: ServerBrowserOperationError: The page was too busy to capture ...

# Harness, main, first response timed into the connect
browserType.connectOverCDP: Protocol error (Browser.setDownloadBehavior): Not attached to an active page

Workaround

Close the tab and open a new one. That is another roll of the same race. Navigating the broken tab to another page sometimes restores it, but not always.

Proposed fix

I have a fix ready and will open a PR once this is triaged. DesktopBrowserHost announces a guest that is still blank and loading only once its first page is up (dom-ready) or its first navigation ends without a page, so Playwright does not connect across the first commit. After 5 s it announces the guest anyway, which leaves the server's 10 s attach timeout room. Every other guest (a re-attach, or one that already stopped loading) is announced at once, as today.

  1. [GPT-6.1 Sol][Codex] on behalf of shivam.

    Handing this investigation to Julius's fix at https://github.com/pingdotgg/t3code/pull/32861. No source changes made here.

    Independent baseline reproduction at 09a54f01bc0ae83865347a965ced50f8c8ec2953, Debian Linux x64, Electron 44.10.1, Playwright 1.60.0: a real-webview harness using DesktopBrowserHost failed 2/21 first-response timing-sweep connections with Browser.setDownloadBehavior: Not attached to an active page; connecting after dom-ready passed 12/12 controls. These are targeted timing sweeps, not user failure rates. In one failure, the host announced at 8.60 ms, the first page committed at 31.32 ms, and dom-ready arrived at 42.63 ms.

    vp test run apps/desktop/src/preview/DesktopBrowserHost.test.ts apps/server/src/preview/DesktopBrowserChannel.test.ts passed 36/36 on that baseline. The permanent utility-world hang, macOS behavior and PR head were not independently verified here. All harness processes are stopped.

  2. juliusmarminge closed this

Sign in to join this conversation.