fix: open desktop browser popups in place

Loads target=_blank links inside the context panel browser
Handles webview popup navigation from Electron
This commit is contained in:
Bohdan Triapitsyn
2026-05-30 02:04:32 +03:00
parent f9e9f30873
commit 2b4b963f24
2 changed files with 67 additions and 0 deletions
+23
View File
@@ -3062,6 +3062,29 @@ contextMenu({
showCopyLink: true,
});
const loadUrlInsideWebContents = (contents, rawUrl) => {
try {
const url = new URL(rawUrl);
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
if (contents.isDestroyed()) return false;
void contents.loadURL(url.toString()).catch((error) => {
log.warn('[webview] failed to load popup URL in place:', error);
});
return true;
} catch {
return false;
}
};
app.on('web-contents-created', (_event, contents) => {
if (contents.getType() !== 'webview') return;
contents.setWindowOpenHandler(({ url }) => {
loadUrlInsideWebContents(contents, url);
return { action: 'deny' };
});
});
// All desktop_* IPC and dialog:open run with full Electron main privileges
// (fs access, shell.openPath, spawn, app.relaunch, …). The preload shim is
// injected into every webContents in the window, including remote hosts the