'Electron starts unfocused (responds to double clicks only)

I'm developing a test application using Electron 18.

I noticed that sometimes on mac the app starts without the focus.

If I click on the window nothing change, I noticed that performing a double click the html buttons are pressed but the window remain unfocused.

My code if very very easy:

Html:

<button>Test</button>
<hr>

Also the main.js is basic:

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

const createWindow = () => {
const win = new BrowserWindow({
  width: 800,
  height: 600
})

  win.loadFile('index.html')
}

app.whenReady().then(() => {
  createWindow()
})

Nothing more..

I start the app with elecrtron ./ and sometime, I get the windows unfocus as the following image (as you can see the app name is gray, unfocused): enter image description here

It happen more ofter when I press ctrl+R to refresh the page



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source