Differences between revisions 4 and 5
Revision 4 as of 2023-03-02 17:32:51
Size: 1373
Comment:
Revision 5 as of 2023-03-02 17:35:18
Size: 1374
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
const { app, BrowserWindow } = require("electron"); const { app, BrowserWindow } = require('electron');
Line 29: Line 29:
      preload: filePreload,       preload: 'preload.js',
Line 48: Line 48:
const { BrowserWindow } = require("electron"); const { BrowserWindow } = require('electron');
Line 60: Line 60:
const { BrowserWindow } = require("electron"); const { BrowserWindow } = require('electron');

Electron Browser Window


BrowserWindow

The basic usage of BrowserWindow is as follows:

  • Wait for the ready event

  • Initialize the object with window size and necessary security options
  • Load an index

const { app, BrowserWindow } = require('electron');

var win;

app.on('ready', () => {
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      contextIsolation: true,
      nodeIntegration: false,
      preload: 'preload.js',
    }
  });

  win.loadFile('index.html');

  win.on('closed', () => {
    win = null;
  });
});

Graceful Load

For large index pages, loading may be visible. To wait for rendering to complete before showing the window, listen for the ready-to-show event.

const { BrowserWindow } = require('electron');

const win = new BrowserWindow({ show: false });

win.once('ready-to-show', () => {
  win.show();
});

Set a background color to show as a placeholder.

const { BrowserWindow } = require('electron');

const win = new BrowserWindow({ backgroundColor: '#ffffff' });

Child and Modal Windows


See also

Electron API for BrowserWindow


CategoryRicottone

Node/Electron/BrowserWindow (last edited 2023-03-02 17:38:24 by DominicRicottone)