Skip to content

The agent that grows with you

fix(desktop): open HUD links in the system browser

Brooklyn Nicholson178c23fb27c3
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx b/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
index fd81a310fc6..2e8a97b9bfb 100644
--- a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
+++ b/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
@@ -118,6 +118,28 @@ describe('AppContextMenu', () => {
await waitFor(() => expect($previewTabs.get().at(-1)?.target.url).toBe('https://example.com/docs'))
})
+ it('skips Open in in-app browser on the HUD — that window has no browser pane', async () => {
+ const originalLocation = window.location
+
+ Object.defineProperty(window, 'location', {
+ configurable: true,
+ value: { ...originalLocation, search: '?win=hud' }
+ })
+
+ try {
+ installBridge()
+ mountMenu()
+ const host = attach('<a href="https://accounts.google.com/o/oauth2/auth">Sign in</a>')
+
+ fireEvent.contextMenu(host.querySelector('a')!)
+
+ expect(await screen.findByText('Open in external browser')).toBeTruthy()
+ expect(screen.queryByText('Open in in-app browser')).toBeNull()
+ } finally {
+ Object.defineProperty(window, 'location', { configurable: true, value: originalLocation })
+ }
+ })
+
it('offers the resolved copy only for loopback links on a remote gateway', async () => {
$connection.set({ mode: 'remote' } as never)
const reachPreviewUrl = vi.fn(async () => 'http://127.0.0.1:45173/')
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.tsx b/apps/desktop/src/app/context-menu/app-context-menu.tsx
index e6e25a9b501..b49397e283f 100644
--- a/apps/desktop/src/app/context-menu/app-context-menu.tsx
+++ b/apps/desktop/src/app/context-menu/app-context-menu.tsx
@@ -17,7 +17,7 @@ import {
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { type Translations, useI18n } from '@/i18n'
-import { hostPathLabel, normalizeExternalUrl, openExternalLink } from '@/lib/external-link'
+import { hostPathLabel, hudForcesNativeLinks, normalizeExternalUrl, openExternalLink } from '@/lib/external-link'
import { formatCombo } from '@/lib/keybinds/combo'
import { isRemoteGateway } from '@/lib/media'
import { reachablePreviewUrl } from '@/lib/preview-reach'
@@ -137,6 +137,7 @@ function domSections(open: Extract<OpenContextMenu, { kind: 'dom' }>, t: Transla
const linkUrl = target.linkUrl ? normalizeExternalUrl(target.linkUrl) : ''
const linkIsWeb = isWebUrl(linkUrl)
const imageIsWeb = isWebUrl(target.imageUrl)
+ const openInApp = !hudForcesNativeLinks()
const showResolvedCopy = linkIsWeb && isRemoteGateway() && isLoopbackUrl(linkUrl)
// The edit verbs and spell-check actions act on the sender's FOCUSED
@@ -194,7 +195,7 @@ function domSections(open: Extract<OpenContextMenu, { kind: 'dom' }>, t: Transla
if (linkUrl) {
sections.push(
[
- linkIsWeb ? (
+ linkIsWeb && openInApp ? (
<Item
icon="globe"
key="link-open-app"
@@ -234,7 +235,7 @@ function domSections(open: Extract<OpenContextMenu, { kind: 'dom' }>, t: Transla
if (target.onImage) {
sections.push(
[
- imageIsWeb ? (
+ imageIsWeb && openInApp ? (
<Item
icon="globe"
key="image-open-app"
@@ -382,6 +383,7 @@ function guestSections(open: Extract<OpenContextMenu, { kind: 'guest' }>, t: Tra
const sections: ReactNode[][] = []
const linkUrl = params.linkURL
const imageUrl = params.srcURL
+ const openInApp = !hudForcesNativeLinks()
// Same trap-timing rule as the dom side: dispatch AFTER the menu closes,
// so the webview's focus() is not stolen back by the radix content.
@@ -393,7 +395,7 @@ function guestSections(open: Extract<OpenContextMenu, { kind: 'guest' }>, t: Tra
if (linkUrl) {
sections.push(
[
- isWebUrl(linkUrl) ? (
+ isWebUrl(linkUrl) && openInApp ? (
<Item
icon="globe"
key="guest-link-open-app"
diff --git a/apps/desktop/src/app/contrib/controller.tsx b/apps/desktop/src/app/contrib/controller.tsx
index 8c19c58eccf..5c626d91b4e 100644
--- a/apps/desktop/src/app/contrib/controller.tsx
+++ b/apps/desktop/src/app/contrib/controller.tsx
@@ -451,10 +451,11 @@ discoverBundledPlugins()
watchContributedPanes()
// Session + route (page) tiles: persisted splits register panes docked beside
-// main. A popped-out Browser has no layout tree — registering tiles there
-// would still run, and preview-tile watching would try to dock into a tree
-// this window never renders.
-if (!isBrowserWindow()) {
+// main. A popped-out Browser and the HUD have no layout tree — registering
+// tiles there would still run, and preview-tile watching would try to dock
+// into a tree this window never renders (and, in the HUD, paint a webview
+// into the transparent overlay).
+if (!isBrowserWindow() && !isHudWindow()) {
watchSessionTiles()
watchRouteTiles()
watchPreviewTiles()
@@ -819,6 +820,7 @@ export function ContribController() {
if (isHudWindow()) {
return (
<ContribWiring>
+ <AppContextMenu />
<HudShell />
</ContribWiring>
)
diff --git a/apps/desktop/src/lib/external-link.test.tsx b/apps/desktop/src/lib/external-link.test.tsx
index 653769c4a62..4b4eb25e18d 100644
--- a/apps/desktop/src/lib/external-link.test.tsx
+++ b/apps/desktop/src/lib/external-link.test.tsx
@@ -9,6 +9,7 @@ import {
ExternalLink,
fetchLinkTitle,
hostPathLabel,
+ hudForcesNativeLinks,
isTitleFetchable,
LinkifiedText,
MarkdownLinkText,
@@ -135,6 +136,39 @@ describe('external link helpers', () => {
expect($previewTabs.get()).toHaveLength(0)
})
+ it('treats only the HUD renderer as a native-link surface', () => {
+ expect(hudForcesNativeLinks('')).toBe(false)
+ expect(hudForcesNativeLinks('?win=secondary')).toBe(false)
+ expect(hudForcesNativeLinks('?win=browser&tab=1')).toBe(false)
+ expect(hudForcesNativeLinks('?win=hud')).toBe(true)
+ expect(hudForcesNativeLinks('?profile=work&win=hud')).toBe(true)
+ })
+
+ // The HUD has no in-app browser. A click that opened a preview tile would
+ // try to paint a webview into the transparent overlay (OAuth, consoles).
+ it('sends every HUD web link to the OS browser', () => {
+ const originalLocation = window.location
+
+ Object.defineProperty(window, 'location', {
+ configurable: true,
+ value: { ...originalLocation, search: '?win=hud' }
+ })
+
+ try {
+ const openExternal = vi.fn().mockResolvedValue(undefined)
+ installDesktopBridge({ openExternal: openExternal as unknown as Window['hermesDesktop']['openExternal'] })
+
+ render(<ExternalLink href="https://accounts.google.com/o/oauth2/auth">Sign in</ExternalLink>)
+
+ fireEvent.click(screen.getByRole('link', { name: 'Sign in' }))
+
+ expect(openExternal).toHaveBeenCalledWith('https://accounts.google.com/o/oauth2/auth')
+ expect($previewTabs.get()).toHaveLength(0)
+ } finally {
+ Object.defineProperty(window, 'location', { configurable: true, value: originalLocation })
+ }
+ })
+
// A setup step sends you to a console you are signed into in your own
// browser, to fill in a form and copy a secret back. The in-app pane has
// none of that session and is the wrong destination even for web URLs.
diff --git a/apps/desktop/src/lib/external-link.tsx b/apps/desktop/src/lib/external-link.tsx
index 0af32238ecc..b55b0258d69 100644
--- a/apps/desktop/src/lib/external-link.tsx
+++ b/apps/desktop/src/lib/external-link.tsx
@@ -211,6 +211,21 @@ export function wantsNativeBrowser(event: Pick<MouseEvent, 'button' | 'ctrlKey'
return event.button === 1 || (IS_MAC ? event.metaKey : event.ctrlKey)
}
+/**
+ * The HUD is a chrome-free bar with no in-app browser. A preview tile there
+ * either no-ops or tries to paint a webview into the transparent overlay —
+ * the OAuth-in-the-HUD case. Always hand off to the OS browser.
+ */
+export function hudForcesNativeLinks(
+ search = typeof window === 'undefined' ? '' : window.location.search
+): boolean {
+ try {
+ return new URLSearchParams(search).get('win') === 'hud'
+ } catch {
+ return false
+ }
+}
+
/**
* Where a link the user clicked should open.
*
@@ -220,7 +235,8 @@ export function wantsNativeBrowser(event: Pick<MouseEvent, 'button' | 'ctrlKey'
* where you go for anything needing your logged-in session or a password.
*
* Everything that ISN'T a web page — `mailto:`, `file:`, a custom scheme — has
- * no business in the webview and always hands off to the OS.
+ * no business in the webview and always hands off to the OS. The HUD has no
+ * browser pane, so it always takes the OS path.
*/
export function openLink(href: string, options: { native?: boolean } = {}): void {
const target = normalizeExternalUrl(href)
@@ -229,7 +245,11 @@ export function openLink(href: string, options: { native?: boolean } = {}): void
return
}
- if (options.native || !/^https?:$/i.test(parseUrl(target)?.protocol ?? '')) {
+ if (
+ options.native ||
+ hudForcesNativeLinks() ||
+ !/^https?:$/i.test(parseUrl(target)?.protocol ?? '')
+ ) {
openExternalLink(target)
return