Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
45.4.1
What operating system(s) are you using?
macOS
Operating System Version
macOS Tahoe 26.6.2
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Does the issue also appear in Chromium / Google Chrome?
No
Expected Behavior
I would expect BrowserWindow.fromWebContents() to return either a BrowserWindow if the given webContents belongs to one or null if not, since that's the behavior described by the types and docs.
Actual Behavior
In practice, if you call BrowserWindow.fromWebContents() with a webContents that belongs to a WebContentsView that's attached to a BaseWindow, it will return the BaseWindow instance.
This works even if there's an indirect ownership chain like BaseWindow -> View -> WebContentsView.
Testcase Gist URL
Additional Information
In #44899, there was a feature request for a BaseWindow.fromWebContents() API that was rejected on the basis that it would be too inefficient to implement. Weirdly, it seems like this BrowserWindow.fromWebContents() behavior already existed at the time, since my repro gist works on 33.2.0.
Unless there's some gotcha that's not obvious to me, I think the move here might be:
- Move the existing
fromWebContents()implementation toBaseWindow, since in practice it's already polymorphic. - Log a deprecation warning when
BrowserWindow.fromWebContents()returns aBaseWindow. - In a future version, update
BrowserWindow.fromWebContents()to returnnullif it's given awebContentsthat belongs to aBaseWindow, consistent with howBrowserWindow.fromId()works today.
BTW I was surprised to discover in Fiddle that after removing a child view from its window, BrowserWindow.fromWebContents() still returns the window. This is true for both BrowserWindow and BaseWindow.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields👍 Does Not Block Stable
Activity