javascriptelectronelectron-builder

How do I set the window name/title in ElectronJS?


Silly question, but I've been struggling just trying to change an Electron window's name for a while now, so hopefully someone here can just help me with it.

I'm trying to change it from "Electron" to anything else. I can get every other title/name changed to what I want, but no matter what I seem to try, it always says "Electron"... :(

enter image description here

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title> <!-- Window name isn't this -->
  </head>
  <body>
    <h1>hi</h1>
  </body>
</html>
// main.js
const { app, BrowserWindow } = require('electron')

function createWindow() {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntegration: true
        },
        title: 'Foo' // Window name isn't this
    })
    app.setName('Bar') // Window name isn't this
    win.setTitle('ReeeeeBar') // Window name isn't this
    win.loadFile('index.html')
}

app.whenReady().then(createWindow)
// package.json
{
  "name": "foobar-electron-app", // Window name isn't this
  "main": "main.js",
  "dependencies": {
    "electron": "^9.1.2"
  }
}

To be very specific, I'm trying to change this: enter image description here


Solution

  • Actually, you can change that particular name. But it's hacky and has no sense :).

    For MacOSX, go to node_modules/electron/dist/Electron.app/Contents/Info.plist and change value for CFBundleName.

    For packaged apps electron/builder will look into productName or name field in package.json - no need for hacks.