Saltar al contenido principal

Web Embeds

Descripción general

Si quiere incrustar contenido web (de terceros) en un BrowserWindow de Electron, hay tres opciones disponible para usted: <iframe> tags, <webview> tags, y WebContentsView. Cada una ofrece una funcionalidad ligeramente diferente y es útil en diferentes situaciones. To help you choose between these, this guide explains the differences and capabilities of each option.

Iframes

Iframes en Electron se comportan como iframes en los navegadores regulares. An <iframe> element in your page can show external web pages, provided that their Content Security Policy allows it. To limit the number of capabilities of a site in an <iframe> tag, it is recommended to use the sandbox attribute and only allow the capabilities you want to support.

WebViews

Nota importante: no se recomienda el uso de WebViews, ya que esta etiqueta genera cambios dramáticos en la arquitectura que podrían afectar a la estabilidad de tu aplicación. Consider switching to alternatives, like iframe and Electron's WebContentsView, or an architecture that avoids embedded content by design.

WebViews son basados en las WebViews de Chromium y no están soportados explícitamente por Electron. No garantizamos que la API WebView permanezca disponible en versiones futuro de Electron. Para usar <webview> etiquetas, necesitaras establecer webviewTag a true en el webPreferences de tu BrowserWindow.

WebView es un elemento personalizado (<webview>) que sólo funcionara dentro de Electron. Están implementadas como un "iframe fuera de proceso". Esto quiere decir que toda la comunicación con el <webview> se hace de forma asíncrona usando IPC. The <webview> element has many custom methods and events, similar to webContents, that provide you with greater control over the content.

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.

WebContentsView

WebContentsViews 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.

WebContentsViews offer the greatest control over their contents, since they implement the webContents similarly to how BrowserWindow does it. However, as WebContentsViews are not elements inside the DOM, positioning them accurately with respect to DOM content requires coordination between the Main and Renderer processes.