fix(desktop): route mouse thumb buttons to the in-app browser#4459
fix(desktop): route mouse thumb buttons to the in-app browser#4459akosbalogh wants to merge 1 commit into
Conversation
When the pointer hovers the preview <webview> without focusing it, Chromium routes back/forward thumb-button navigation to the focused host renderer, so the app router navigated instead of the browser. Intercept the thumb buttons (button 3 = back, 4 = forward) in the guest preload, suppress Chromium's default, and forward an explicit navigate request to PreviewManager so the buttons always drive the hovered browser's history and never the host app. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved This is a targeted bug fix for mouse thumb button navigation in the in-app browser. The changes follow existing patterns in the codebase, include comprehensive tests, and are self-contained within the preview system without touching sensitive areas. You can customize Macroscope's approvability policy. Learn more. |
What changed
Mouse thumb (side) buttons — back =
button 3, forward =button 4— now navigate the in-app browser's history when the pointer is over the preview<webview>, instead of navigating the host T3 Code app (threads/agents view).Why
The preview is an Electron
<webview>whoseWebContentsis driven byPreviewManager. When the pointer merely hovers the guest page (the guest isn't focused), Chromium routes thumb-button history navigation to the focusedWebContents— the host app renderer — so pressing back/forward over the browser sent the app router back instead of the browser. This was intermittent ("sometimes") because it depended on which surface held focus.How
PickPreload.ts(runs inside every preview guest): capture-phase listeners for the thumb buttonspreventDefault()+stopImmediatePropagation()onmousedown/mouseup/auxclickto suppress Chromium's default navigation, and forward an explicit{ direction }over a newMOUSE_NAVIGATE_CHANNELIPC. Guarded byevent.isTrustedso automation-injected events are unaffected.Manager.ts:attachListenersregisters amouseNavigatehandler that drives that tab's history via the existingwc.navigationHistory.goBack()/goForward()(guarded bycanGoBack()/canGoForward()), mirroring the existing UI back/forward path. Registered/torn down alongside the existingHUMAN_INPUT_CHANNELlistener.GuestProtocol.ts: newMOUSE_NAVIGATE_CHANNELconstant.Suppression in the guest is unconditional, so the host app never navigates while the cursor is over the browser — even when the browser has no back history.
Testing
Manager.test.tsasserting the IPC handler drivesgoBack/goForward, ignores unknown payloads, and does nothing when history is exhausted.apps/desktoptypecheck, lint, format, and fullManager.test.tssuite (20 tests) pass locally.🤖 Generated with Claude Code
Note
Low Risk
Scoped to desktop preview input handling with guards on payload and history; no auth or data changes.
Overview
Mouse back/forward thumb buttons over the preview webview now move that tab’s browser history instead of the host app router when the guest isn’t focused.
In
PickPreload.ts, capture-phase listeners on thumb buttons (button3/4) callpreventDefault/stopImmediatePropagationand send{ direction: "back" | "forward" }on newpreview:mouse-navigateIPC (trusted events only).PreviewManagerregisters amouseNavigatehandler alongside human-input listeners that callsnavigationHistory.goBack()/goForward()when history allows.Manager.test.tscovers valid directions, bad payloads, and exhausted back history.Reviewed by Cursor Bugbot for commit d04de2b. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Route mouse thumb buttons to the in-app browser for back/forward navigation
mousedown,auxclick, andmouseupevents for mouse buttons 3 (back) and 4 (forward), suppresses Chromium's default focus-dependent navigation, and emits apreview:mouse-navigateIPC message with a direction payload.wc.navigationHistory.goBack()orgoForward()only whencanGoBack()/canGoForward()returns true; invalid payloads are ignored.Macroscope summarized d04de2b.