Repository navigation
fix(desktop): same-origin window.open keeps window.opener #36291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,24 +484,44 @@ const POPUP_WINDOW_OPTIONS = { | |
| }, | ||
| } satisfies Electron.BrowserWindowConstructorOptions; | ||
|
|
||
| const isSameOriginHttpUrl = (left: string, right: string): boolean => { | ||
| const from = URL.parse(left); | ||
| const to = URL.parse(right); | ||
| return ( | ||
| from !== null && | ||
| to !== null && | ||
| (from.protocol === "http:" || from.protocol === "https:") && | ||
| from.origin === to.origin | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * OAuth needs a surviving popup opener. `blob:`, app links (behind the session's `openExternal` | ||
| * prompt) and form POSTs stay in place. | ||
| * OAuth needs a surviving popup opener. Same-origin `window.open` without features is a Chromium | ||
| * foreground-tab; opening it as a T3 tab via URL navigation drops `window.opener`. | ||
| * `blob:`, app links (behind the session's `openExternal` prompt) and form POSTs stay in place. | ||
| */ | ||
| export const previewWindowOpenAction = (details: { | ||
| readonly url: string; | ||
| readonly disposition: Electron.HandlerDetails["disposition"]; | ||
| readonly postBody?: Electron.PostBody; | ||
| }): "popup" | "new-tab" | "navigate" | "deny" => { | ||
| export const previewWindowOpenAction = ( | ||
| details: { | ||
| readonly url: string; | ||
| readonly disposition: Electron.HandlerDetails["disposition"]; | ||
| readonly postBody?: Electron.PostBody; | ||
| }, | ||
| openerUrl?: string, | ||
| ): "popup" | "new-tab" | "navigate" | "deny" => { | ||
| const protocol = URL.parse(details.url)?.protocol; | ||
| // MSAL redirects on a denied blank popup; navigating the tab would destroy that fallback. | ||
| if (protocol === undefined || IN_PLACE_DENIED_PROTOCOLS.has(protocol)) return "deny"; | ||
| if (!POPUP_PROTOCOLS.has(protocol)) return "navigate"; | ||
| if (details.disposition === "new-window") return "popup"; | ||
| return !details.postBody && | ||
| if ( | ||
| !details.postBody && | ||
| (details.disposition === "foreground-tab" || details.disposition === "background-tab") | ||
| ? "new-tab" | ||
| : "navigate"; | ||
| ) { | ||
| return openerUrl !== undefined && isSameOriginHttpUrl(details.url, openerUrl) | ||
| ? "popup" | ||
|
Comment on lines
+520
to
+521
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve follow-up window opens in newly promoted pages. If a same-origin tab request opens an application page, this branch now creates a native window. Electron then emits Provide bounded routing for follow-up requests instead of applying the blanket deny policy to every page promoted by this branch.
|
||
| : "new-tab"; | ||
| } | ||
| return "navigate"; | ||
| }; | ||
|
|
||
| const isPreviewRefreshShortcut = (input: Electron.Input, platform: NodeJS.Platform): boolean => | ||
|
|
@@ -1646,7 +1666,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function | |
| wc.ipc.on(PAGE_UNHANDLED_SHORTCUT_CHANNEL, pageUnhandledShortcut); | ||
| detachPasskeys = passkeys.attachGuest(wc); | ||
| wc.setWindowOpenHandler((details) => { | ||
| const action = previewWindowOpenAction(details); | ||
| const openerUrl = wc.isDestroyed() ? undefined : wc.getURL(); | ||
| const action = previewWindowOpenAction(details, openerUrl); | ||
| if (action === "popup") { | ||
| return { action: "allow", overrideBrowserWindowOptions: POPUP_WINDOW_OPTIONS }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
preview/Manager.ts:520Same-origin pages opened as
"popup"cannot open their own OAuth popups or_blanklinks:windowCreatedinstalls asetWindowOpenHandlerthat denies every subsequent open. Preserve opener support for OAuth while giving ordinary pages a tab-navigation fallback.🤖 Copy this AI Prompt to have your agent fix this: