[Bug]: preview_press does not reliably target the preview page #3715
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#
Start T3 Code Desktop.
Open a Codex-backed thread with the T3 preview MCP tools available.
Open any page in the browser preview.
Install a page-level keydown listener:
(() => { window.__t3KeyEvents = []; window.addEventListener( "keydown", (event) => { window.__t3KeyEvents.push({ key: event.key, code: event.code, target: event.target && event.target.tagName, active: document.activeElement && document.activeElement.tagName, time: Date.now() }); }, true ); return { active: document.activeElement && document.activeElement.tagName, events: window.__t3KeyEvents }; })()Confirm
document.activeElementisBODY.Call
preview_pressbefore clicking inside the page:{ "key": "b" }Read
window.__t3KeyEvents.Click inside the preview page body with
preview_click.Clear the log and call
preview_pressagain:{ "key": "c" }Clear the log and call
preview_presswithEscapethree times.In a separate hidden or degraded tab, call
preview_presswithTab, then call a simplepreview_evaluate.
Expected behavior#
preview_press should target the selected preview page consistently when a tabId is provided.
If the preview page is not focusable or the tab cannot receive keyboard events, the tool should return a clear failure. It should not return null while no key event reaches the page.
Keyboard events should not go to the T3 host prompt when the agent is trying to target the preview page.
Actual behavior#
Before a real click inside the page, preview_press("b") returned null, but the page captured no key event:
{
"active": "BODY",
"events": []
}
After clicking the page body, preview_press("c") returned null and the page captured the event:
{
"active": "BODY",
"events": [
{
"active": "BODY",
"code": "KeyC",
"key": "c",
"target": "BODY"
}
]
}
After focus was established, three Escape presses all returned null, but only two page-side keydown events were captured.
In an earlier run, a printable key was not captured by the page and the human operator observed that the character appeared in the T3 prompt input instead.
On a previously degraded invisible tab, preview_press("Tab") timed out after 15 seconds, and a simple preview_evaluate immediately afterward also timed out.
Impact#
Major degradation or frequent failure
Version or commit#
T3 Code desktop 0.0.28-1 via t3code-bin AUR package.
Environment#
Arch Linux x86_64, kernel 7.0.13-arch1-1, T3 Code desktop AppImage package via t3code-bin, Codex provider.
Logs or stack traces#
Representative timeout after pressing in a degraded invisible tab:
PreviewAutomationTimeoutError: Preview automation press timed out after 15000ms.
PreviewAutomationTimeoutError: Preview automation evaluate timed out after 15000ms.
Screenshots, recordings, or supporting files#
No screenshot included. Page-side key event logs are the relevant evidence. A recording could help demonstrate the host-prompt mutation, but the agent cannot inspect that host input directly.
Workaround#
Before using preview_press, click inside the preview page and verify delivery with a page-side listener or an observable page effect. Avoid keyboard workflows in hidden or already-degraded tabs. Prefer preview_type for text input and preview_evaluate for state changes that are not specifically testing keyboard behavior.
Sorry for the delayed response, but no, I am not using remote instances here. This is all local here
Summary#
Keystrokes issued through T3 Code's
preview_pressbrowser-automation tool were explicitly targeted at one preview tab, but some of those keystrokes appeared in an unrelated input field that the user was actively editing.This appears to violate the isolation boundary between an agent-controlled browser preview and other user-controlled surfaces. Depending on which surfaces can receive the leaked events, a malicious agent might be able to inject text or commands into T3 Code controls, terminals, authenticated forms, or conversations with other agents.
I have not confirmed command execution, cross-agent control, or a JavaScript sandbox escape. Those are potential impacts that should be investigated.
Confirmed observation#
At
2026-08-11T06:12:19.572Z, an agent ran the following tool-orchestration code:for (const key of "thisisunsafe") { await tools.mcp__t3_code__preview_press({ tabId: "tab_5", key, }); }The intention was to send Chrome's interstitial bypass sequence exclusively to preview tab
tab_5.While this happened, the user was working in an unrelated input field and saw the characters:
s...a...f...e...appear one at a time over approximately two seconds. This exactly matches the final four characters of the automation sequence.
No Enter key, modifiers, click, or submit action was sent during this event.
Expected behavior#
preview_press({tabId: "tab_5", ...})should deliver input only to the browser target identified bytab_5.If strict delivery cannot be guaranteed, the tool should fail closed without generating any keyboard event.
It should never deliver input to:
- another preview tab;
- a T3 Code host-interface input;
- an editor or terminal;
- an input associated with another worktree or agent session;
- another application or globally focused operating-system control.
Actual behavior#
At least four character events intended for
tab_5reached an unrelated user-focused input.The gradual character-by-character appearance suggests that the individual
preview_pressevents themselves were misrouted, rather than text being copied or pasted by the user.Security impact#
This may create a confused-deputy or capability-boundary vulnerability. An agent authorized only to automate a browser preview could potentially act with the user's authority in another focused surface.
Potential impacts requiring investigation include:
- injecting commands into a focused terminal and submitting them with Enter;
- modifying or submitting authenticated forms;
- typing into T3 Code control-plane inputs;
- sending instructions or messages to unrelated agent sessions;
- triggering keyboard shortcuts with modifier keys;
- interacting with another worktree, window, or browser tab;
- bypassing permissions that assume preview automation is tab-scoped.
User focus appears to be a precondition in this observation, but that does not make the behavior safe because agents can issue individual keys, Enter, and modifier combinations.
Scope and confirmed limits#
The observed event proves cross-surface character injection.
It does not currently prove:
- arbitrary command execution;
- access to another agent's environment;
- use of collaboration or agent-management APIs;
- a JavaScript page-sandbox escape;
- persistence outside the affected input;
- successful form submission.
An audit of the affected session found no calls to agent spawning, agent messaging, follow-up, or interruption tools. The accidental sequence contained no Enter key, so it did not execute or submit the text it injected.
Suggested reproduction#
Use only disposable inputs and environments for this test.
- Open a T3 Code browser preview and record its
tabId. - Focus a harmless canary input outside that preview.
- Invoke
preview_pressrepeatedly with the preview's explicittabId. - Check whether any character or input event reaches the canary field.
- Repeat with:
- the target preview visible and hidden;
- multiple preview tabs;
- multiple worktrees or agent sessions;
- host UI, editor, and terminal canary fields;
preview_type, Enter, and modifier combinations;- focus changing during a sequence.
Do not test Enter or shortcuts against a real terminal or authenticated form.
Suggested remediation#
- Deliver keyboard events through a CDP or equivalent session bound to the exact target tab and frame.
- Do not use operating-system-level or globally focused keyboard synthesis for preview tools.
- Assert the target browser context, tab, frame, and web contents before every event.
- Fail closed if the requested target is unavailable or cannot be uniquely resolved.
- Audit
preview_type,preview_click, paste, drag-and-drop, and other input-producing tools for the same routing problem. - Add isolation tests proving that non-target tabs and T3 Code host controls receive no input events.
- Test concurrent user interaction and focus changes during multi-key sequences.
- Include the resolved destination tab/frame in browser-action audit records.
- Consider temporarily disabling
preview_pressmodifier and Enter support until isolation is verified.
Environment#
- T3 Code Desktop v0.0.33 on macOS
- Session originator:
t3code_desktop - Codex CLI recorded by the session:
0.147.0 - Date: 2026-08-11 UTC
Adding my encounter with this bug here rather than opening a new report. In my case, the agent attempting browser control was running from a remote
t3 servesession. It was able to send keystrokes to the client machine's T3 desktop app.I haven't investigated whether a clever agent could use this as a sandbox escape mechanism to control the client machine's agents (or agents within in the fleet of connected machines).
Possible security concern.
I think I just stumbled upon this issue as well. Regular keys were not passed, but as I was writing a prompt in a different thread, it got suddenly sent because a different agent (running on remote env) with web browser pressed Enter key.
I have encountered this as well while using the T3 browser preview. An Enter key event triggered by browser automation was intermittently routed to the T3 Code prompt composer instead of remaining scoped to the preview, causing the prompt I was writing to be submitted unexpectedly.
The affected prompt was outside the browser preview, and I did not manually press Enter at the time. The intermittent, cross-surface behavior matches the reports above and makes
preview_pressunsafe for Enter while another T3 Code input is focused.We are also experiencing this on T3 Code 0.0.40 on macOS 27 with Codex. Key inputs intended for the T3 browser preview also reach the T3 Code interface, interfering with the prompt input.
#11354 appears to address the mistaken keystrokes part of this commit (thank you @maria-rcks!)
Unfortunately, preview_click still takes focus away from the composer.
Repro: Keep typing in the composer. Have the agent open a preview with
preview_open(open: true). Have the agent click a heading withpreview_click.Result: lose focus on the composer
Written by a human: As reported in #17478, the mistaken keystrokes part of this issue has regressed. :/ Unlike most of my other reported issues (which tend to be unimportant QoL stuff), this one is actually a seriously disruptive issue that I would very much like to get fixed.
Written by AI, for AI:
Confirmed recurrence: preview input reaches the wrong tab or composer#
Reproduced October 10, 2026, on T3 Code Desktop at
477282263a9115f911380b5aec7d4973267e4edc, with Codex, on Arch Linux x86_64. The operator confirmed the running build’s checkout commit. The preview’s user agent reported Electron 44.4.5 / Chromium 152.0.7977.130.preview_pressandpreview_typereturned success without delivering input to the explicitly requestedtabId. The reproduction confirmed wrong-tab delivery through page-side event logs. The operator separately confirmed probe text appearing in the T3 composer.Expected behavior: input reaches only the requested preview tab. Other previews and the composer remain unchanged. Failed delivery is reported as a failure.
Reproduction#
Use a disposable Desktop session with no valuable drafts or consequential inputs: this sequence can modify the composer. Only literal probe text and printable keys were used; no Enter, submission shortcuts, or authenticated forms were tested.
Create tab A:
preview_open({ open: true, reuseExistingTab: false, url: "https://example.com" })Install this fixture through
preview_evaluate, explicitly targeting A:(() => { document.body.innerHTML = '<label>Name <input id="name" aria-label="Name"></label>'; window.__probe = []; for (const type of ["keydown", "keyup", "beforeinput", "input"]) { document.addEventListener(type, event => { window.__probe.push({ type: event.type, key: event.key ?? null, data: event.data ?? null, target: event.target.id, trusted: event.isTrusted }); }, true); } })()Before any automated click, send these calls with A’s
tabId, reading the fixture after each:preview_press({ tabId: A, key: "q" }) preview_type({ tabId: A, locator: "role=textbox[name='Name']", text: "t3probeA" }) preview_type({ tabId: A, locator: "role=textbox[name='Name']", clear: true, text: "t3probeB" })Read with:
({ value: document.querySelector("#name").value, events: window.__probe, active: document.activeElement.tagName, focus: document.hasFocus() })Click A’s input with
preview_click, then explicitly target A withpreview_press("r")andpreview_type("t3probeA").Create fresh tab B with
open: falseandreuseExistingTab: false. Install the same fixture. Explicitly target B withpreview_type("t3probeB"), using the same locator, thenpreview_press("q").Read both tabs.
Observed in the independent verification:
- Before clicking A, all three calls returned success. A remained empty and recorded no keyboard or input events. After each typing call, its active element was
INPUTanddocument.hasFocus()wastrue. - After clicking A, pressing and typing worked. A contained
rt3probeAand recorded trusted events. - Calls targeting B returned success, but B remained empty with no events. A received the input instead and became
rt3probeAt3probeBq. - The operator confirmed probe text appearing in the composer during the pre-click calls. Composer events were not instrumented, so individual leaked characters cannot be attributed to particular calls.
- Both tabs reported
visible: false, including A opened withopen: true. This status does not establish actual Desktop panel visibility.
Both disposable tabs were closed afterward. No fix was applied.
Source findings and regression history#
The current delivery paths at the reproduced commit are:
ServerBrowserPage.type: locator +clear: trueuseslocator.fill(). Other typing checks DOM editability/focus, then usespage.keyboard.insertText(). Neither branch verifies the resulting field value.ServerBrowserPage.press: usespage.keyboard.press()without page-side delivery confirmation.DesktopBrowserHostandCdpRelay: forward commands to the guest debugger without equivalent keyboard isolation or delivery confirmation.
Relevant history:
- #11354 merged September 12, adding native, frame-targeted keyboard delivery, host-forwarding suppression, and delivery confirmation. #5792 was subsequently closed. My September 12 comment reported that mistaken keystrokes appeared addressed, while
preview_clickstill stole composer focus. - #15008 merged October 3 and added click-focus restoration; #10980 closed that day.
- #15328 merged October 6, moving automation to the server’s Playwright engine and deleting
PreviewKeyboard.ts,previewClickFocus.ts, and the previous Desktop automation path.
All three merged changes are ancestors of the reproduced commit. This makes the migration a likely regression point. No before/after build comparison or bisect was performed, and the precise Electron routing mechanism remains unproven.
#17478 independently reports recurrence on October 8–9 macOS nightlies. Its initial source analysis identifies the removed isolation path; its follow-up also reports failure with
clear: true.Open PR #8494 targets the removed Desktop implementation. PR #9522 is closed and unmerged. Neither establishes a fix for the current path.
Evidence needed for a fix#
Keep the investigation focused on preview input delivery and isolation. The observed focus dependence is a useful starting point, but DOM focus and successful CDP responses do not establish the destination.
A regression test should exercise real Electron guests, with the composer or another preview focused, and assert both:
- The requested target receives the intended input.
- Other previews and the composer receive no input.
Cover
preview_typewith and withoutclear: true,preview_press, fresh/background tabs, and the A-to-B sequence above. Check click-focus preservation when changing focus handling, since the migration also removed that safeguard. Headless Chromium checks alone cannot establish Electron guest isolation.Clicking first enabled delivery in A, but subsequent input targeting B reached A, so it is not a verified isolation workaround. Direct DOM form editing is reported as a temporary workaround in #17478; it does not validate native keyboard correctness.
Cross-thread/window behavior and human typing after an automated click were not independently verified. Any proposed fix should report the focused checks, observed results, and remaining platform or connection-mode gaps, consistent with CONTRIBUTING.md’s verification requirements.
Originally investigated with GPT-6-Astra through the Codex harness in T3 Code. Independently reproduced, fact-checked, and revised with GPT-6.1-Sol through the same harness.
Note
Grok responding on behalf of Julius.
Fixed by #18556, now on main. Agent
preview_typeandpreview_pressinput no longer follows window focus into the app. When the preview doesn't have focus, text and keys go straight to that tab's own page, and copy, cut, and paste are dropped so the clipboard is never touched. That covers the keystrokes landing in the composer (and the regression in #17478). Ifpreview_clickstill pulls focus out of the composer on a build with this fix, please open a new issue for just that.juliusmarminge closed this
Sign in to join this conversation.
Are you by chance using the t3 serve command to have a remote instance?
I was connected from windows and my macbook to my linux dev box at the same time and noticed it was having a hard time with the preview and realized the preview was getting launched on my macbook even though i was prompting/interacting from my windows machine.
Additionally some of the commands like snapshot, click, and other tools fail with a "tab reports hidden" unless you actively have that browser tab open.