Zum Hauptteil springen

BrowserView

History
Version(s)Changes
None
API DEPRECATED

[!NOTE] Die BrowserView Klasse ist veraltet und wird durch die neue WebContentsView Klasse ersetzt.

Ein BrowserView kann verwendet werden, um zusätzliche Webinhalte in ein BrowserWindow einzubetten. Es ist wie ein untergeordnetes Fenster, mit der Ausnahme, dass es relativ zu dem übergeordneten Fenster positioniert ist. Es ist als Alternative zum Webview Tag gedacht.

Klasse: BrowserView

History
Version(s)Changes
None
API DEPRECATED

Erstelle und kontrolliere Ansichten.

[!NOTE] Die BrowserView Klasse ist veraltet und wird durch die neue WebContentsView Klasse ersetzt.

Process: Main

This module cannot be used until the ready event of the app module is emitted.

[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.

Beispiel

// Im Hauptprozess.
const { app, BrowserView, BrowserWindow } = require('electron')

app.whenReady().then(() => {
const win = new BrowserWindow({ width: 800, height: 600 })

const view = new BrowserView()
win.setBrowserView(view)
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
view.webContents.loadURL('https://electronjs.org')
})

new BrowserView([options]) Experimentell Veraltet

History
Version(s)Changes
None
API DEPRECATED
  • options Object (optional)
    • webPreferences WebPreferences (optional) - Einstellungen der Funktionen der Webseite.
      • devTools boolean (optional) - Gibt an ob die Entwicklerwerkzeuge aktiviert sind. Falls dies auf false gesetzt ist, kann BrowserWindow.webContents.openDevTools() nicht verwendet werden um die Entwicklerwerkzeuge zu öffnen. Standard ist true.
      • nodeIntegration boolesche (optional) - Ob Knotenintegration aktiviert ist. Standard ist false.
      • nodeIntegrationsInWorker boolean (optional) - Gibt an ob die Node Integration in Web Workern aktiviert ist. Standard ist false. Mehr dazu finden Sie in Multithreading.
      • nodeIntegrationInSubFrames boolean (optional) - Experimental option for enabling Node.js support in sub-frames such as iframes and child windows. All your preloads will load for every iframe, you can use process.isMainFrame to determine if you are in the main frame or not.
      • preload string (optional) - Gibt ein Skript an das vor allen anderen Skripten geladen wird bevor andere Skripte der Seite ausgeführt werden. Dieses Skript hat immer Zugriff auf die Node APIs, unabhängig davon ob die Node Integration aktiviert ist oder nicht. Der Wert sollte der absolute Pfad zum Skript sein. Wenn die Node Integration ausgeschaltet ist, kann das Preload Skript globale Node Symbole in den Globalen Scope zurückbringen. Siehe Beispiel hier.
      • sandbox boolean (optional) - Wenn gesetzt, wird der Renderer des Fensters in einer Sandbox ausgeführt, wodurch es kompatibel mit der Chromium Sandbox wird und die Node.js Integration deaktiviert wird. Dies ist nicht das gleiche wie nodeIntegration, da die APIs die dem Preload Skript zur Verfügung stehen stärker limitiert sind. Lesen Sie mehr über die Option hier.
      • session Session (optional) - Sets the session used by the page. Instead of passing the Session object directly, you can also choose to use the partition option instead, which accepts a partition string. When both session and partition are provided, session will be preferred. Standard ist die Standardsitzung.
      • partition string (optional) - Sets the session used by the page according to the session's partition string. If partition starts with persist:, the page will use a persistent session available to all pages in the app with the same partition. If there is no persist: prefix, the page will use an in-memory session. By assigning the same partition, multiple pages can share the same session. Standard ist die Standardsitzung.
      • zoomFactor number (optional) - The default zoom factor of the page, 3.0 represents 300%. Standard ist 1.0.
      • javascript boolean (optional) - Aktiviert die JavaScript-Unterstützung. Standard ist true.
      • webSecurity boolean (optional) - Wenn false, wird die Same-Origin-Richtlinie deaktiviert (meistens verwendet zum Testen von Websites) und allowRunningInsecureContent wird auf true gesetzt, wenn diese Option nicht vom Benutzer festgelegt wurde. Standard ist true.
      • allowRunningInsecureContent boolean (optional) - Erlaubt einer https-Seite das Ausführen von JavaScript, CSS oder Plugins von http-URLs. Standard ist false.
      • images boolean (optional) - Aktiviert die Bildunterstützung. Standard ist true.
      • imageAnimationPolicy string (optional) - Bestimmt, wie Bildanimationen ausgeführt werden sollen (z. B. GIFs). Kann animate, animateOnce oder noAnimation sein. Standard ist animate.
      • textAreasAreResizable boolean (optional) - TextArea Elemente skalierbar machen. Standard ist true.
      • webgl boolean (optional) - Aktiviert WebGL Unterstützung. Standard ist true.
      • plugins boolean (optional) - Ob Plugins aktiviert werden sollen. Standard ist false.
      • experimentalFeatures boolean (optional) - Aktiviert Chromiums experimentelle Funktionen. Standard ist false.
      • scrollBounce boolean (optional) macOS - Aktiviert den Bounce (Gummiband) Effekt auf macOS. Standard ist false.
      • enableBlinkFeatures string (optional) - Eine Liste von Zeichenketten getrennt durch ,, wie CSSVariables,KeyboardEventKey zum Aktivieren. Die vollständige Liste der unterstützten Funktions-strings finden Sie in der RuntimeEnabledFeatures.json5 Datei.
      • disableBlinkFeatures string (optional) - Eine Liste von Zeichenketten getrennt durch ,, wie CSSVariables,KeyboardEventKey zum deaktivieren. Die vollständige Liste der unterstützten Funktions-strings finden Sie in der RuntimeEnabledFeatures.json5 Datei.
      • defaultFontFamily Object (optional) - Legt die Standardschriftart für die font-family fest.
        • standard string (optional) - Standard Times New Roman.
        • serif string (optional) - Standard Times New Roman.
        • sansSerif string (optional) - Standard Arial.
        • monospace string (optional) - Standard Courier New.
        • cursive string (optional) - Standard Script.
        • fantasy string (optional) - Standard Impact.
        • math String (optional) - Standardmäßig auf Latin Modern Math.
      • defaultFontSize Integer (optional) - Standart ist 16.
      • defaultMonospaceFontSize Integer (optional) - Standart ist 13.
      • minimumFontSize Integer (optional) - Standart ist 0.
      • defaultEncoding string (optional) - Standard ISO-8859-1.
      • backgroundThrottling boolean (optional) - Ob Animationen und Timer gedrosselt werden sollen, wenn die Seite in den Hintergrund rückt. This also affects the Page Visibility API. Wenn mindestens ein webContents in einem einzelnen browserWindow das backgroundThrottling deaktiviert hat angezeigt wird, dann werden Rahmen für das gesamte Fenster und andere webContents, die von diesem dargestellt werden, gezeichnet und ausgetauscht. Standardwert ist true.
      • offscreen Object | boolean (optional) - Whether to enable offscreen rendering for the browser window. Standardwert ist false. See the offscreen rendering tutorial for more details.
        • useSharedTexture boolean (optional) Experimental - Whether to use GPU shared texture for accelerated paint event. Standardwert ist false. See the offscreen rendering tutorial for more details.
      • contextIsolation boolean (optional) - Whether to run Electron APIs and the specified preload script in a separate JavaScript context. Defaults to true. The context that the preload script runs in will only have access to its own dedicated document and window globals, as well as its own set of JavaScript builtins (Array, Object, JSON, etc.), which are all invisible to the loaded content. The Electron API will only be available in the preload script and not the loaded page. This option should be used when loading potentially untrusted remote content to ensure the loaded content cannot tamper with the preload script and any Electron APIs being used. Diese Option verwendet die gleiche Technik, wie sie von Chrome Content Scripts verwendet wird. You can access this context in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab.
      • webviewTag boolean (optional) - Whether to enable the <webview> tag. Standardwert ist false. Note: The preload script configured for the <webview> will have node integration enabled when it is executed so you should ensure remote/untrusted content is not able to create a <webview> tag with a possibly malicious preload script. You can use the will-attach-webview event on webContents to strip away the preload script and to validate or alter the <webview>'s initial settings.
      • additionalArguments string[] (optional) - A list of strings that will be appended to process.argv in the renderer process of this app. Useful for passing small bits of data down to renderer process preload scripts.
      • safeDialogs boolean (optional) - Whether to enable browser style consecutive dialog protection. Standard ist false.
      • safeDialogsMessage string (optional) - The message to display when consecutive dialog protection is triggered. If not defined the default message would be used, note that currently the default message is in English and not localized.
      • disableDialogs boolean (optional) - Whether to disable dialogs completely. Overrides safeDialogs. Standard ist false.
      • navigateOnDragDrop boolean (optional) - Whether dragging and dropping a file or link onto the page causes a navigation. Standard ist false.
      • autoplayPolicy string (optional) - Autoplay policy to apply to content in the window, can be no-user-gesture-required, user-gesture-required, document-user-activation-required. Defaults to no-user-gesture-required.
      • disableHtmlFullscreenWindowResize boolean (optional) - Whether to prevent the window from resizing when entering HTML Fullscreen. Default is false.
      • accessibleTitle string (optional) - Eine alternative Titelzeichenfolge nur für Zugänglichkeitswerkzeuge wie Bildschirmleser zur Verfügung gestellt. This string is not directly visible to users.
      • spellcheck boolean (optional) - Ob die eingebaute Rechtschreibprüfung aktiviert werden soll. Standard ist true.
      • enableWebSQL boolean (optional) - Ob die WebSQL API aktiviert werden soll. Standard ist true.
      • v8CacheOptions string (optional) - Erzwingt die v8 Code Caching Richtlinie die von Blink verwendet wird. Akzeptierte Werte sind
        • none - Deaktiviert Code-Caching
        • code - Heuristisches Code-Caching
        • bypassHeatCheck - Umgehe Code Cache Heuristik aber mit lazy Kompilierung
        • bypassHeatCheckAndEagerCompile - Dasselbe wie oben, außer, dass die Kompilierung eager ist. Standardrichtlinie ist code.
      • enablePreferredSizeMode boolean (optional) - Ob bevorzugte size mode aktiviert werden soll. Die bevorzugte Größe ist die minimale Größe, die benötigt wird um das Layout der documents zu beinhalten ohne scrollen zu müssen. Dies zu aktivieren, führt dazu, dass das preferred-size-changed -Ereignis auf WebContents ausgeführt wird, wenn sich die bevorzugte Größe ändert. Standard ist false.
      • transparent boolean (optional) - Gibt an, ob die Hintergrundtransparenz für die Gastseite aktiviert werden soll. Standard ist true. Hinweis: Die Text- und Hintergrundfarben der Gastseite werden aus dem Farbschema des Stammelements abgeleitet. Wenn die Transparenz aktiviert ist, ändert sich zwar die Textfarbe entsprechend, der Hintergrund bleibt jedoch transparent.
      • enableDeprecatedPaste boolean (optional) Veraltet - Ob das paste execCommand aktiviert werden soll. Standard ist false.

Instanz Eigenschaften

Objekte, die mit new BrowserView erstellt wurden, haben folgende Eigenschaften:

view.webContents Experimentell Veraltet

History
Version(s)Changes
None
API DEPRECATED

Ein WebContents Objekt im Besitz dieser Ansicht.

Beispiel Methoden

Objekte, die mit new BrowserView erstellt wurden, haben folgende Instanzmethoden:

view.setAutoResize(options) Experimentell Veraltet

History
  • options Objekt
    • width boolean (optional) - Wenn true, wächst und schrumpft die Breite der Ansicht zusammen mit dem übergeordneten Fenster. Automatisch false.
    • height boolean (optional) - Wenn true, wächst und schrumpft die Höhe der Ansicht zusammen mit dem übergeordneten Fenster. Automatisch false.
    • horizontal boolean (optional) - Wenn true, ändert sich sowohl die X-Position als auch die Breite der Ansicht zusammen mit dem übergeordneten Fenster. Automatisch false.
    • vertical boolean (optional) - Wenn true, ändert sich sowohl die Y-Position als auch die Höhe der Ansicht zusammen mit dem übergeordneten Fenster. Automatisch false.

view.setBounds(bounds) Experimentell Veraltet

History
Version(s)Changes
None
API DEPRECATED

Passt die Ansicht an die Dimensionen und die Ausrichtung des Rechteckes relativ zum übergeordneten Fenster an.

view.getBounds() Experimentell Veraltet

History
Version(s)Changes
None
API DEPRECATED

Returns Rectangle

Die bounds dieser BrowserView-Instanz als Object.

view.setBackgroundColor(color) Experimentell Veraltet

History
Version(s)Changes
None
API DEPRECATED
  • color string - Farbe in Hex, RGB, ARGB, HSL, HSLA oder benannten CSS-Farbformat. Der Alphakanal ist optional für den Hex-Typ.

Beispiele für gültige color Werte:

  • Hex
    • #fff (RGB)
    • #ffff (ARGB)
    • #ffffff (RRGGBB)
    • #ffffffff (AARRGGBB)
  • RGB
    • rgb\(([\d]+),\s*([\d]+),\s*([\d]+)\)
      • z.B. rgb(255, 255, 255)
  • RGBA
    • rgba\(([\d]+),\s*([\d]+),\s*([\d]+),\s*([\d.]+)\)
      • z.B. rgba(255, 255, 255, 1.0)
  • HSL
    • hsl\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%\)
      • z.B. hsl(200, 20%, 50%)
  • HSLA
    • hsla\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)
      • z.B. hsla(200, 20%, 50%, 0.5)
  • Farbname
    • Optionen sind in SkParseColor.cpp aufgelistet
    • Ähnlich wie CSS-Farbmodul Level 3 Keywords, aber Groß- und Kleinschreibung.
      • z.B. blueviolet oder red

[!NOTE] Hex-Format mit Alphawert nimmt AARRGGBB oder ARGB, aber nicht RRGGBBAA oder RGB.