Repository navigation
fix: keep focus in a child WebContentsView when its window regains focus - #54378
Merged
Merged
Conversation
|
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
force-pushed
the
fix-keep-child-view-focus-on-activation
branch
from
September 25, 2026 13:36
e165a23 to
ea66544
Compare
MarshallOfSound
approved these changes
Sep 26, 2026
|
Release Notes Persisted
|
Contributor
|
I was unable to backport this PR to "45-x-y" cleanly; |
Contributor
|
I was unable to backport this PR to "43-x-y" cleanly; |
Contributor
|
I was unable to backport this PR to "44-x-y" cleanly; |
Contributor
|
@codebytere has manually backported this PR to "45-x-y", please check out #54454 |
Contributor
|
@codebytere has manually backported this PR to "44-x-y", please check out #54455 |
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)
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)
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Fixes #28163.
Refs #25429.
After this change a child
WebContentsViewthat had focus keeps it when itsBrowserWindowis 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 withwin.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
WebContentsViewlosing focus when its window is reactivated.