Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): typing after a click by coordinates no longer hangs a preview tab #32845

MergedEntrpi(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/32845/headmerged by maria-rcks View on GitHub

Entrpi(GitHub profile, opens in a new tab)commented

Problem

preview_act type with no locator can hang forever, even though it takes a timeoutMs. To find the focused element, ServerBrowserPage.type builds page.locator("*:focus").last() and awaits its count(), which takes no timeout. That query runs in Playwright's utility world. On a desktop-drawn tab that lost its utility world while connecting, the query never settles. So type never ends, and it holds the tab's SessionControl queue. Every later action on that tab then times out at the broker. This is the same wedge as preview_wait_for on main (fixed separately in #32846).

Those are the tabs where an agent cannot get element refs and must click by x and y. "Click the field by position, then type" is exactly the flow that hangs.

A bound on count() alone does not make typing work. locator.evaluate resolves its target through waitForSelector, which also runs in the utility world. On those tabs every type after a coordinate click would then fail at its timeout instead of hanging.

Change

Only apps/server/src/preview/ServerBrowserPage.ts (type) and its test file change.

The focus check already ran in the page's main world, and main-world page.evaluate still works on the affected tabs. So the lookup now runs there too:

  • The inline check moves to a module-level focusTextTarget(target | null). Its body is the same as before: an enabled, writable text control or contentEditable element, then focus(), then the getRootNode().activeElement test. The locator path calls it with locator.evaluate(focusTextTarget, undefined, { timeout }) and keeps its behaviour.
  • With no locator, it starts from document.activeElement and walks open shadowRoot.activeElement to the innermost focused element, as .last() did. Closed shadow roots stop at the host, which is refused, as before.
  • It refuses iframe, frame, fencedframe, object and embed explicitly. From the top document it cannot confirm that a text field has focus inside a frame. Without this, an editable iframe (or an iframe inside a contenteditable element) passes as isContentEditable. I checked this in Playwright 1.60 headless Chromium. Text then lands in the frame, or, for a frame with no field, type reports success and nothing changes. Main refused these only because *:focus matched nothing. Typing into a frame is a possible follow-up and needs a real check inside the frame.
  • The no-locator path runs it with one page.evaluate, raced against a single expiry timer. The timer is cleared in finally. On expiry it throws PreviewAutomationTimeoutError with detail.timeoutMs, before any text is typed. evaluate and waitFor in the same module use this expiry shape.
  • The *:focus locator, its count() and the shadow-host comment are gone. The not-editable error, the clear keypresses and insertText do not change.

For reviewers reading Playwright's source: page.evaluate runs through Playwright's UtilityScript, which is injected into the main context. That is not the utility world.

Behaviour changes:

  • On a tab whose utility world never answers, type with no locator now types.
  • On a page busy past timeoutMs, it fails at timeoutMs without typing. Before, it waited past its timeout and then typed late, or hung if the page never answered.
  • document.activeElement does not need the window to be focused, but *:focus did. So an unfocused page can now be accepted, as the locator path already allowed. Server commands keep focus emulation on, so this rarely differs.
  • A navigation during the probe now gives Playwright's "Execution context was destroyed" error, where main usually gave not-editable. Both happen before any text is typed.

What this does not do:

  • It does not cancel an expired probe. The probe only reads, and it calls focus() on the element that already has focus, so it cannot move focus when it runs late.
  • insertText and the clear keypresses stay unbounded. Abandoning them midway would make "no text was typed" untrue. That is the general queue defence, out of scope here.
  • A type queued behind another action on the same tab can still overrun the broker grace. That belongs to the broker's timeout handling.

Model-facing text: the tool description, schema and immediate result do not change. The error carries only detail.timeoutMs, so the broker still returns "Preview automation type timed out after Xms." The new message, "The page did not report its focused element within Xms, so no text was typed.", reaches agents one step later: recordAction stores the error's first line in the action timeline, and later preview_snapshot results return it. Before this fix that case never ended and showed a "running" entry forever. No eval case was added; see the question below.

Surfaces: the MCP preview_act type is the only entry point (ServerBrowser.ts is its only caller). No UI, palette or keybinding types for an agent. It is server-only, provider-neutral MCP, and the same for local, remote and tunnel connections. Desktop-drawn and headless tabs share the code path. No contract, broker, SessionControl or docs change.

Scope and approval

This is a very small fix for an obvious bug: a call that takes a timeout can hang forever and wedge the tab's queue. It moves the existing focus check out of type and adds about 35 lines around it, all in one file, with two failing-first tests and one guard test. It changes no contract, setting or tool text. Per CONTRIBUTING.md, a focused fix like this can go straight to a PR.

It also matters for snapshots that come back without element refs (#23936, #28136): the agent then has to act by x and y from the screenshot, which leads to exactly this click-then-type flow.

Verification

Base: upstream main 09a54f01bc. Rebased onto 9e12eca125 to resolve a test-file conflict with #31925, which added its own describe block in the same place. Main was later merged in to resolve the same kind of conflict with the describe blocks of #32846 and #36365; the last merge is 86e4449927, on main dea07a1b12. vp run check:changed passes on the merged branch (44 tests in the 2 changed files).

Tests that fail on main (09a54f01bc), with ServerBrowserPage.ts reverted:

  • apps/server/src/preview/ServerBrowserPage.test.ts > "server browser type" > "types into the focused field when Playwright's utility world never answers". It uses a fake page whose locator().last().count() never settles, and vitest fake timers. It records the outcome in a variable instead of awaiting the promise, so on main it fails at once and does not hang to the test timeout. On main, after 300 ms of fake time the outcome was still pending and nothing was typed (expected 'pending' to be 'typed'). With the fix it types "hello".
  • Same describe, "stops at its timeout without typing when the page never answers". Here page.evaluate also never settles, which stands for a busy main thread. On main the call is still stuck on count() after 300 ms (expected 'pending' to match object { tag: "PreviewAutomationTimeoutError", detail: { timeoutMs: 300 } }). With the fix it rejects with that error, and nothing is typed.

Guard test that passes on main by design:

  • "server browser element refs" > "types after a click by coordinates into a shadow-root field, and refuses a field inside an editable frame". Real Chromium. It clicks an input in an open shadow root by x and y and types into it. Then it clicks an input in an iframe inside a contenteditable element, and expects PreviewAutomationTargetNotEditableError with the inner value unchanged. This is the only test that runs the no-locator branch in a real page: the activeElement walk, the shadow descent, serializing a module-level function through page.evaluate, and the frame refusal. With the frame-refusal line removed, it fails (promise resolved 'undefined' instead of rejecting), because the editable iframe passes the check and the text lands in the frame. A comment in the test says the frame refusal is current behaviour with a reason, not a product goal.

With the fix, the whole file passes (27 of 27). A fresh vp run check:changed on this branch passes: format, lint, knip, graphql, typecheck of the 3 affected packages, and tests for the 2 changed files (29 tests).

Evals: none. No eval case belongs to this fix, because no tool description, schema or immediate result changes.

Live check, on a dev desktop build with this commit and other preview fixes merged: an agent opened a form page in a desktop-drawn tab, clicked the name field by x and y, and called preview_act type "Ada" with no locator. It returned in about 30 ms, and the field then read "Ada". That build also had a fix for the desktop connect race, so the tab had a working utility world. It shows the new main-world lookup finds the field in a real desktop tab. It does not show the hang itself, which the unit tests and the runtime check below cover.

Runtime check, with no dev server: real headless Chromium through playwright-core, calling ServerBrowserPage.type directly with no locator after a page.mouse.click by x and y. Case 1 replaces only Playwright's locator queries with ones that never settle, as on a desktop tab with no utility world. Case 2 keeps the page's main thread busy for 5000 ms.

[main]   case 1: type { text: 'hello', timeoutMs: 2000 }
[main]   type: still pending after 6000ms (script watchdog gave up)
[main]   field value: ""
[main]   case 2: page main thread busy for 5000ms; type { text: 'x', timeoutMs: 2000 }
[main]   type: resolved after 4969ms
[main]   field value: "x"
[branch] case 1: type { text: 'hello', timeoutMs: 2000 }
[branch] type: resolved after 2ms
[branch] field value: "hello"
[branch] case 2: page main thread busy for 5000ms; type { text: 'x', timeoutMs: 2000 }
[branch] type: rejected: PreviewAutomationTimeoutError: The page did not report its focused element within 2000ms, so no text was typed. after 2001ms
[branch] field value: ""

Not checked: an MCP-level transcript of the timeout from a real client. In the live pass, the page's busy script had already ended when its type ran, so that call just typed.

No before/after captures: nothing visible in a client changes.

Questions for maintainers

  • After a probe timeout, the new message "The page did not report its focused element within Xms, so no text was typed." appears in the action timeline that later snapshots return. It states only facts, like the other timeline failure strings there (such as Playwright's "locator.evaluate: Timeout 15000ms exceeded."). No observed agent behaviour depends on it, so I did not add an eval case. Is that acceptable, or do you want one?

Built with Claude Opus 5.5 in Claude Code (run from T3 Code); reviewed by GPT-6.1 Sol in Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at de3dc14

      Macroscope's review found this PR approvable — Preview typing now checks focus without relying on Playwright’s utility world and times out instead of hanging. The change remains confined to requested typing operations and retains editable-target safeguards.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      No-locator typing now checks the focused text target through page-side evaluation. The check follows nested shadow roots, rejects frame-like focused elements, and times out if the page does not report focus. Locator-based typing remains unchanged.

      Changes: Preview typing focus validation

      Layer / File(s)Summary
      Validate focus before typing
      apps/server/src/preview/ServerBrowserPage.ts, apps/server/src/preview/ServerBrowserPage.test.ts
      No-locator typing uses a timeout-bounded page-side focus check. Tests cover shadow-root typing, iframe rejection, and stalled focus checks.

      Estimated code review effort: 2 (Simple) | ~15 minutes

      Change: Bug fix

      Suggested reviewers: maria-rcks, juliusmarminge

      Merge Risk: Minimal · up to 86e44

      Typing after a coordinate click now checks focus in the page itself and times out rather than hanging the preview tab. No actionable merge-blocking risk remains.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: typing after a coordinate click no longer hangs a preview tab. The changeset moves the no-locator type focus check into the page's main world, which removes the utilit…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe description follows the template's sections: Problem, Change, Scope, and Verification are all present and substantively filled. It states the bug, the mechanism, the fix, scope justification, the …
      Full details: Title check

      Explanation

      The title names the main change: typing after a coordinate click no longer hangs a preview tab. The changeset moves the no-locator type focus check into the page's main world, which removes the utility-world hang. The title follows the conventional commit format and is specific enough for a teammate scanning history.

      Full details: Description check

      Explanation

      The description follows the template's sections: Problem, Change, Scope, and Verification are all present and substantively filled. It states the bug, the mechanism, the fix, scope justification, the test results, and a runtime check with output. Items the template asks for are covered. The description also explains what was not checked. Minor gaps: the title is not stated in the description body, and the template's Scope section asks for a linked issue. The description cites PR #32846 and related PRs, but it does not link an issue that shows the bug. It gives a reason for skipping one. The Verification section is thorough. The agent-attribution line at the end is present, which the template requests.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 92439ba47f7172661944906530fde5283d3c4fe5 and 86e444992745b3b6274f37ba3f630f9184aab742.

      Files selected for processing: 2

      • apps/server/src/preview/ServerBrowserPage.test.ts
      • apps/server/src/preview/ServerBrowserPage.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

    4. Independent source review at exact head de3dc144d4b5c28340b8333c07a7cc3a7879ec60, author Entrpi distinct from reviewer Wladefant.

      I traced the no-locator focus lookup, nested open-shadow-root traversal, text-control/readOnly/disabled checks, frame refusal, timeout race and the unchanged locator/clear/insertText paths. The bounded main-world probe is coherent with the reported utility-world failure; I found no independently demonstrated P1/P2 in this diff.

      Qualification HOLD — changed-module CI is missing. Normal exact-head all-event run 42455141924 completed with Test Server shards 1–8, Lint, Test, Build/Typecheck and Check successful. I inspected every server-shard command: none selected apps/server/src/preview/ServerBrowserPage.test.ts (the changed regression file). Test Web, Rust, mobile-native static analysis and release smoke were skipped. The PR's author-reported local ServerBrowserPage.test.ts 27/27 and check:changed do not replace admitted exact-head CI evidence. Please obtain the normally admitted changed-module test result; do not infer it from the green wrapper.

      The PR's recorded base is 09a54f01bc0ae83865347a965ced50f8c8ec2953; current main is 8e6a7323050ea8d2891f745f7e624e84f9fd8d9a (three commits ahead). The branch is one commit ahead and three behind current main. No rebase/merge or branch mutation was performed; the maintainer/author retains composition and landing custody.

      Disposition: COMMENTED / source review only, not APPROVED and not merge-qualified. No local tests, CI dispatch, merge, installation or browser acceptance performed.

    5. Thanks for the review. CI did run the changed test file on this head. In run 42455141924 (head de3dc144d4), Test Server 4 runs vp test run 'src/preview/ServerBrowserPage.test.ts' and reports ✓ src/preview/ServerBrowserPage.test.ts (27 tests). Those are all 27 tests in the file, with the three new ones. The test cache runs each file as its own command, so the file appears in that shard's log as a separate step, not in the shard's command line.

    6. Wladefant(GitHub profile, opens in a new tab) approved these changes

      Independent source approval at exact head de3dc144d4b5c28340b8333c07a7cc3a7879ec60 (author Entrpi, reviewer Wladefant). I traced the no-locator focus lookup, nested open-shadow-root traversal, editable/readOnly/disabled checks, frame refusal, timeout race, and unchanged explicit-locator/clear/insertText paths. No P1/P2 defect was demonstrated.

      CI correction: I initially filtered the Test Server 4 log incompletely and incorrectly said the changed module was absent. Full job 128652435196 from all-event run 42455141924 checked out synthetic merge 1f902a4 containing the exact candidate and ran vp test run 'src/preview/ServerBrowserPage.test.ts': 27/27 passed, including the three new cases. Applicable Lint, Build/Typecheck, Test, Check and server shards succeeded. Test Web, Rust, Mobile Native Static Analysis and Release Smoke were skipped; these are not applicable to this server-only change. The earlier missing-module qualification hold is withdrawn.

      The recorded PR base 09a54f01bc0ae83865347a965ced50f8c8ec2953 is three commits behind current main 8e6a7323050ea8d2891f745f7e624e84f9fd8d9a; the intervening main commits do not touch the changed server preview files. This approval is for the exact source delta only. No merge, deployment, installed-browser test or operator-session acceptance is claimed.

    7. Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified as-is at 7ed3bdaceeac2a143c94a3a535644badc8a12a0c on this linux boat vm. no code changes or pushes.

      ran github/main (e4d86abca9) in a separate worktree first, stopped it, then ran the exact pr head. both used vp i and a background vp run dev with isolated, unseeded state. drove the web app with the repo's playwright and /usr/bin/google-chrome, added the real git repository through the app, and submitted real codex gpt-6.1-sol turns. those turns exercised the running server's preview mcp tools against wikipedia's real search field, without mocks or fixtures.

      reproduced a changed timeout behavior on main: after clicking the field by coordinates, a no-locator typing call reported a timeout but inserted its text later. on the pr, the same call timed out and left the field unchanged after the busy period ended. the page was made genuinely busy for 60 seconds with a scheduled javascript loop; playwright and the server were not replaced or patched.

      short transcript from the persisted provider tool results:

      both: explicit #searchInput replacement -> "baseline"
      both: coordinate click -> schedule 60-second page loop -> wait 3 seconds
      both: preview_act {action:"type", text:"SHOULD-NOT-TYPE", clear:true, timeoutMs:1000}
            no locator or selector
      
      main 08:46:09.076 -> 08:46:11.109 UTC:
        "Preview automation type timed out after 1000ms."
      main 08:47:20.366 UTC, after the busy interval:
        #searchInput.value = "SHOULD-NOT-TYPE"  (late insertion)
      
      pr   08:51:20.858 -> 08:51:21.888 UTC:
        "Preview automation type timed out after 1000ms."
      pr   08:52:32.745 UTC, after the busy interval:
        #searchInput.value = "baseline"  (unchanged)
      
      pr: next coordinate click + no-locator clear/type -> "recovered"
      pr: focus language selector + no-locator type -> editable-target error
      pr: search value remains "recovered"

      normal coordinate typing, explicit-selector replacement, clearing, and typing after the timeout all worked. the noneditable-target guard still rejected typing into the focused language selector. i inspected the saved screenshots and the short interaction recording.

      main after the expired call inserted text late:

      main: timed-out typing later inserted SHOULD-NOT-TYPE

      pr after the same expired call left baseline unchanged:

      pr: timed-out typing left baseline unchanged

      vp run check:changed HEAD^ passed through blacksmith-check: format, lint, knip, graphql, typechecks for 3 affected packages, and 35 tests across 2 files. the worker needed its playwright chromium installed before the successful run. github's exact-head checks are also green.

      Not verified

      the original desktop-drawn tab losing its playwright utility world was not reproduced here. the real-app reproduction above covers the busy-main-thread timeout and late-insertion behavior, plus the normal web-hosted preview path. native desktop/mobile clients, other providers, and relay/tunnel connections were not exercised. the preview action timeline was omitted from the bounded snapshot response, so its new timeout message was not checked.

    8. tanstack-source added labelsbug

    9. maria-rcks merged thisf00afc6

    10. maria-rcks closed this

Sign in to join this conversation.