Skip to content

Instantly share code, notes, and snippets.

@Imperat
Created September 22, 2023 07:48
Show Gist options
  • Save Imperat/624d9989cff29005e6f9e8a9cc185eef to your computer and use it in GitHub Desktop.
Save Imperat/624d9989cff29005e6f9e8a9cc185eef to your computer and use it in GitHub Desktop.
Cursor Movement Causes Window Blur on App Startup
const {app, BrowserView, BrowserWindow} = require('electron')
app.whenReady().then(function createWindow () {
const mainWindow = new BrowserWindow({ width: 1080, height: 720 });
const browserView = new BrowserView();
browserView.webContents.loadURL('https://electronjs.org')
mainWindow.addBrowserView(browserView);
browserView.setBounds({ x: 0, y: 0, width: 1080, height: 720 });
// This is the problem:
browserView.webContents.focus();
// This fixes it:
// setTimeout(() => browserView.webContents.focus());
})
{
"name": "shocking-sound-quit-u8cib",
"productName": "shocking-sound-quit-u8cib",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "leliakin",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "25.8.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment