Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): use unique identifier for window focus restoration #5898

Closedmohamedmastouri-hue(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5898/headopened View on GitHub

Fixes #5792c


Note

Medium Risk Touches focus handling during agent keyboard automation with injected page scripts; bugs could leave stale window properties or wrong focus, but scope is limited to the press cleanup path.

Overview Preview automation press now restores in-page focus after simulated key events, not only the previously focused WebContents.

Before dispatching keys to the preview guest, the flow stores document.activeElement on the prior renderer under a random per-press window['__t3_focus_…'] id. Cleanup refocuses that WebContents, calls .focus() on the saved element if present, then deletes the property. That addresses collisions from a shared restore slot (#5792) and keeps keyboard focus on inputs in the main UI after agent key automation.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 15b2a4bd2937b373b60f2b98f32519143f620105. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Restore active element focus after automation key press in desktop preview

During automationPress in Manager.ts, focus is temporarily moved to a target WebContents. The previously focused renderer's active element is now saved to a unique window[focusRestoreId] before the shift, then refocused and cleaned up after the automation completes. Save/restore steps use attemptPromise and are silently ignored on failure.

Macroscope summarized 15b2a4b.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 98f51353-b48d-4b80-bd3d-a350a9b9917a

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Approved 15b2a4b

      Straightforward bug fix that uses unique identifiers to prevent collisions in window focus restoration logic. Limited scope, clear intent, and no security or schema implications.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.

      Closing in favor of #4118. It restores the focused DOM element in the renderer with try/finally, detached-element checks, and no scrolling. That addresses the same gap without injecting temporary global references through Electron. Review continues there, including current preview routing and cross-thread focus checks. The native focus observation is recorded on the retained PR.

Sign in to join this conversation.