Skip to content

Commit f93e335

Browse files
authored
docs: revised the web embeds feature page (electron#26008)
* docs: revised the web embeds feature page * docs: minor styling updates to the web embeds feature page * docs: fixed text and grammar mentions * docs: changed placement of the webviews warning * docs: added a few missing commas
1 parent 35455c7 commit f93e335

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

docs/tutorial/web-embeds.md

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
1-
# Web embeds in Electron
2-
3-
If you want to embed (third party) web content in an Electron `BrowserWindow`, there are three options available to you: `<iframe>` tags, `<webview>` tags, and `BrowserViews`. Each one offers slightly different functionality and is useful in different situations. To help you choose between these, this guide will explain the differences and capabilities of each.
4-
5-
## Iframes
6-
7-
Iframes in Electron behave like iframes in regular browsers. An `<iframe>` element in your page can show external web pages, provided that their [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) allows it. To limit the amount of capabilities a site in an `<iframe>` tag, it's recommended to use the [`sandbox` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox) and only allow the capabilities you want to support.
8-
9-
## WebViews
10-
11-
[WebViews](../api/webview-tag.md) are based on Chromium's WebViews and are not explicitly supported by Electron. We do not guarantee that the WebView API will remain available in future versions of Electron. This is why, if you want to use `<webview>` tags, you will need to set `webviewTag` to `true` in the `webPreferences` of your `BrowserWindow`.
12-
13-
WebViews are a custom element (`<webview>`) that will only work inside Electron.
14-
They are implemented as an "out-of-process iframe". This means that all communication with the `<webview>` is done asynchronously using IPC. The `<webview>` element has many custom methods and events, similar to `webContents`, that allow you much greater control over the contents.
15-
16-
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.
17-
18-
## BrowserViews
19-
20-
[BrowserViews](../api/browser-view.md) are not 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 that their position is not controlled by the DOM or CSS but by setting the bounds in the main process.
21-
22-
BrowserViews offer the greatest control over their contents, since they implement the `webContents` similarly to how a `BrowserWindow` implements it. However, they are not part of your DOM but are overlaid on top of them, which means you will have to manage their position manually.
1+
# Web embeds
2+
3+
## Overview
4+
5+
If you want to embed (third-party) web content in an Electron `BrowserWindow`,
6+
there are three options available to you: `<iframe>` tags, `<webview>` tags,
7+
and `BrowserViews`. Each one offers slightly different functionality and is
8+
useful in different situations. To help you choose between these, this guide
9+
explains the differences and capabilities of each option.
10+
11+
### Iframes
12+
13+
Iframes in Electron behave like iframes in regular browsers. An `<iframe>`
14+
element in your page can show external web pages, provided that their
15+
[Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
16+
allows it. To limit the number of capabilities of a site in an `<iframe>` tag,
17+
it is recommended to use the [`sandbox` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox)
18+
and only allow the capabilities you want to support.
19+
20+
### WebViews
21+
22+
> Important Note:
23+
[we do not recommend you to use use WebViews](https://www.electronjs.org/docs/api/webview-tag#warning),
24+
as this tag undergoes dramatic architectural changes that may affect stability
25+
of your application. Consider switching to alternatives, like `iframe` and
26+
Electron's `BrowserView`, or an architecture that avoids embedded content
27+
by design.
28+
29+
[WebViews](../api/webview-tag.md) are based on Chromium's WebViews and are not
30+
explicitly supported by Electron. We do not guarantee that the WebView API will
31+
remain available in future versions of Electron. To use `<webview>` tags, you
32+
will need to set `webviewTag` to `true` in the `webPreferences` of your
33+
`BrowserWindow`.
34+
35+
WebView is a custom element (`<webview>`) that will only work inside Electron.
36+
They are implemented as an "out-of-process iframe". This means that all
37+
communication with the `<webview>` is done asynchronously using IPC. The
38+
`<webview>` element has many custom methods and events, similar to
39+
`webContents`, that provide you with greater control over the content.
40+
41+
Compared to an `<iframe>`, `<webview>` tends to be slightly slower but offers
42+
much greater control in loading and communicating with the third-party content
43+
and handling various events.
44+
45+
### BrowserViews
46+
47+
[BrowserViews](../api/browser-view.md) are not a part of the DOM - instead,
48+
they are created in and controlled by your Main process. They are simply
49+
another layer of web content on top of your existing window. This means
50+
that they are completely separate from your own `BrowserWindow` content and
51+
their position is not controlled by the DOM or CSS. Instead, it is controlled
52+
by setting the bounds in the Main process.
53+
54+
`BrowserViews` offer the greatest control over their contents, since they
55+
implement the `webContents` similarly to how the `BrowserWindow` does it.
56+
However, as `BrowserViews` are not a part of your DOM, but are rather overlaid
57+
on top of them, you will have to manage their position manually.

0 commit comments

Comments
 (0)