Skip to content

fix: keep focus in a child WebContentsView when its window regains focus - #54378

Merged
codebytere merged 1 commit into
mainfrom
fix-keep-child-view-focus-on-activation
Sep 26, 2026
Merged

codebytere merged 1 commit into
mainfrom
fix-keep-child-view-focus-on-activation

Conversation

@codebytere

@codebytere codebytere commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Description of Change

Fixes #28163.
Refs #25429.

After this change a child WebContentsView that had focus keeps it when its BrowserWindow is reactivated (Alt+Tab back, taskbar click) on Windows and Linux, instead of focus jumping to the window's own page.

On reactivation the views focus manager restores focus to the view the user last clicked into, and BrowserWindow::OnWindowFocus() then focused the window's primary webContents unconditionally, pulling focus out of the child. Apps compensated with win.on('focus', () => view.webContents.focus()), the pattern behind the focus loop in #25429.

OnWindowFocus() now leaves focus alone when the focus manager already has a focused view outside the primary web contents view, and behaves as before otherwise; macOS is untouched. A spec focuses a child view, deactivates and reactivates the window, and expects the child to still be focused: it fails 3/3 on main and passes 3/3 here under Xvfb, and the existing focus specs pass.

Checklist

Release Notes

Notes: Fixed a child WebContentsView losing focus when its window is reactivated.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 25, 2026
@release-clerk

release-clerk Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Release note looks good now.

When a BrowserWindow was reactivated, the views focus manager restored
focus to the view the user last clicked into, and BrowserWindow's focus
handler then moved it to the window's own webContents unconditionally. A
child WebContentsView therefore lost focus on every Alt+Tab round trip on
Windows and Linux. Leave focus alone when another view in the window
already holds it.
@codebytere
codebytere force-pushed the fix-keep-child-view-focus-on-activation branch from e165a23 to ea66544 Compare September 25, 2026 13:36
@codebytere
codebytere merged commit 2dc5757 into main Sep 26, 2026
122 of 124 checks passed
@release-clerk

release-clerk Bot commented Sep 26, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a child WebContentsView losing focus when its window is reactivated.

@codebytere
codebytere deleted the fix-keep-child-view-focus-on-activation branch September 26, 2026 12:43
@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "45-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot removed the target/45-x-y PR should also be added to the "45-x-y" branch. label Sep 26, 2026
@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "43-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/45-x-y and removed target/43-x-y PR should also be added to the "43-x-y" branch. labels Sep 26, 2026
@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "44-x-y" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "45-x-y", please check out #54454

@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "44-x-y", please check out #54455

@trop

trop Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "43-x-y", please check out #54456

MarshallOfSound pushed a commit that referenced this pull request Sep 26, 2026
…cus (#54456)

fix: keep focus in a child WebContentsView when its window regains focus (#54378)

When a BrowserWindow was reactivated, the views focus manager restored
focus to the view the user last clicked into, and BrowserWindow's focus
handler then moved it to the window's own webContents unconditionally. A
child WebContentsView therefore lost focus on every Alt+Tab round trip on
Windows and Linux. Leave focus alone when another view in the window
already holds it.

(cherry picked from commit 2dc5757)
(cherry picked from commit 4fddea7)
@trop trop Bot added merged/43-x-y PR was merged to the "43-x-y" branch. and removed in-flight/43-x-y labels Sep 26, 2026
MarshallOfSound pushed a commit that referenced this pull request Sep 26, 2026
…cus (#54455)

fix: keep focus in a child WebContentsView when its window regains focus (#54378)

When a BrowserWindow was reactivated, the views focus manager restored
focus to the view the user last clicked into, and BrowserWindow's focus
handler then moved it to the window's own webContents unconditionally. A
child WebContentsView therefore lost focus on every Alt+Tab round trip on
Windows and Linux. Leave focus alone when another view in the window
already holds it.

(cherry picked from commit 2dc5757)
(cherry picked from commit 4fddea7)
@trop trop Bot added merged/44-x-y PR was merged to the "44-x-y" branch. and removed in-flight/44-x-y labels Sep 26, 2026
MarshallOfSound pushed a commit that referenced this pull request Sep 27, 2026
…cus (#54454)

fix: keep focus in a child WebContentsView when its window regains focus (#54378)

When a BrowserWindow was reactivated, the views focus manager restored
focus to the view the user last clicked into, and BrowserWindow's focus
handler then moved it to the window's own webContents unconditionally. A
child WebContentsView therefore lost focus on every Alt+Tab round trip on
Windows and Linux. Leave focus alone when another view in the window
already holds it.

(cherry picked from commit 2dc5757)
@trop trop Bot added merged/45-x-y PR was merged to the "45-x-y" branch. and removed in-flight/45-x-y labels Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Bug]: BrowserView elements do not retain input focus between BrowserWindow blur/focus

2 participants