Skip to content

The agent that grows with you

feat(desktop): open a Browser tab in the default browser from its context menu

Brooklyn Nicholson26777a417825
diff --git a/apps/desktop/src/app/chat/preview-tile.test.ts b/apps/desktop/src/app/chat/preview-tile.test.ts
index 637d71c9adc..51073def256 100644
--- a/apps/desktop/src/app/chat/preview-tile.test.ts
+++ b/apps/desktop/src/app/chat/preview-tile.test.ts
@@ -10,9 +10,9 @@ vi.mock('./right-rail/preview-console-store', () => ({
import { contributesToWorkspace } from '@/components/pane-shell/workspace-scope'
import { registry } from '@/contrib/registry'
-import { closeRightRail, openPreview } from '@/store/preview'
+import { $previewTabs, closeRightRail, noteBrowserPage, openPreview } from '@/store/preview'
-import { browserTabLabel, watchPreviewTiles } from './preview-tile'
+import { browserTabExternalUrl, browserTabLabel, watchPreviewTiles } from './preview-tile'
beforeAll(() => {
watchPreviewTiles()
@@ -72,6 +72,36 @@ describe('browserTabLabel', () => {
})
})
+describe('browserTabExternalUrl', () => {
+ const openBrowser = (url: string) => {
+ openPreview({ kind: 'url', label: 'Browser', source: url, url }, 'explicit-link')
+
+ return $previewTabs.get().find(tab => tab.target.kind === 'url')!.id
+ }
+
+ it('hands the live page to the OS browser, not the address the tab was opened with', () => {
+ const tabId = openBrowser('https://example.com')
+
+ noteBrowserPage(tabId, { title: 'Hacker News', url: 'https://news.ycombinator.com/' })
+
+ expect(browserTabExternalUrl(tabId)).toBe('https://news.ycombinator.com/')
+ })
+
+ it('falls back to the target when the tab has not reported a page yet', () => {
+ expect(browserTabExternalUrl(openBrowser('https://github.com/nous'))).toBe('https://github.com/nous')
+ })
+
+ it('refuses about:blank and other non-pages', () => {
+ expect(browserTabExternalUrl(openBrowser('about:blank'))).toBeNull()
+ })
+
+ it('is null for a file peek', () => {
+ openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
+
+ expect(browserTabExternalUrl('file:/tmp/a.ts')).toBeNull()
+ })
+})
+
type DockData = { dock?: { pane?: string; pos?: string } } | undefined
function dockOf(paneId: string) {
diff --git a/apps/desktop/src/app/chat/preview-tile.tsx b/apps/desktop/src/app/chat/preview-tile.tsx
index d0dd3fec2b4..32dc8d7db26 100644
--- a/apps/desktop/src/app/chat/preview-tile.tsx
+++ b/apps/desktop/src/app/chat/preview-tile.tsx
@@ -14,8 +14,11 @@ import { useStore } from '@nanostores/react'
import { findGroup } from '@/components/pane-shell/tree/model'
import { $activeTreeGroup, $layoutTree, revealTreePane, treePanesWithPrefix } from '@/components/pane-shell/tree/store'
+import { type MenuKit, renderActionItem } from '@/components/ui/actions-menu'
import { FileTypeIcon } from '@/components/ui/file-type-icon'
import { ToolIcon } from '@/components/ui/tool-icon'
+import { translateNow } from '@/i18n'
+import { openExternalLink } from '@/lib/external-link'
import { $rightRailActiveTabId, type RightRailTabId, selectRightRailTab } from '@/store/layout'
import {
$browserPages,
@@ -36,6 +39,40 @@ function targetFor(tabId: string): PreviewTarget | null {
return $previewTabs.get().find(tab => tab.id === tabId)?.target ?? null
}
+/** Schemes that are not a page the user's default browser can usefully open
+ * (blank vessel, Chromium internals, injected documents). */
+const NON_EXTERNAL_URL = /^(about|blob|chrome|data|devtools|javascript):/i
+
+/** The URL a Browser tab should hand to the OS browser — the page it is
+ * showing now, else the address it was opened with. Null when there isn't
+ * one (`about:blank`, a half-typed address, a file/artifact tab). */
+export function browserTabExternalUrl(tabId: string): null | string {
+ const target = targetFor(tabId)
+
+ if (target?.kind !== 'url') {
+ return null
+ }
+
+ const url = $browserPages.get()[tabId]?.url || target.url
+
+ return url && !NON_EXTERNAL_URL.test(url) ? url : null
+}
+
+function browserTabMenuPrefix(tabId: string) {
+ if (targetFor(tabId)?.kind !== 'url') {
+ return undefined
+ }
+
+ return (kit: MenuKit) =>
+ renderActionItem(kit, {
+ disabled: !browserTabExternalUrl(tabId),
+ icon: 'link-external',
+ key: 'open-external',
+ label: translateNow('preview.openInExternal'),
+ onSelect: () => openExternalLink(browserTabExternalUrl(tabId) ?? '')
+ })
+}
+
/** Tab title. A URL tab is titled by the CONTRIBUTION as the surface — see
* `BrowserTabLabel` for the live page name the strip actually renders — so
* navigating doesn't re-register the pane on every hop. A file names the
@@ -207,6 +244,7 @@ const watchPreviewTileMirror = paneMirror<{ id: string }>({
// A Browser is a vessel, so there can be more of it — a file peek is one of
// a kind and leaves the strip's "+" to whatever else the zone holds.
newTab: tabId => (targetFor(tabId)?.kind === 'url' ? newBrowserTab : undefined),
+ tabMenuPrefix: browserTabMenuPrefix,
render: tabId => <PreviewTilePane tabId={tabId} />,
close: tabId => {
forgetBrowserPage(tabId)
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 293771af119..8236d26aea4 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -2327,6 +2327,7 @@ export const ar = defineLocale({
hide: 'إخفاء',
openPreview: 'فتح المعاينة',
openInBrowser: 'فتح في المتصفح',
+ openInExternal: 'فتح في الخارج',
linkHint: '⌘/Ctrl-نقر لجزء المعاينة',
sourceLineTitle: 'انقر للتحديد · shift-نقر للتوسيع · اسحب إلى المُنشئ',
source: 'المصدر',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index cedad3862df..b0c21591143 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2970,6 +2970,7 @@ export const en: Translations = {
hide: 'Hide',
openPreview: 'Open preview',
openInBrowser: 'Open in browser',
+ openInExternal: 'Open in external',
linkHint: '⌘/Ctrl-click for preview pane',
sourceLineTitle: 'Click to select · shift-click to extend · drag to composer',
source: 'SOURCE',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 96bb9b746b9..896c755792c 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2624,6 +2624,7 @@ export const ja = defineLocale({
hide: '非表示',
openPreview: 'プレビューを開く',
openInBrowser: 'ブラウザで開く',
+ openInExternal: '外部で開く',
linkHint: '⌘/Ctrl+クリックでプレビューペイン',
sourceLineTitle: 'クリックして選択 · Shift クリックで拡張 · コンポーザーにドラッグ',
source: 'ソース',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 217367cec57..c5f3eff99f0 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2535,6 +2535,7 @@ export interface Translations {
hide: string
openPreview: string
openInBrowser: string
+ openInExternal: string
linkHint: string
sourceLineTitle: string
source: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index c191f002c20..e850dd80154 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2535,6 +2535,7 @@ export const zhHant = defineLocale({
hide: '隱藏',
openPreview: '開啟預覽',
openInBrowser: '在瀏覽器中開啟',
+ openInExternal: '在外部開啟',
linkHint: '⌘/Ctrl+點擊在預覽窗格開啟',
sourceLineTitle: '點擊選取 · shift 點擊擴展 · 拖曳至輸入框',
source: '原始碼',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 0c1fbbc94a1..0c4c3fd8882 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3134,6 +3134,7 @@ export const zh: Translations = {
hide: '隐藏',
openPreview: '打开预览',
openInBrowser: '在浏览器中打开',
+ openInExternal: '在外部打开',
linkHint: '⌘/Ctrl+点击在预览面板打开',
sourceLineTitle: '点击选择 · shift 点击扩展 · 拖到输入框',
source: '源码',