Skip to content

Conversation

@nornagon
Copy link
Contributor

@nornagon nornagon commented Sep 13, 2022

Description of Change

Replaces the experimental BrowserView API with a new WebContentsView API.

  • Documents the existing BaseWindow, which BrowserWindow extends.
    • Currently we duplicate all the documentation for the inherited methods into
      the BrowserWindow docs. Ideally we could deduplicate this, but for
      usability and consistency (avoiding "where did all the BrowserWindow
      methods go???" type questions), we should probably change the docs site to
      account for that change, e.g. to have the duplication of docs for inherited
      methods happen at render time.
  • Adds one new BaseWindow read-write property, contentView.
  • Documents the existing View and WebContentsView.
    • WebContentsView is the replacement for the old BrowserView class. We
      also expose and document the View class, because that is the type
      of BaseWindow.contentView, to which WebContentsViews are added.
  • Adds several new View properties and methods.
    • removeChildView(), children, setBounds(), getBounds(), setBackgroundColor(), setVisible().
  • Deprecates the BrowserView API and updates all references to it to point to WebContentsView instead.
    • We also need a new guide on how to use WebContentsView.
  • Adds a JavaScript shim with the same API surface as the old BrowserView API, which
    under the hood delegates to the new WebContentsView API.
  • Removes BrowserView-specific draggable region handling. This will be
    replaced with refactor: use views NonClientHitTest for draggable regions on mac #35603, but may need some more holes poked to enable draggable
    regions to work correctly on all platforms in WebContentsViews.
  • Changes setAutoResize to behave consistently on all platforms. (The behavior on macOS has been changed to match the behavior on Windows.)

Still TODO:

  • BrowserView had options for auto-sizing. This isn't yet possible with the
    currently exposed APIs of WebContentsView / View, but it should be
    doable!
    This is done, I ported the autoresizing logic from C++ to JS.
  • There is some code about compositor recycling for BrowserViews that I glazed
    over and removed in this PR. I'm not really sure how to test "is this still
    working properly", but it deserves investigation.
    I tested this using the example from fix: Disable new fade animation for BrowserViews #14911 and it seems like things are okay (no flickering)!
  • Test that background colors are working properly. as far as I can tell, they are.
  • Test that onbeforeunload works properly in WebContentsView.
  • Draggable regions are broken in WebContentsView. I think this should be fixed with chore: Move draggable regions implementation from NativeBrowserView into InspectableWebContentsView #35007, so I'm going to say that doesn't block this PR from landing.

Checklist

Release Notes

Notes: Added WebContentsView and BaseWindow, replacing the now-deprecated BrowserView APIs.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Sep 20, 2022
Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very much in favor of the direction these changes are taking the view-related classes. Cool to see classes move directly into JS. 👍👍

Do you happen to know whether the View class is at all compatible with the design of BaseView in #32890? Would be great if these two proposals could build off of each other.

@nornagon
Copy link
Contributor Author

My main comment on #32890 is that BaseView should not exist, it should just use View. I believe this was addressed in the RFC, and that the PR is out of date.

@CezaryKulakowski
Copy link
Contributor

I've reported two issues caused by this change:
#41141
#41142

@CezaryKulakowski
Copy link
Contributor

I' ve reported issue for WebContentsView visibility on macOS: #41276

@mx369
Copy link

mx369 commented Apr 17, 2024

Why didn't I see any related documentation?

@panther7
Copy link

In changelog:

BrowserView is now a shim over WebContentsView and the old implementation has been removed.

But, BrowserView is still here (v30.0.0) ...

@dsanders11
Copy link
Member

@panther7, BrowserView was not removed, the implementation was changed.

@dsanders11 dsanders11 mentioned this pull request Aug 5, 2024
18 tasks
trop bot added a commit that referenced this pull request Aug 6, 2024
Reference: #35658

Co-authored-by: Piotr Płaczek <[email protected]>
VerteDinde pushed a commit that referenced this pull request Aug 6, 2024
* docs: deprecate `BrowserView`

Reference: #35658

Co-authored-by: Piotr Płaczek <[email protected]>

* docs: deprecate `webContents.goToIndex(index)`

Reference: https://github.com/electron/electron/pull/41752/files#diff-18ed6a5b5a9084c976509502962b7f05989a8bd13a2ba3dc02868056938c03b6R1165-R1167

Co-authored-by: Piotr Płaczek <[email protected]>

* docs: deprecate some protocol methods

Reference: https://github.com/electron/electron/pull/36674/files#diff-74861ecada868821b139e79f244ea32b840a93f60de572d585117a0ff8d165c8R380

Co-authored-by: Piotr Płaczek <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Piotr Płaczek <[email protected]>
ckerr added a commit that referenced this pull request Oct 6, 2025
codebytere pushed a commit that referenced this pull request Oct 8, 2025
chore: remove unused reference to api::BrowserView

Unused since #35658 / 15c6014
TheCommieAxolotl pushed a commit to TheCommieAxolotl/electron that referenced this pull request Nov 2, 2025
chore: remove unused reference to api::BrowserView

Unused since electron#35658 / 15c6014
nilayarya pushed a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
chore: remove unused reference to api::BrowserView

Unused since electron#35658 / 15c6014
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
chore: remove unused reference to api::BrowserView

Unused since electron#35658 / 15c6014
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
chore: remove unused reference to api::BrowserView

Unused since electron#35658 / 15c6014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/29-x-y PR was merged to the "29-x-y" branch. no-backport semver/major incompatible API changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.