Open pushkin- opened 4 years ago
doing the bv.webContents.focus()
operation on a setTimeout(..., 0)
works around the issue
This affects 11.2.0 and is reproducible without the devtools workflow:
The window close is triggering a focus (explicitly) and that seems to trigger the other window's focus for some reason.
main.js:
const { join } = require("path");
const { app, BrowserWindow, BrowserView } = require('electron')
async function createWindow() {
const mainWindow = new BrowserWindow();
const view = new BrowserView({ webPreferences: { nativeWindowOpen: true }});
mainWindow.setBrowserView(view);
const bounds = mainWindow.getContentBounds();
view.setBounds({x: 0, y: 0, width: bounds.width, height: bounds.height});
mainWindow.on("focus", () => {
view.webContents.focus();
});
await view.webContents.loadFile(join(__dirname, "index.html"));
view.webContents.on("new-window", (e, url, frameName, disp, opts) => {
if (frameName === "browserView") {
e.preventDefault();
const win = new BrowserWindow(opts);
e.newGuest = win;
const bv = new BrowserView();
win.setBrowserView(bv);
win.on("focus", () => {
bv.webContents.focus();
});
bv.webContents.loadURL(url);
}
});
app.on("browser-window-created", (e, window) => {
window.on("closed", () => {
mainWindow.focus();
});
});
}
app.on('ready', createWindow)
index.html:
<!DOCTYPE html>
<html>
<body>
<button id="b">Open window with BrowserView</button>
<button id="b2">Open window</button>
<script src="./renderer.js"></script>
</body>
</html>
renderer.js:
document.getElementById("b").onclick = () => {
window.open("https://google.com", "browserView");
};
document.getElementById("b2").onclick = () => {
window.open("https://google.com");
};
Please make sure that the workflow in this dupe issue is also fixed.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
repros in Electron 21
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
repros with v22 gist
click "Open window with BrowserView" click "Open window" Focus the BrowserView window Close the child window focus switches between the windows forever.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
repros with v27
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
repros w v29 alpha 8
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
Preflight Checklist
Issue Details
Actual Behavior
closing out of devtools triggers infinite focus events for a secondary window when the window and the main window have focus event handlers that focus their respective browser view web contents
Expected Behavior
I expect this not to happen.
Closing the detached devtools (has to be detached) puts focus in the main window which triggers the main window's focus handler which focuses the main window's browser view's webcontents. For some reason, doing that causes the focus event of the secondary window to fire, and we get left in a focus loop.
To Reproduce
Screenshots
Additional Information
It is important to close out of the devtools the normal way: click the X in the devtools window.
This isn't reproducible if you close out of devtools via the taskbar (hover over electron icon, find devtools window image, click X)