From 2d6b7e35b15d1088be86004fa4ade9d0f011d19a Mon Sep 17 00:00:00 2001 From: aparusel Date: Tue, 27 Jan 2026 22:42:10 +0100 Subject: [PATCH] fix(desktop): open external links in default browser Intercept external http(s) anchor clicks and delegate to the OS browser so the main app webview is never replaced by a navigated page. --- packages/desktop/src/index.tsx | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index b19adfeda5a..ddd63e71e43 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -3,7 +3,7 @@ import "./webview-zoom" import { render } from "solid-js/web" import { AppBaseProviders, AppInterface, PlatformProvider, Platform } from "@opencode-ai/app" import { open, save } from "@tauri-apps/plugin-dialog" -import { open as shellOpen } from "@tauri-apps/plugin-shell" +import { openUrl } from "@tauri-apps/plugin-opener" import { type as ostype } from "@tauri-apps/plugin-os" import { check, Update } from "@tauri-apps/plugin-updater" import { invoke } from "@tauri-apps/api/core" @@ -77,7 +77,7 @@ const createPlatform = (password: Accessor): Platform => ({ }, openLink(url: string) { - void shellOpen(url).catch(() => undefined) + void openUrl(url).catch(() => undefined) }, back() { @@ -337,11 +337,31 @@ render(() => { const platform = createPlatform(() => serverPassword()) function handleClick(e: MouseEvent) { - const link = (e.target as HTMLElement).closest("a.external-link") as HTMLAnchorElement | null - if (link?.href) { - e.preventDefault() - platform.openLink(link.href) - } + if (e.defaultPrevented) return + if (e.button !== 0) return + if (!(e.target instanceof Element)) return + + const link = e.target.closest("a[href]") + if (!(link instanceof HTMLAnchorElement)) return + + const href = link.getAttribute("href") + if (!href) return + + const url = (() => { + try { + return new URL(href, window.location.href) + } catch { + return + } + })() + if (!url) return + + const http = url.protocol === "http:" || url.protocol === "https:" + if (!http) return + if (url.origin === window.location.origin) return + + e.preventDefault() + platform.openLink(url.toString()) } onMount(() => {