TutorialOctober 3, 2025·6 min read
Creating a Transparent Always-on-Top Window in Electron
Building a desktop overlay app? The transparent always-on-top window is the foundation. Here's how to do it correctly in Electron 28.
Basic Configuration
const win = new BrowserWindow({
x: 0, y: 0,
width: screen.getPrimaryDisplay().workArea.width,
height: screen.getPrimaryDisplay().workArea.height,
frame: false,
transparent: true,
resizable: false,
hasShadow: false,
skipTaskbar: true,
alwaysOnTop: true,
focusable: false,
backgroundColor: '#00000000',
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.js')
}
});
win.setIgnoreMouseEvents(true, { forward: true });
win.setAlwaysOnTop(true, 'screen-saver');Click-Through Magic
The setIgnoreMouseEvents(true, { forward: true }) combination is critical. It tells Electron to pass mouse events through the window to whatever is behind it — while still letting your renderer receive mousemove events.
When your pet needs to be clickable, disable it temporarily:
ipcMain.on('pet:set-ignore-mouse-events', (_e, ignore) => {
petWindow.setIgnoreMouseEvents(ignore, { forward: true });
});Chromium Flags
On some Windows setups, transparency needs help. Add these flags:
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-features', 'CalculateNativeWinOcclusion');Full Dhiva Pet source is on GitHub.