Skip to content

[Bug]: addBrowserView unnecessarily removes and re-adds the same browserView #48057

@mai-121

Description

@mai-121

Preflight Checklist

Electron Version

36.4.0

What operating system(s) are you using?

Windows

Operating System Version

windows 11

What arch are you using?

x64

Last Known Working Electron version

29.4.6

Does the issue also appear in Chromium / Google Chrome?

No

Expected Behavior

When the same browserView is added to a browserWindow multiple times, the visibility of the pages in the browserView does not change.

Actual Behavior

When the same browserView is added to a browserWindow multiple times, the visibility of the pages in the browserView quickly changes from visible to hidden and then to visible.

Testcase Gist URL

https://gist.github.com/mai-121/43a7ad52f16e6c86b0fc1369c84fa97a

Additional Information

After the BrowserView module was refactored in Electron 30, the behavior of the addBrowserView API changed. When the same browserView is added multiple times to a browserWindow, the browserView will first be removed and then re-added.
Specifically, this causes a jump in the page's visibility inside the browserView, and the visibilitychange event is triggered unexpectedly.

The impl of 'addBrowserView' in different versions:
electron 29: https://github.com/electron/electron/blob/v29.4.6/shell/browser/api/electron_api_base_window.cc#L762
electron 30: https://github.com/electron/electron/blob/v30.0.0/lib/browser/api/browser-window.ts#L178

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions