fix(web): preserve composer focus during browser automation - #4118
fix(web): preserve composer focus during browser automation#4118mwolfeio wants to merge 1 commit into
Conversation
|
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 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 Straightforward refactor extracting existing focus-preservation logic into a reusable utility, with unit tests. Limited scope, self-contained UI behavior fix. You can customize Macroscope's approvability policy. Learn more. |
|
Note 🤖 GPT-6 Astra (preview) responding on behalf of Theo This note is part of an automated cleanup pass. Carryover from #5898 at 15b2a4bd29: Electron's |
|
Fix first at 6ae43825. P2: runPreservingDocumentFocus unconditionally restores its captured element after the asynchronous operation. If the person focuses another control while the request is pending, this moves focus away from their newer selection when the request completes or rejects. Extracting the same helper into the longer element-picker flow also keeps that behavior there. I executed the exact proposed helper in an isolated Chromium DOM with two synthetic inputs and actual browser clicks. No T3 or Electron behavior was mocked into the helper:
Preserve the person's newer focus choice rather than always reclaiming the original element. Add success and failure regressions for an intentional focus change, alongside the detached-element control. The existing tests only verify the captured element's focus callback and do not cover that transition. This establishes a flaw in the proposed helper, not reproduction of native guest focus loss or keyboard delivery. The same-thread/cross-thread Electron checks from the earlier maintainer comment remain required. #5792 also reports other automation actions, so a press-only fix must retain that limitation. Current main 4f782bed still restores only the prior WebContents in the desktop press cleanup; source inspection alone does not establish native runtime behavior. Audited by GPT 6 Astra via Codex in T3 Code. |
|
Native follow-up for #5792: the focus-only proposal still needs a correct-key-target check. I ran the unchanged Actual semantic clicks established the initial focus. After calling the production
The final run at 06:20:31 UTC used the actual unwrapped Electron debugger methods; an earlier instrumented run had the same result. Direct semantic-click/Enter controls also delivered correctly to each intended field. The loaded source hashes were captured. In the failing controls, the outer document remained focused while This is a minimal native preview-manager reproduction, not the full T3 composer, original Arch/AppImage/window-manager setup, or proof that a real draft was submitted. The original reported focus-loss symptom was not reproduced here. Nevertheless, preserving DOM focus alone is insufficient evidence for shipping: native tests must establish that keys reach the target preview and never reach the foreground composer, as well as preserving the person's newer focus choice from the earlier review. The original issue remains open; no fix or closure claim. Audited by GPT 6 Astra via Codex in T3 Code. |
What Changed
pressoperations.finallyblock, including when automation fails.Why
Native browser key dispatch temporarily focuses Electron’s guest
WebContents. The main process restores the outer renderer afterward, but not its active DOM element, so the composer stays blurred and interrupts users typing queued follow-ups while the agent works. This restores the prompt editor without changing the guest-focus behavior required by browser automation.UI Changes
Behavior-only fix; there are no visual changes. Before this change, an agent browser key press leaves the composer unfocused. Afterward, the same editor regains focus without scrolling.
Validation
vp check(0 errors; 10 pre-existing warnings)vp run typecheckChecklist
Note
Low Risk
Small, localized renderer UX fix with best-effort focus restoration and no changes to auth, data, or automation semantics beyond wrapping
press.Overview
Adds shared
documentFocushelpers that snapshot the renderer’s active element and restore it withfocus({ preventScroll: true })in afinallyblock, skipping detached or invalid targets.Agent browser
pressinPreviewAutomationHostsnow runs insiderunPreservingDocumentFocusso guestWebContentskey dispatch no longer leaves the chat composer blurred while the user types follow-ups.The element-picker flow in
PreviewViewuses the same capture/restore helpers instead of inline focus logic. Unit tests cover success, failure, and detached-element cases.Reviewed by Cursor Bugbot for commit 6ae4382. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Preserve composer focus during browser automation press actions
documentFocusutility module (documentFocus.ts) withcaptureDocumentFocus,restoreDocumentFocus, andrunPreservingDocumentFocushelpers.pressautomation action in PreviewAutomationHosts.tsx withrunPreservingDocumentFocusso the previously focused element is restored after the operation completes or fails.Macroscope summarized 6ae4382.