feat: replace BrowserView with WebContentsView (#35658)
This commit is contained in:
parent
a94fb2cb5d
commit
15c6014324
76 changed files with 2987 additions and 1531 deletions
|
@ -79,8 +79,8 @@ will be able to execute native code on the user's machine.
|
|||
Under no circumstances should you load and execute remote code with
|
||||
Node.js integration enabled. Instead, use only local files (packaged together
|
||||
with your application) to execute Node.js code. To display remote content, use
|
||||
the [`<webview>`][webview-tag] tag or [`BrowserView`][browser-view], make sure
|
||||
to disable the `nodeIntegration` and enable `contextIsolation`.
|
||||
the [`<webview>`][webview-tag] tag or a [`WebContentsView`][web-contents-view]
|
||||
and make sure to disable the `nodeIntegration` and enable `contextIsolation`.
|
||||
:::
|
||||
|
||||
:::info Electron security warnings
|
||||
|
@ -166,7 +166,7 @@ This recommendation is the default behavior in Electron since 5.0.0.
|
|||
:::
|
||||
|
||||
It is paramount that you do not enable Node.js integration in any renderer
|
||||
([`BrowserWindow`][browser-window], [`BrowserView`][browser-view], or
|
||||
([`BrowserWindow`][browser-window], [`WebContentsView`][web-contents-view], or
|
||||
[`<webview>`][webview-tag]) that loads remote content. The goal is to limit the
|
||||
powers you grant to remote content, thus making it dramatically more difficult
|
||||
for an attacker to harm your users should they gain the ability to execute
|
||||
|
@ -306,8 +306,8 @@ This recommendation is Electron's default.
|
|||
|
||||
You may have already guessed that disabling the `webSecurity` property on a
|
||||
renderer process ([`BrowserWindow`][browser-window],
|
||||
[`BrowserView`][browser-view], or [`<webview>`][webview-tag]) disables crucial
|
||||
security features.
|
||||
[`WebContentsView`][web-contents-view], or [`<webview>`][webview-tag]) disables
|
||||
crucial security features.
|
||||
|
||||
Do not disable `webSecurity` in production applications.
|
||||
|
||||
|
@ -782,10 +782,10 @@ learn how to serve files / content from a custom protocol.
|
|||
|
||||
[breaking-changes]: ../breaking-changes.md
|
||||
[browser-window]: ../api/browser-window.md
|
||||
[browser-view]: ../api/browser-view.md
|
||||
[webview-tag]: ../api/webview-tag.md
|
||||
[web-contents-view]: ../api/web-contents-view.md
|
||||
[responsible-disclosure]: https://en.wikipedia.org/wiki/Responsible_disclosure
|
||||
[web-contents]: ../api/web-contents.md
|
||||
[window-open-handler]: ../api/web-contents.md#contentssetwindowopenhandlerhandler
|
||||
[will-navigate]: ../api/web-contents.md#event-will-navigate
|
||||
[open-external]: ../api/shell.md#shellopenexternalurl-options
|
||||
[responsible-disclosure]: https://en.wikipedia.org/wiki/Responsible_disclosure
|
||||
|
|
|
@ -42,16 +42,15 @@ Compared to an `<iframe>`, `<webview>` tends to be slightly slower but offers
|
|||
much greater control in loading and communicating with the third-party content
|
||||
and handling various events.
|
||||
|
||||
### BrowserViews
|
||||
### WebContentsView
|
||||
|
||||
[BrowserViews](../api/browser-view.md) are not a part of the DOM - instead,
|
||||
they are created in and controlled by your Main process. They are simply
|
||||
another layer of web content on top of your existing window. This means
|
||||
that they are completely separate from your own `BrowserWindow` content and
|
||||
their position is not controlled by the DOM or CSS. Instead, it is controlled
|
||||
by setting the bounds in the Main process.
|
||||
[`WebContentsView`](../api/web-contents-view.md)s are not a part of the
|
||||
DOM—instead, they are created, controlled, positioned, and sized by your
|
||||
Main process. Using `WebContentsView`, you can combine and layer many pages
|
||||
together in the same [`BaseWindow`](../api/base-window.md).
|
||||
|
||||
`BrowserViews` offer the greatest control over their contents, since they
|
||||
implement the `webContents` similarly to how the `BrowserWindow` does it.
|
||||
However, as `BrowserViews` are not a part of your DOM, but are rather overlaid
|
||||
on top of them, you will have to manage their position manually.
|
||||
`WebContentsView`s offer the greatest control over their contents, since they
|
||||
implement the `webContents` similarly to how `BrowserWindow` does it. However,
|
||||
as `WebContentsView`s are not elements inside the DOM, positioning them
|
||||
accurately with respect to DOM content requires coordination between the
|
||||
Main and Renderer processes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue