Skip to content

feat: replace BrowserView with WebContentsView - #35658

Merged
nornagon merged 103 commits into
mainfrom
replace-browserview
Dec 13, 2023
Merged

nornagon merged 103 commits into
mainfrom
replace-browserview

Conversation

@nornagon

@nornagon nornagon commented Sep 13, 2022 •

Copy link
Copy Markdown
Contributor

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

@samuelmaddock samuelmaddock left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@dsanders11

Copy link
Copy Markdown
Member

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

@dsanders11 dsanders11 mentioned this pull request Aug 5, 2024
17 of 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
@ckerr ckerr mentioned this pull request Apr 2, 2026
3 of 4 tasks
pedro-b-rosa added a commit to pedro-b-rosa/electron that referenced this pull request May 21, 2026
- Remove redundant v8::TryCatch in JSLayoutManager. gin's V8FunctionInvoker
  already absorbs JS exceptions thrown from calculateProposedLayout: it
  returns a default-constructed ProposedLayout and leaves the exception
  pending on the isolate, which Node surfaces via uncaughtException on the
  next reentry. The previous TryCatch+ReThrow added no observable behavior
  vs. simply not catching.
- Reject unknown layout type values explicitly (e.g. setLayout({type:'fluss'}))
  instead of silently falling through to FlexLayout. An *absent* type still
  configures FlexLayout for back-compat with the legacy PR electron#35658 shape.
- Make getMainAxisAlignment and getCrossAxisAlignment symmetric across
  BoxLayout and FlexLayout via an AlignmentToString helper.
- Document the SetLayoutFlex cache invariant on last_min/max_flex_rule_.
- Add 6 tests: unknown-type rejection, legacy no-type shape, setLayout(null)
  on a JS layout manager, setBoxFlex(child, 0), and flex variants of both
  alignment getters.

Co-authored-by: João Miguel Ribeiro da Silva <[email protected]>
pedro-b-rosa added a commit to pedro-b-rosa/electron that referenced this pull request May 23, 2026
- Remove redundant v8::TryCatch in JSLayoutManager. gin's V8FunctionInvoker
  already absorbs JS exceptions thrown from calculateProposedLayout: it
  returns a default-constructed ProposedLayout and leaves the exception
  pending on the isolate, which Node surfaces via uncaughtException on the
  next reentry. The previous TryCatch+ReThrow added no observable behavior
  vs. simply not catching.
- Reject unknown layout type values explicitly (e.g. setLayout({type:'fluss'}))
  instead of silently falling through to FlexLayout. An *absent* type still
  configures FlexLayout for back-compat with the legacy PR electron#35658 shape.
- Make getMainAxisAlignment and getCrossAxisAlignment symmetric across
  BoxLayout and FlexLayout via an AlignmentToString helper.
- Document the SetLayoutFlex cache invariant on last_min/max_flex_rule_.
- Add 6 tests: unknown-type rejection, legacy no-type shape, setLayout(null)
  on a JS layout manager, setBoxFlex(child, 0), and flex variants of both
  alignment getters.

Co-authored-by: João Miguel Ribeiro da Silva <[email protected]>
pedro-b-rosa added a commit to pedro-b-rosa/electron that referenced this pull request May 24, 2026
- Remove redundant v8::TryCatch in JSLayoutManager. gin's
  V8FunctionInvoker already absorbs JS exceptions thrown from
  calculateProposedLayout: it returns a default-constructed
  ProposedLayout and leaves the exception pending on the
  isolate, which Node surfaces via uncaughtException on the
  next reentry. The previous TryCatch+ReThrow added no
  observable behavior vs. simply not catching.
- Reject unknown layout type values explicitly (e.g.
  setLayout({type:'fluss'})) instead of silently falling
  through to FlexLayout. An *absent* type still configures
  FlexLayout for back-compat with the legacy PR electron#35658 shape.
- Make getMainAxisAlignment and getCrossAxisAlignment
  symmetric across BoxLayout and FlexLayout via an
  AlignmentToString helper.
- Document the SetLayoutFlex cache invariant on
  last_min/max_flex_rule_.
- Add 6 tests: unknown-type rejection, legacy no-type shape,
  setLayout(null) on a JS layout manager, setBoxFlex(child,
  0), and flex variants of both alignment getters.

Co-authored-by: João Miguel Ribeiro da Silva <[email protected]>
pedro-b-rosa added a commit to pedro-b-rosa/electron that referenced this pull request May 24, 2026
- Remove redundant v8::TryCatch in JSLayoutManager. gin's
  V8FunctionInvoker already absorbs JS exceptions thrown from
  calculateProposedLayout: it returns a default-constructed
  ProposedLayout and leaves the exception pending on the
  isolate, which Node surfaces via uncaughtException on the
  next reentry. The previous TryCatch+ReThrow added no
  observable behavior vs. simply not catching.
- Reject unknown layout type values explicitly (e.g.
  setLayout({type:'fluss'})) instead of silently falling
  through to FlexLayout. An *absent* type still configures
  FlexLayout for back-compat with the legacy PR electron#35658 shape.
- Make getMainAxisAlignment and getCrossAxisAlignment
  symmetric across BoxLayout and FlexLayout via an
  AlignmentToString helper.
- Document the SetLayoutFlex cache invariant on
  last_min/max_flex_rule_.
- Add 6 tests: unknown-type rejection, legacy no-type shape,
  setLayout(null) on a JS layout manager, setBoxFlex(child,
  0), and flex variants of both alignment getters.

Co-authored-by: João Silva <[email protected]>
pedro-b-rosa added a commit to pedro-b-rosa/electron that referenced this pull request May 26, 2026
- Remove redundant v8::TryCatch in JSLayoutManager. gin's
  V8FunctionInvoker already absorbs JS exceptions thrown from
  calculateProposedLayout: it returns a default-constructed
  ProposedLayout and leaves the exception pending on the
  isolate, which Node surfaces via uncaughtException on the
  next reentry. The previous TryCatch+ReThrow added no
  observable behavior vs. simply not catching.
- Reject unknown layout type values explicitly (e.g.
  setLayout({type:'fluss'})) instead of silently falling
  through to FlexLayout. An *absent* type still configures
  FlexLayout for back-compat with the legacy PR electron#35658 shape.
- Make getMainAxisAlignment and getCrossAxisAlignment
  symmetric across BoxLayout and FlexLayout via an
  AlignmentToString helper.
- Document the SetLayoutFlex cache invariant on
  last_min/max_flex_rule_.
- Add 6 tests: unknown-type rejection, legacy no-type shape,
  setLayout(null) on a JS layout manager, setBoxFlex(child,
  0), and flex variants of both alignment getters.

Co-authored-by: João Silva <[email protected]>
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.