Skip to content

Instantly share code, notes, and snippets.

@t57ser
Created June 19, 2024 07:25
Show Gist options
  • Save t57ser/593fffc8417dc35f1df5c84227db595d to your computer and use it in GitHub Desktop.
Save t57ser/593fffc8417dc35f1df5c84227db595d to your computer and use it in GitHub Desktop.
webContentsView steals focus after loading url
const {app, BrowserWindow, ipcMain, WebContentsView} = require('electron')
let mainWindow
function createWindow () {
const mainWindow1 = new BrowserWindow({
x: 0,
y: 0,
width: 1000,
height: 600,
show: true,
frame: false,
});
mainWindow1.loadURL("https://www.google.com").then(() => {
mainWindow1.webContents.openDevTools();
})
const bw1 = new WebContentsView({
x: 0,
y: 0,
width: 200,
height: 200,
show: true,
});
bw1.setBounds({
x: 0,
y: 0,
width: 200,
height: 200,
});
bw1.webContents.loadURL("https://www.google.com");
bw1.webContents.openDevTools({mode: "detach"})
mainWindow1.contentView.addChildView(bw1);
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
{
"main": "main7.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "31.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment