Skip to content

Commit 0604de5

Browse files
fix(web): set allowpopups before the preview webview attaches
Electron reads allowpopups when the guest attaches. The attribute was set from the ref callback, which runs after the element is in the DOM, so every preview guest attached with popups disabled and Electron blocked window.open before the window-open handler ran. Verified in a running desktop build: will-attach-webview reported allowpopups: false before this change and true after.
1 parent 7c5b69a commit 0604de5

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎apps/web/src/browser/HostedBrowserWebview.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export function HostedBrowserWebview(props: {
9292

9393
const setWebviewRef = useCallback((node: HTMLElement | null) => {
9494
webviewRef.current = node as ElectronWebview | null;
95-
if (node && !node.hasAttribute("allowpopups")) node.setAttribute("allowpopups", "true");
9695
}, []);
9796

9897
useEffect(() => {
@@ -259,6 +258,10 @@ export function HostedBrowserWebview(props: {
259258
<webview
260259
key={webviewGeneration}
261260
ref={setWebviewRef}
261+
// Must be an attribute on the element itself: Electron reads it when the
262+
// guest attaches, so setting it from the ref callback lands too late and
263+
// the guest attaches with popups disabled.
264+
allowpopups="true"
262265
src={webviewGeneration === 0 ? initialSrc : recoverySrc}
263266
partition={config.partition}
264267
webpreferences={config.webPreferences}

0 commit comments

Comments
 (0)