Created
June 19, 2024 07:25
-
-
Save t57ser/593fffc8417dc35f1df5c84227db595d to your computer and use it in GitHub Desktop.
webContentsView steals focus after loading url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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