fix(desktop): keep preview automation from stealing chat focus #19548
main fromrefs/pull/19548/head·opened View on GitHubProblem#
Agent browser typing can land in the chat composer, and preview clicks can interrupt the user's typing or dictation, including when the preview is in a background thread. Desktop-local server tabs still used embedded Electron webviews: their CDP keyboard routing and native mouse focus share the app's focus tree.
Fixes #17478.
Change#
Keep desktop-local server tabs in hidden, non-focusable offscreen windows and display them through the existing streamed browser surface. Each page uses the same Electron session partition as before, preserving default/custom profile logins and incognito isolation. Remote tabs keep their existing streaming path; human-only desktop tabs remain native.
The preview manager owns page creation, renderer initialization, debugger attachment, and cleanup. The server now applies viewport and zoom to desktop-supplied pages just as it does to headless pages. The desktop retains capture, annotation, DevTools, and picture-in-picture controls, and excludes hidden page windows from app activation and broadcasts. The CDP relay acknowledges Page.bringToFront without activating a native window.
A keyboard-only workaround cannot protect dictation through clicks: Chromium requests embedder focus before dispatching the page's mouse handler. Isolating the native focus tree covers both input paths while retaining normal CDP input behavior.
Scope and approval#
This fixes the existing browser input regression triaged by a maintainer, restoring the isolation users expect while agents operate previews. The desktop lifecycle, server rendering, and web surface changes are required for that same boundary. All providers use the common browser path. No mobile-specific behavior or provider adapter changes are needed; mobile and remote clients continue to use the existing stream protocol.
Verification#
- 197 tests passed across the focused desktop preview/session/IPC/window, server browser, and web runtime/lifetime suites. Coverage includes session selection, lifecycle cleanup, renderer/initial-navigation races, preventing native activation, and streamed desktop viewport/zoom. The server suite passed again after adding resize-at-zoom coverage.
- Follow-up startup navigation coverage: all 110 preview manager tests passed, including four cases that navigate during renderer or debugger initialization, with and without an initial URL. A newer request proceeds without waiting for the initial page load. The native Electron focus fixture and desktop typecheck also passed again.
- Scoped desktop, server, and web typechecks passed. Scoped lint and formatting passed, with existing lint warnings. Desktop build passed.
- A native Electron 44.4.5 regression fixture using the real preview manager, browser session, desktop host, and CDP relay reproduced the old composer leak. With the fix, typing, select-all/replacement, mouse clicks, scrolling, and
Page.bringToFrontreached the isolated page; chat selection was retained with zero input or window blur events. Native host typing continued without refocusing. The page retained a synthetic login cookie in the same session. Native results. - Integrated web pass through T3's Browser panel: opened a local page, typed and submitted a synthetic pairing code through the stream, preserved the chat draft, and exercised zoom/reset. Web capture.
- macOS system Dictation itself was not manually exercised. Local desktop tabs now incur the existing stream's rendering path; native sign-in popups remain separate windows and open inactive.
Matched native regression fixture captures (not product screenshots):
| Before: agent text leaks into chat | After: input stays in the isolated page |
|---|---|
![]() | ![]() |
Short native regression recording.
Model: GPT-6.1 Sol | Harness: Codex in T3 Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -1724,0 +1781,21 @@1781+ nodeIntegration: false,1782+ nodeIntegrationInSubFrames: false,1783+ nodeIntegrationInWorker: false,1784+ disableHtmlFullscreenWindowResize: true,1785+ ...(passkeys.bridgeEnabled ? { additionalArguments: [PASSKEY_BRIDGE_ARGUMENT] } : {}),1786+ },1787+ });1788+ isolatedWindows.set(tabId, window);1789+ window.once("closed", () => {1790+ if (isolatedWindows.get(tabId) === window) runFork(closeTab(tabId));1791+ });1792+ return window;1793+ });1794+ // A new BrowserWindow has no renderer until its first navigation. CDP1795+ // initialization cannot complete before that renderer exists.1796+ yield* attemptPromise({ operation: "createTab.initializeRenderer", tabId }, () =>1797+ window.webContents.loadURL("about:blank"),1798+ );1799+ yield* registerContents(tabId, window.webContents, tabLifecycleGenerations.get(tabId));1800+ if (!frameCaptureWindowOpen) return yield* new PreviewMainWindowClosedError({ tabId });1801+ if (initialUrl !== undefined) {
🟠 High
preview/Manager.ts:1801A navigation issued while this isolated window is initializing is overwritten by
initialUrl(or never loaded wheninitialUrlis undefined), so the tab does not navigate to the latest committed URL.navigatecan commit whilewebContentsIdis null, and isolatedregisterContentsskips pending-URL loading; read the latestLoadingURL after registration and load that instead of the creation-time snapshot.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1801: A navigation issued while this isolated window is initializing is overwritten by `initialUrl` (or never loaded when `initialUrl` is undefined), so the tab does not navigate to the latest committed URL. `navigate` can commit while `webContentsId` is null, and isolated `registerContents` skips pending-URL loading; read the latest `Loading` URL after registration and load that instead of the creation-time snapshot. Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR changes the default execution and rendering path for local server previews by introducing hidden offscreen Electron windows and cross-layer lifecycle/session plumbing. The scope includes substantial runtime behavior changes and an unresolved high-severity startup-navigation concern, so human review is required.
Not approved because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ec4e5c96-4c9b-4051-8815-555a23a9bbbc
📥 Commits
-
Reviewing files that changed from the base of the PR and between bf8ffe81a63c82d3de5fbaa9991fd5f30034a452 and deb5c64e96d597c7c732669cdee7f1addb57614c.
📒 Files selected for processing: 19
-
apps/desktop/src/electron/ElectronWindow.test.tsapps/desktop/src/electron/ElectronWindow.tsapps/desktop/src/ipc/methods/preview.test.tsapps/desktop/src/ipc/methods/preview.tsapps/desktop/src/preload.tsapps/desktop/src/preview/BrowserSession.tsapps/desktop/src/preview/CdpRelay.test.tsapps/desktop/src/preview/CdpRelay.tsapps/desktop/src/preview/DesktopBrowserHost.tsapps/desktop/src/preview/Manager.test.tsapps/desktop/src/preview/Manager.tsapps/server/src/preview/ServerBrowser.test.tsapps/server/src/preview/ServerBrowser.tsapps/web/src/browser/ElectronBrowserHost.tsxapps/web/src/browser/desktopTabLifetime.tsapps/web/src/browser/previewRuntime.tsapps/web/src/components/preview/PreviewView.tsxapps/web/src/components/preview/ThreadPreviewMiniPlayer.tsxpackages/contracts/src/ipc.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.
-
📝 Walkthrough
-
Server-runtime preview tabs now use isolated desktop browser windows with profile-scoped sessions. Server-side viewport and zoom updates apply to those pages. Web preview controls and Electron window handling account for the isolated tabs.
Changes: Isolated Server Preview
Layer / File(s) Summary Profile scope and tab creation inputs
packages/contracts/src/ipc.ts,apps/desktop/src/preview/BrowserSession.ts,apps/desktop/src/ipc/methods/preview.ts,apps/desktop/src/preload.tsTab creation accepts optional environment, profile, and URL values. BrowserSession.resolvePartitionScoperesolves the session scope, and the preview IPC path passes the values to tab creation.Isolated desktop tab lifecycle
apps/desktop/src/preview/Manager.ts,apps/desktop/src/preview/Manager.test.ts,apps/desktop/src/electron/ElectronWindow.ts,apps/desktop/src/electron/ElectronWindow.test.ts,apps/desktop/src/preview/CdpRelay.ts,apps/desktop/src/preview/CdpRelay.test.ts,apps/desktop/src/preview/DesktopBrowserHost.tsPreviewManagercreates and registers isolated offscreen windows, coordinates startup navigation, and closes windows with their tabs or the main window. Electron window operations exclude offscreen windows except when destroying windows.Page.bringToFrontreceives an empty response without forwarding the command.Server-side viewport and zoom
apps/server/src/preview/ServerBrowser.ts,apps/server/src/preview/ServerBrowser.test.tsServer viewport sizing and zoom updates now apply to desktop isolated pages, including viewer resize requests. Pointer reporting returns when no viewer or recording encoder exists. Web preview hosting and controls
apps/web/src/browser/ElectronBrowserHost.tsx,apps/web/src/browser/desktopTabLifetime.ts,apps/web/src/browser/previewRuntime.ts,apps/web/src/components/preview/PreviewView.tsx,apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsxServer-runtime tabs acquire an isolated desktop-tab lease after authorization and settings hydration. Preview controls classify server tabs by runtime and enable desktop capture and picking for bridged desktop-hosted tabs. Priority: ⬆️ High
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant ElectronBrowserHost participant acquireDesktopTab participant preload participant PreviewIPC participant PreviewManager participant BrowserSession participant BrowserWindow ElectronBrowserHost->>acquireDesktopTab: acquire tab with environment, profile, and URL acquireDesktopTab->>preload: send tab creation defaults preload->>PreviewIPC: invoke preview.createTab PreviewIPC->>PreviewManager: create tab with profile and URL PreviewManager->>BrowserSession: resolve profile-scoped session PreviewManager->>BrowserWindow: create isolated offscreen windowSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
deb5c-
No confirmed issue blocks merging after normal checks.
Security architecture risk: 🔵 Low · up to
deb5c-
The change improves separation between automated browsing and user input while preserving browser-profile isolation. Normal creation is permission-gated and limited to the local environment, but exceptional identity and permission-transition cases are not fully established.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The reviewed production path operates in the desktop primary environment and uses the selected browser profile, including its existing site logins. These are application/session boundaries rather than restrictions on the privileges of the desktop application itself. No newly attackable remote-environment path was established, but arbitrary native request provenance remains incompletely covered.
Security Findings and Attack Paths
- inferred — The new component subscribes to desktop-state mirroring even when preview-operation permission is denied. This differs from the base component mounting gate, but the same desktop state was already broadcast and observable through the privileged renderer bridge. Creation is still denied and permission loss releases the lease. A new unauthorized recipient or materially expanded disclosure path was not established.
Trust Boundaries and Controls
- observed — The production creation effect checks the selected environment's preview-operation grant. Missing or failed session results and unauthenticated sessions deny the grant; cached grants during refresh are intentional. Native request handling performs schema validation but does not independently authorize the supplied environment/profile against the sender in the inspected path.
Resilience and Maintainability Implications
- inferred — Repeated creation reuses existing state solely by tab ID without comparing profile/session identity. The normal caller mitigates accidental cross-environment reuse through a framed environment/thread/server-epoch/tab key and latched profile fallback. Reachability of conflicting profile requests remains unresolved, so this is not retained as an introduced security concern.
Hardening Proposals
- proposed — Make the native creation trust policy explicit: if environment/profile access must be constrained independently of the trusted desktop renderer, bind creation requests to authorized caller and session ownership rather than relying only on the client permission gate.
- proposed — Persist the environment/profile identity with each isolated tab and explicitly reject conflicting repeated creation requests. This would strengthen the identity invariant beyond the current production caller's key and profile-latching conventions.
-
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Title check The title clearly identifies the primary change: preventing preview automation from taking chat focus. Description check The description includes all required sections. It explains the problem, implementation, scope and approval, focused verification, test results, limitations, screenshots, recording, and agent details. Linked Issues check Issue #17478requires preview input to reach the targeted local page for inline and background tabs without leaking into T3 UI. Server tabs now use hidden, non-focusable offscreen BrowserWindow instan…Out of Scope Changes check The changes stay within issue #17478. Electron window filtering prevents hidden preview windows from activation and broadcasts. Manager lifecycle, browser-session selection, server viewport and zoom h…
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
PixPMusic(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed