[Bug]: window.open("about:blank") replaces the preview page, which breaks MSAL login and its redirect fallback #14452
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/desktop
Steps to reproduce#
Open any page in a preview tab, for example
http://localhost:3000/.Run this in the page, for example from a click handler:
const w = window.open('about:blank', 'popup', 'width=483,height=600') console.log(w) // nullThe call returns
null, and then the preview tab navigates toabout:blank. The original page is gone.
This is how @azure/msal-browser opens its popup. With the default asyncPopups: false, loginPopup() and acquireTokenPopup() call window.open("about:blank", …) synchronously in the click handler, then set the popup's URL (PopupClient.openSizedPopup). Other SDKs pre-open a blank popup this way to keep the user gesture.
Expected behavior#
If the preview won't open a real window for about:blank, it should deny the call without navigating the preview tab. window.open then returns null and the page stays as it was, which is what a normal popup blocker does. SDKs detect this case and fall back: MSAL throws popup_window_error, and apps typically call loginRedirect() next.
Actual behavior#
The call is denied and the preview tab loads about:blank. MSAL throws popup_window_error, and the app's loginRedirect() fallback runs from a page that is already being replaced. The tab stays blank, with no Microsoft sign-in. Reading sessionStorage on that page then throws SecurityError: Access is denied for this document.
Cause, in apps/desktop/src/preview/Manager.ts on main (c2fa9fc911):
isPopupUrldeliberately excludesabout:blank, for thecontextIsolationreason in its comment. SopreviewWindowOpenActionreturns"navigate"for thisnew-windowrequest.- The
setWindowOpenHandlerin the preview attach path handles"navigate"withwc.loadURL(details.url)and returns{ action: "deny" }. Forabout:blank, this loads a blank page over the opener.
Loading about:blank into the opener never helps. A possible fix: when the URL isn't a popup URL, for example about:blank or "", return { action: "deny" } without calling loadURL. The page then gets a plain blocked popup and can use its own fallback.
Related: #6561 / #8435 (OAuth popups for http(s) URLs) and #13953 (target="_blank" loads in place). The new-tab fix planned for #13953 covers http(s) tab dispositions, not this about:blank new-window case.
Impact#
Blocks work completely
Version or commit#
T3Code(Nightly)/0.0.44-nightly.20260929.2456 (Electron 44.4.2, Chrome 152.0.7977.130)
Environment#
Ubuntu 26.04.1 LTS, Linux 7.0.0-34-generic
Logs or stack traces#
[auth] loginPopup failed, trying loginRedirect BrowserAuthError: popup_window_error: Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser.
at createBrowserAuthError (...)
at PopupClient.openPopup (...)
at PopupClient.initiateAuthRequest (...)
Workaround#
Two app-side options:
- In the page, replace
window.openwith a stub that returnsnullwithout calling the native handler. The redirect fallback then works: we confirmed a full sign-in through Microsoft this way. - Detect
Electron/in the user agent and callloginRedirect()directly, without trying the popup.
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
juliusmarminge closed this
Sign in to join this conversation.
Triage#
Confirmed on
mainatc2fa9fc911, which ships the same Electron 44.4.2 as your nightly. This is a real desktop-preview bug. It isn't a duplicate of #13953 (open issue) or of the OAuth popup work in #6561 (closed issue) and #8435 (merged PR).What happens.
window.open("about:blank", …)with popup features arrives as anew-windowrequest, and its URL failsisPopupUrl, which only allowshttp:andhttps:.about:blankis left out on purpose: Chromium copies the guest'scontextIsolation: falsepreferences to it, and Electron won't let us override them (seeisPopupUrl/previewWindowOpenActioninapps/desktop/src/preview/Manager.ts). SopreviewWindowOpenActionreturns"navigate", and the preview'ssetWindowOpenHandlerdoes two things:wc.loadURL(details.url), which replaces the preview page withabout:blank{ action: "deny" }, sowindow.openreturnsnullMSAL's default
asyncPopups: falsepath relies on that synchronous blank popup. It throwspopup_window_error, andloginRedirect()then runs on a page that's already being replaced. ReadingsessionStorageon thatabout:blankpage throws theSecurityErroryou saw. The same handler also runs for an empty URL, which Electron sometimes reports instead ofabout:blank. Aforeground-tabdisposition would hit"navigate"too, so the features string isn't what matters here.Why the existing fixes don't cover it. #8435 fixed real
http(s)popups and intentionally left blank URLs on the in-tab path, but loadingabout:blankinto the opener never helps and destroys the page that would have handled a blocked popup. #13953 is about turningtarget="_blank"/window.openofhttp(s)URLs into new preview tabs, so its planned"new-tab"result doesn't touch thisabout:blanknew-windowcase either.Fix direction. Allowing a real
about:blankwindow isn't an option, because the context-isolation constraint still applies. Instead, blank URLs (""andabout:blank) should get a plain deny with noloadURL. Other non-popup schemes (javascript:,file:,vscode:) can keep their current in-tab behavior. The testdoes not hand a window to schemes that cannot be hardenedcurrently expects"navigate"for all of these and would need updating for the blank case.After that change,
window.open("about:blank")returnsnulland the preview page stays put, the same as with a normal popup blocker.loginPopup()will still fail, but your app'sloginRedirect()fallback can then run. Both of your workarounds (stubbingwindow.opento returnnull, or skipping the popup when the user agent containsElectron/) end up in that same place. Thanks for the precise root-cause write-up.