-
Notifications
You must be signed in to change notification settings - Fork 16.9k
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Electron Version
12.0.1
What operating system are you using?
Windows
Operating System Version
Windows 10 v1909
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
when executing window.close() in web page in a BrowserView, the window won't close.
Actual Behavior
The window is closed
Testcase Gist URL
No response
This is a continuation of this closed issue
- run main.js
- execute
window.close()inside of web page's devtools - observe that the window closes
main.js:
(async () => {
const { app, BrowserWindow, BrowserView } = require("electron");
app.on("window-all-closed", async () => {
app.quit();
});
await app.whenReady();
const mainWindow = new BrowserWindow();
const view = new BrowserView();
view.setBounds({x: 0, y: 0, width: 800, height: 600});
mainWindow.setBrowserView(view);
await view.webContents.loadURL("https://google.com");
view.webContents.openDevTools();
})();
Some notes form the closed issue:
I think the issue is that if you have a BrowserWindow with a BrowserView attached to it, calling window.close from inside the view will close the parent window, which isn't what I would expect to happen. Since the close event on BrowserWindow doesn't provide a way to tell whether the window itself or just the view is closing, there's no way to prevent this behavior without also making it impossible to close the window.
I think the expected behavior would be that calling close() from inside a BrowserView doesn't do anything to the window, and the view would emit a close event to let you destroy the view (like how webviews work).
This PR was opened to address this but never landed.