codebytere

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

Merged
Created: Sep 25, 2026, 8:16:41 AM
Merged: Sep 26, 2026, 7:43:26 AM
8 comments
Target: main

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.

Backports

43-x-y
In-flight
PR Number
#54456
Waiting to be merged
44-x-y
In-flight
PR Number
#54455
Waiting to be merged
45-x-y
In-flight
PR Number
#54454
Waiting to be merged

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron