Search code examples
electrondesktop-application

Electron: Maximize Window on Start


I'm creating a electron app and am trying to allow it to open so that it is maximized on start. Is there a function of some kind that you put in the main.js to maximize the window? Thanks!


Solution

  • win.maximize() will maximize your window.

    One caveat: even if you instantly call this function after creating the BrowserWindow you may still see the small window before maximizing. So hiding the window and showing it only after maximizing should do the trick.

    const { BrowserWindow, app } = require("electron");
    
    let win;
    app
      .whenReady()
      .then(() => {
        win = new BrowserWindow({
          show: false,
        });
        win.maximize();
        win.show();
      })
      .catch(console.error);