Description
On Windows with the native renderer, pressing Ctrl+N inside a BrowserWindow opens a new, empty WebView2 popup window. The app gets no event for it: new-window-open is not emitted, and a capture-phase keydown listener in the page that calls preventDefault() for Ctrl+N does not stop it.
For a desktop app this is never wanted, and it also makes Ctrl+N unusable as an app shortcut.
Steps to reproduce
- Create a native
BrowserWindowon Windows (Electrobun 2.0.1; also unchanged on master at v2.0.3-beta.7):
import { BrowserWindow } from "electrobun/main"
const win = new BrowserWindow({
title: "Ctrl+N repro",
url: "views://mainview/index.html",
frame: { width: 800, height: 600 },
renderer: "native",
})
win.webview.on("new-window-open", (e) => console.log("new-window-open", e))- In the page, add
window.addEventListener("keydown", (e) => { if (e.ctrlKey && e.key === "n") e.preventDefault() }, true). - Focus the window and press Ctrl+N.
Actual behavior
An empty WebView2 window opens. No new-window-open event is logged.
Expected behavior
No window opens unless the app asks for one. Ideally the key either reaches the page (so preventDefault() works) or is surfaced to the host as an event, so apps can bind Ctrl+N themselves.
Possible implementation
nativeWrapper.cpp (Windows) registers no NewWindowRequested and no AcceleratorKeyPressed handler, and never sets AreBrowserAcceleratorKeysEnabled, so WebView2's defaults apply. Either of these would fix it:
- Handle
ICoreWebView2::add_NewWindowRequested: setHandled = TRUEand forward the request URI asnew-window-open, so every window request goes through the app. - Handle
ICoreWebView2Controller::add_AcceleratorKeyPressedand expose browser accelerator keys as an option (e.g.browserAcceleratorKeys: false), alongsideput_AreBrowserAcceleratorKeysEnabled(FALSE).
Related: #549 (Windows new-window-open is inferred from NavigationStarting + Ctrl key state rather than from NewWindowRequested), #534 (another WebView2 browser default apps want to turn off).
Activity
0No activity yet.