BrowserWindow | Electron
https://www.electronjs.org/de/docs/latest/api/browser-window • 274 KB fetched
Open original page
BrowserWindow | Electron
Zum Hauptteil springen
Electron Dokumentation API Blog Tools
* Electron Forge
* Elektro-Fiddle
Community
* Kontrolle
* Showcase
* Ressourcen
Veröffentlichungen Deutsch
* English
* Deutsch
* Español
* Français
* 日本語
* Português
* Русский
* 中文
Suche
* Hauptprozessmodule
* app
* autoUpdater
* BaseWindow
* BrowserView
* Deprecated
* BrowserWindow
* clipboard
* contentTracing
* crashReporter
* desktopCapturer
* dialog
* globalShortcut
* ImageView
* inAppPurchase
* ipcMain
* Menu
* MenuItem
* MessageChannelMain
* MessagePortMain
* nativeImage
* nativeTheme
* net
* netLog
* Notification
* powerMonitor
* powerSaveBlocker
* process
* protocol
* pushNotifications
* safeStorage
* screen
* session
* sharedTexture
* ShareMenu
* shell
* systemPreferences
* TouchBar
* Tray
* utilityProcess
* webContents
* WebContentsView
* webFrameMain
* View
* Renderer Prozessmodule
* Utility Process Modules
* Benutzerdefinierte DOM-Elemente
* Chromium und Node.js
* Klassen
* API-Strukturen
*
* Hauptprozessmodule
* BrowserWindow Auf dieser Seite
BrowserWindow
Erstellung und Steuerung von Browserfenstern.
Process: Main
This module cannot be used until the ready event of the app module is emitted.
// Im Hauptprozess.
const { BrowserWindow } = require ( 'electron' )
const win = new BrowserWindow ( { width : 800 , height : 600 } )
// Load a remote URL
win . loadURL ( 'https://github.com' )
// Or load a local HTML file
win . loadFile ( 'index.html' )
Window customization
The BrowserWindow class exposes various ways to modify the look and behavior of your app's windows. For more details, see the Window Customization tutorial.
Showing the window gracefully
When loading a page in the window directly, users may see the page load incrementally, which is not a good experience for a native app. To make the window display without a visual flash, there are two solutions for different situations.
Using the ready-to-show event
Das ready-to-show Ereignis wird während des Ladens der Seite ausgelöst, falls das Fenster noch nicht angezeigt wurde nachdem der Rendererprozess die Seite erstmalig gerendert hat. Wenn das Fenster nach diesem Ereignis gezeigt wird, gibt es keinen bemerkbaren Seitenaufbau:
const { BrowserWindow } = require ( 'electron' )
const win = new BrowserWindow ( { show : false } )
win . once ( 'ready-to-show' , ( ) => {
win . show ( )
} )
Für gewöhnlich wird dieses Ereignis nach dem did-finish-load Ereignis ausgelöst. Bei Seiten mit vielen Remoteressourcen kann es aber passieren dass das Event vor dem did-finish-load Ereignis ausgelöst wird.
Bitte beachten Sie, dass die Verwendung dieses Ereignisses impliziert, dass der Renderer als "sichtbar" und bemalt betrachtet wird, obwohl show falsch ist. Dieses Ereignis wird nie abfeuern, wenn paintWhenInitiallyHidden: false gesetzt ist.
Setting the backgroundColor property
Bei umfangreichen Apps könnte das ready-to-show Ereignis zu spät ausgelöst werden, sodass sich die App langsam anfühlt. In diesem Fall empfiehlt es sich, das Fenster sofort anzuzeigen und die backgroundColor auf einen Wert zu setzen der dem Hintergrund ihrer App ähnelt:
const { BrowserWindow } = require ( 'electron' )
const win = new BrowserWindow ( { backgroundColor : '#2e2c29' } )
win . loadURL ( 'https://github.com' )
Note that even for apps that use ready-to-show event, it is still recommended to set backgroundColor to make the app feel more native.
Some examples of valid backgroundColor values include:
const win = new BrowserWindow ( )
win . setBackgroundColor ( 'hsl(230, 100%, 50%)' )
win . setBackgroundColor ( 'rgb(255, 145, 145)' )
win . setBackgroundColor ( '#ff00a3' )
win . setBackgroundColor ( 'blueviolet' )
For more information about these color types see valid options in win.setBackgroundColor .
Übergeordnete und untergeordnete Fenster
Mithilfe der parent Option können Sie untergeordnete Fenster erstellen:
const { BrowserWindow } = require ( 'electron' )
const top = new BrowserWindow ( )
const child = new BrowserWindow ( { parent : top } )
child . show ( )
top . show ( )
Das child Fenster wird stets über dem top Fenster angezeigt.
Modale Fenster
A modal window is a child window that disables parent window. To create a modal window, you have to set both the parent and modal options:
const { BrowserWindow } = require ( 'electron' )
const top = new BrowserWindow ( )
const child = new BrowserWindow ( { parent : top , modal : true , show : false } )
child . loadURL ( 'https://github.com' )
child . once ( 'ready-to-show' , ( ) => {
child . show ( )
} )
Seiten Sichtbarkeit
Die Page Visibility API Funktioniert wie folgt:
* Auf allen Plattformen gibt der Sichtbarkeitszustand an ob das Fenster versteckt bzw. minimiert ist oder nicht.
* Zusätzlich wird unter macOS auch angegeben ob das Fenster verdeckt ist. Wenn das Fenster vollständig durch ein anderes Fenster verdeckt ist, ist der Sichtbarkeitszustand hidden . Auf den anderen Plattformen ist der Sichtbarkeitszustand nur hidden , wenn das Fenster minimiert oder explizit durch win.hide() verseckt wurde.
* Wenn ein BrowserWindow mit der Option show: false erzeugt wurde, ist der anfängliche Sichtbarkeitszustand visible , obwohl das Fenster eigentlich versteckt ist.
* Wenn backgroundThrottling deaktiviert ist, bleibt der Sichtbarkeitszustand visible , selbst wenn das Fenster minimiert, verdeckt oder versteckt wird.
Es wird empfohlen aufwendige Aufgaben zu pausieren wenn der Sichtbarkeitszustand hidden ist, um Energie zu sparen.
Plattformhinweise
* Unter macOS werden modale Fenster als Seiten angezeigt, die an das übergeordnete Fenster angehängt sind.
* Wenn unter macOS übergeordnete Fenster bewegt werden, behalten untergeordnete Fenster ihre Position relativ zum übergeordneten Fenster bei. Unter Windows und Linux bewegen sich die untergeordneten Fenster nicht.
* Unter Linux wird der Typ von modalen Fenstern zu dialog geändert.
* Unter Linux wird das verstecken von modalen Fenstern von vielen Desktop Umgebungen nicht unterstützt.
* On Wayland (Linux) it is generally not possible to programmatically resize windows after creation, or to position, move, focus, or blur windows without user input. If your app needs these capabilities, run it in Xwayland by appending the flag --ozone-platform=x11 .
Class: BrowserWindow extends BaseWindow
Erstellung und Steuerung von Browserfenstern.
Process: Main
BrowserWindow ist ein EventEmitter .
Es erzeugt ein neues BrowserWindow mit nativen Eigenschaften die durch options gesetzt wurden.
[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ .
new BrowserWindow([options])
* options BrowserWindowConstructorOptions (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. Default is true since Electron 20. The sandbox will automatically be disabled when nodeIntegration is set to true . 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) - When false , it will disable the same-origin policy (usually using testing websites by people), and set allowRunningInsecureContent to true if this option has not been set by user. 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.
* sharedTexturePixelFormat string (optional) Experimental - The requested output format of the shared texture. Standard ist argb . The name is originated from Chromium media::VideoPixelFormat enum suffix and only subset of them are supported. The actual output pixel format and color space of the texture should refer to OffscreenSharedTexture object in the paint event.
* argb - The requested output texture format is 8-bit unorm RGBA, with SRGB SDR color space.
* rgbaf16 - The requested output texture format is 16-bit float RGBA, with scRGB HDR color space.
* nv12 - The requested output texture format is 12bpp with Y plane followed by a 2x2 interleaved UV plane, with REC709 color space.
* deviceScaleFactor number (optional) Experimental - The device scale factor of the offscreen rendering output. If not set, will use 1 as default.
* 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 .
* focusOnNavigation boolean (optiona
Links found on this page
- Zum Hauptteil springen [direct]
- Electron [direct]
- Dokumentation [direct]
- API [direct]
- Blog [direct]
- Electron Forge [direct]
- Elektro-Fiddle [direct]
- Kontrolle [direct]
- Showcase [direct]
- Ressourcen [direct]
- Veröffentlichungen [direct]
- English [direct]
- Español [direct]
- Français [direct]
- 日本語 [direct]
- Português [direct]
- Русский [direct]
- 中文 [direct]
- autoUpdater [direct]
- BaseWindow [direct]
- BrowserView Deprecated [direct]
- clipboard [direct]
- contentTracing [direct]
- crashReporter [direct]
- desktopCapturer [direct]
- dialog [direct]
- globalShortcut [direct]
- ImageView [direct]
- inAppPurchase [direct]
- ipcMain [direct]
- Menu [direct]
- MenuItem [direct]
- MessageChannelMain [direct]
- MessagePortMain [direct]
- nativeImage [direct]
- nativeTheme [direct]
- net [direct]
- netLog [direct]
- Notification [direct]
- powerMonitor [direct]
- powerSaveBlocker [direct]
- process [direct]
- protocol [direct]
- pushNotifications [direct]
- safeStorage [direct]
- screen [direct]
- session [direct]
- sharedTexture [direct]
- ShareMenu [direct]
- shell [direct]
- systemPreferences [direct]
- TouchBar [direct]
- Tray [direct]
- utilityProcess [direct]
- webContents [direct]
- WebContentsView [direct]
- webFrameMain [direct]
- View [direct]
- Benutzerdefinierte DOM-Elemente [direct]
- Chromium und Node.js [direct]
- Klassen [direct]
- API-Strukturen [direct]
- Main [direct]
- Window Customization [direct]
- Page Visibility API [direct]
- EventEmitter [direct]
- the FAQ [direct]
- BrowserWindowConstructorOptions [direct]
- WebPreferences [direct]
- Multithreading [direct]
- hier [direct]
- hier [direct]
- RuntimeEnabledFeatures.json5 [direct]
- offscreen rendering tutorial [direct]
- media::VideoPixelFormat [direct]
- OffscreenSharedTexture [direct]
- Chrome Content Scripts [direct]
- WebSQL API [direct]
- Farbschema [direct]
- execCommand [direct]