Skip to content

BrowserWindow.fromWebContents has undocumented ability to return BaseWindow #56007

Todo

Description

@rf-

Preflight Checklist

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

https://gist.github.com/00bea3308909c20a5fedd46a8ad36068

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 to BaseWindow, since in practice it's already polymorphic.
  • Log a deprecation warning when BrowserWindow.fromWebContents() returns a BaseWindow.
  • In a future version, update BrowserWindow.fromWebContents() to return null if it's given a webContents that belongs to a BaseWindow, consistent with how BrowserWindow.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.

Activity

  1. added theissue type on Nov 22, 2026
  2. added
    has-repro-gist
    on Nov 22, 2026
  3. moved this to 👀 Unsorted Items in 45-x-yon Nov 22, 2026
  4. moved this from 👀 Unsorted Items to 👍 Does Not Block Stable in 45-x-yon Nov 25, 2026
  5. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

45-x-ybug 🪲has-repro-gistplatform/macOS

Type

Projects

  • Status
    👍 Does Not Block Stable

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions