Skip to content

fix: honour trapLinkClicks for bare window.open() OAuth popups - #2573

Open
thejdubb02 wants to merge 1 commit into
ferdium:developfrom
thejdubb02:fix/trap-link-clicks-oauth-popups
Open

thejdubb02 wants to merge 1 commit into
ferdium:developfrom
thejdubb02:fix/trap-link-clicks-oauth-popups

Conversation

@thejdubb02

Copy link
Copy Markdown

Fixes #2538.

"Open URLs within Ferdium" (Service.trapLinkClicks) is declared and persisted but was never read anywhere in the app. A window.open(url) call with no target name or window features, which is how the Gmail and Google Voice sign-in popups (and others) open, went through windowOpenShim's bare url branch straight to the default browser regardless of the setting, so sign-in completed in a window Ferdium can never see the session from.

windowOpenShim.ts now asks window.ferdium.shouldTrapLinkClicks() in that branch and, when true, routes the call through the same real window path already used when the page asks for window features, by synthesizing a popup=yes features string. That existing path is what index.ts's setWindowOpenHandler already allows as a popup on the service's own session and preserves window.opener for the OAuth postMessage callback, so this reuses it instead of adding a new mechanism.

shouldTrapLinkClicks is exposed on the existing window.ferdium contextBridge object in recipe.ts and reads live off the single RecipeController instance's settings.service.trapLinkClicks, so it stays correct on both the initial load (loadRecipeModule) and a live settings change (updateServiceSettings) without a second, separately synced copy of the flag. An earlier version of this fix kept a duplicate copy that only synced on updateServiceSettings and missed the initial load and reload cases, which is exactly the repro in the issue, so I removed that and read the setting directly.

Added regression tests to test/webview/windowOpenShim.test.ts covering the new branch, confirmed they fail on the old code and pass with the fix. Ran the full existing suite (144 tests, 2 pre-existing skips unrelated to this change), pnpm typecheck, and pnpm lint (zero warnings) against src/webview/windowOpenShim.ts, src/webview/recipe.ts, and the test file, all clean. Also ran pnpm biome:check against the same three files.

Scope note: this fixes the window.open() based popup case from the issue, which covers the Gmail and Google Voice OAuth reports. A target=_blank link still takes the separate foreground-tab disposition path in index.ts's setWindowOpenHandler and still opens externally regardless of this setting. I left that alone since it is a different code path with different tradeoffs and wasn't part of the reported repro, but flagging it here in case a maintainer wants it folded into the same setting later.

"Open URLs within Ferdium" (Service#trapLinkClicks) was declared and
persisted but never read anywhere. A window.open(url) call with no
target name or window features, which is how Gmail, Google Voice and
other OAuth sign-in flows open their popup, went through
windowOpenShim's bare-url branch straight to the default browser
regardless of the setting, so the sign-in completed in a window
Ferdium can never see the session from.

windowOpenShim.ts now asks window.ferdium.shouldTrapLinkClicks() for
that branch and, when true, routes the call through the same
real-window path already used when the page asks for window features,
by synthesizing a 'popup=yes' features string. That existing path is
what index.ts's setWindowOpenHandler already allows as a popup on the
service's own session and preserves window.opener for the OAuth
postMessage callback, so this reuses it instead of adding a new one.

shouldTrapLinkClicks is exposed on the existing window.ferdium
contextBridge object in recipe.ts and reads live off the single
RecipeController instance's settings.service.trapLinkClicks, so it is
correct on both the initial load (loadRecipeModule) and a live
settings change (updateServiceSettings) without keeping a second
synced copy of the flag.

Fixes ferdium#2538.
@thejdubb02

Copy link
Copy Markdown
Author

Hi, friendly ping on this one. It is a small fix for OAuth popups that open via a bare window.open(), and it applies cleanly to current nightly. Happy to adjust anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Open URLs within Ferdium" (trapLinkClicks) is never read - OAuth sign-ins open in the system browser

1 participant