Skip to content

The agent that grows with you

feat(desktop): hide the docked Browser tab while it is popped out

Brooklyn Nicholsone8df4017386e
diff --git a/apps/desktop/src/app/chat/browser-popout-shell.tsx b/apps/desktop/src/app/chat/browser-popout-shell.tsx
new file mode 100644
index 00000000000..e14ed3290dc
--- /dev/null
+++ b/apps/desktop/src/app/chat/browser-popout-shell.tsx
@@ -0,0 +1,50 @@
+import type { CSSProperties } from 'react'
+
+import { PanelEmpty } from '@/app/overlays/panel'
+import { TITLEBAR_HEIGHT } from '@/app/shell/titlebar'
+import { useI18n } from '@/i18n'
+import { windowBrowserTabId } from '@/store/windows'
+
+import { PreviewTilePane } from './right-rail/preview'
+
+/**
+ * Dedicated shell for `?win=browser`: the in-app Browser, full-window, no
+ * session sidebar or layout tree. Same webview + address bar the docked tab
+ * uses — just in its own OS window.
+ */
+export function BrowserPopoutShell() {
+ const { t } = useI18n()
+ const tabId = windowBrowserTabId()
+
+ return (
+ <div
+ className="flex h-screen min-h-0 w-screen flex-col bg-(--ui-bg-chrome) text-(--ui-text-primary)"
+ data-contrib-shell=""
+ style={{ '--titlebar-height': `${TITLEBAR_HEIGHT}px` } as CSSProperties}
+ >
+ <div
+ aria-hidden="true"
+ className="relative shrink-0 bg-(--ui-bg-chrome)"
+ style={{ height: TITLEBAR_HEIGHT }}
+ >
+ {/* Same traffic-light / native-overlay carve-out as the main titlebar:
+ a full-bar drag region would eat the window buttons. */}
+ <div
+ className="pointer-events-none absolute inset-y-0 left-0 w-(--titlebar-controls-left,14px) [-webkit-app-region:drag]"
+ />
+ <div
+ className="pointer-events-none absolute inset-y-0 left-[calc(var(--titlebar-controls-left,14px)+(var(--titlebar-control-size,24px)*2)+0.75rem)] right-[calc(var(--titlebar-tools-right,0.75rem)+0.75rem)] [-webkit-app-region:drag]"
+ />
+ </div>
+ <div className="relative min-h-0 min-w-0 flex-1 overflow-hidden">
+ {tabId ? (
+ <PreviewTilePane tabId={tabId} />
+ ) : (
+ <div className="grid h-full place-items-center">
+ <PanelEmpty description={t.preview.web.blankPageBody} icon="globe" />
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}
diff --git a/apps/desktop/src/app/chat/preview-tile.tsx b/apps/desktop/src/app/chat/preview-tile.tsx
index 32dc8d7db26..7777cf954c7 100644
--- a/apps/desktop/src/app/chat/preview-tile.tsx
+++ b/apps/desktop/src/app/chat/preview-tile.tsx
@@ -22,13 +22,18 @@ import { openExternalLink } from '@/lib/external-link'
import { $rightRailActiveTabId, type RightRailTabId, selectRightRailTab } from '@/store/layout'
import {
$browserPages,
+ $dockedPreviewTabs,
$previewTabs,
+ adoptPersistedBrowserTab,
type BrowserPage,
closeRightRailTab,
forgetBrowserPage,
+ markBrowserTabPopped,
newBrowserTab,
+ popOutBrowserTab,
type PreviewTarget
} from '@/store/preview'
+import { canOpenBrowserWindow } from '@/store/windows'
import { paneMirror } from './pane-mirror'
import { PreviewTilePane } from './right-rail/preview'
@@ -63,14 +68,25 @@ function browserTabMenuPrefix(tabId: string) {
return undefined
}
- return (kit: MenuKit) =>
- renderActionItem(kit, {
- disabled: !browserTabExternalUrl(tabId),
- icon: 'link-external',
- key: 'open-external',
- label: translateNow('preview.openInExternal'),
- onSelect: () => openExternalLink(browserTabExternalUrl(tabId) ?? '')
- })
+ return (kit: MenuKit) => (
+ <>
+ {canOpenBrowserWindow()
+ ? renderActionItem(kit, {
+ icon: 'empty-window',
+ key: 'pop-out',
+ label: translateNow('preview.popOut'),
+ onSelect: () => popOutBrowserTab(tabId)
+ })
+ : null}
+ {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
@@ -169,7 +185,7 @@ function existingPreviewAnchor(tabId: string): string | undefined {
return inTree
}
- const other = $previewTabs.get().find(tab => tab.id !== tabId)
+ const other = $dockedPreviewTabs.get().find(tab => tab.id !== tabId)
return other ? previewPaneId(other.id) : undefined
}
@@ -180,6 +196,11 @@ function existingPreviewAnchor(tabId: string): string | undefined {
export function watchPreviewTiles(): void {
watchPreviewTileMirror()
+ window.hermesDesktop?.onBrowserPopoutClosed?.(tabId => {
+ adoptPersistedBrowserTab(tabId)
+ markBrowserTabPopped(tabId, false)
+ })
+
// The reveal analog of session tiles (session-states calls revealTreePane on
// open): `openPreview` selects the tab, and the TREE must front its pane —
// un-minimize, un-hide, activate in its zone. Both stores, because re-opening
@@ -223,7 +244,7 @@ export function watchPreviewTiles(): void {
}
const watchPreviewTileMirror = paneMirror<{ id: string }>({
- source: $previewTabs,
+ source: $dockedPreviewTabs,
// Unscoped on purpose. `$previewTabs` is one global Browser/file surface —
// clicking a link in a bot chat must open the same pane Sessions already
// shows. Scoping this to `sessions` filtered the pane out of Bot Mode, so
diff --git a/apps/desktop/src/app/chat/right-rail/preview-browser-bar.test.tsx b/apps/desktop/src/app/chat/right-rail/preview-browser-bar.test.tsx
index 3390690d596..135c2b13267 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-browser-bar.test.tsx
+++ b/apps/desktop/src/app/chat/right-rail/preview-browser-bar.test.tsx
@@ -12,7 +12,7 @@ const baseProps = {
onBack: vi.fn(),
onForward: vi.fn(),
onNavigate: vi.fn(),
- onOpenExternal: vi.fn(),
+ onPopOut: vi.fn(),
onReload: vi.fn(),
onToggleConsole: vi.fn(),
onToggleDevTools: vi.fn(),
@@ -86,7 +86,7 @@ describe('PreviewBrowserBar', () => {
expect(rendered.getByRole('button', { name: 'Forward' })).toBeTruthy()
expect(rendered.getByRole('button', { name: 'Reload page' })).toBeTruthy()
expect(rendered.getByRole('button', { name: 'Copy URL' })).toBeTruthy()
- expect(rendered.getByRole('button', { name: 'Open in browser' })).toBeTruthy()
+ expect(rendered.getByRole('button', { name: 'Pop out' })).toBeTruthy()
expect(rendered.getByRole('button', { name: 'Show preview console' })).toBeTruthy()
expect(rendered.getByRole('button', { name: 'Open preview DevTools' })).toBeTruthy()
expect(address(rendered)).toBeTruthy()
@@ -110,7 +110,7 @@ describe('PreviewBrowserBar', () => {
['Back', 'onBack'],
['Forward', 'onForward'],
['Reload page', 'onReload'],
- ['Open in browser', 'onOpenExternal']
+ ['Pop out', 'onPopOut']
] as const)('fires %s', (label, handler) => {
const spy = vi.fn()
const rendered = render(<PreviewBrowserBar {...baseProps} canGoBack canGoForward {...{ [handler]: spy }} />)
@@ -317,4 +317,38 @@ describe('PreviewBrowserBar', () => {
expect(copyButton.parentElement?.contains(address)).toBe(true)
expect(copyButton.className).toContain('absolute')
})
+
+ it('shows Open in browser when only the external handler is provided', () => {
+ const onOpenExternal = vi.fn()
+ const rendered = render(
+ <PreviewBrowserBar {...baseProps} onOpenExternal={onOpenExternal} onPopOut={undefined} />
+ )
+
+ expect(rendered.getByRole('button', { name: 'Open in browser' })).toBeTruthy()
+ expect(rendered.queryByRole('button', { name: 'Pop out' })).toBeNull()
+
+ fireEvent.click(rendered.getByRole('button', { name: 'Open in browser' }))
+
+ expect(onOpenExternal).toHaveBeenCalledOnce()
+ })
+
+ it('prefers pop-out over open-in-browser when both handlers are provided', () => {
+ const rendered = render(<PreviewBrowserBar {...baseProps} onOpenExternal={vi.fn()} />)
+
+ expect(rendered.getByRole('button', { name: 'Pop out' })).toBeTruthy()
+ expect(rendered.queryByRole('button', { name: 'Open in browser' })).toBeNull()
+ })
+
+ it('shows Pop in when the window is already popped out', () => {
+ const onPopIn = vi.fn()
+ const rendered = render(<PreviewBrowserBar {...baseProps} onPopIn={onPopIn} onPopOut={undefined} />)
+
+ expect(rendered.getByRole('button', { name: 'Pop in' })).toBeTruthy()
+ expect(rendered.queryByRole('button', { name: 'Pop out' })).toBeNull()
+ expect(rendered.queryByRole('button', { name: 'Open in browser' })).toBeNull()
+
+ fireEvent.click(rendered.getByRole('button', { name: 'Pop in' }))
+
+ expect(onPopIn).toHaveBeenCalledOnce()
+ })
})
diff --git a/apps/desktop/src/app/chat/right-rail/preview-browser-bar.tsx b/apps/desktop/src/app/chat/right-rail/preview-browser-bar.tsx
index 00561183389..ec7b87f0d00 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-browser-bar.tsx
+++ b/apps/desktop/src/app/chat/right-rail/preview-browser-bar.tsx
@@ -1,6 +1,6 @@
/**
- * BROWSER BAR: back / forward / reload / address / open-in-browser for a URL
- * preview.
+ * BROWSER BAR: back / forward / reload / address / pop-out (or pop-in) for a
+ * URL preview.
*
* The Browser tab had no way to move: no history, and the only address on
* screen was a read-only label. Every other embedded browser (VS Code's Simple
@@ -32,7 +32,9 @@ interface PreviewBrowserBarProps {
onBack: () => void
onForward: () => void
onNavigate: (url: string) => void
- onOpenExternal: () => void
+ onOpenExternal?: () => void
+ onPopIn?: () => void
+ onPopOut?: () => void
onReload: () => void
onToggleConsole: () => void
onToggleDevTools: () => void
@@ -96,6 +98,8 @@ export function PreviewBrowserBar({
onForward,
onNavigate,
onOpenExternal,
+ onPopIn,
+ onPopOut,
onReload,
onToggleConsole,
onToggleDevTools,
@@ -202,11 +206,25 @@ export function PreviewBrowserBar({
text={url}
/>
</div>
- <PaneStripGlyph
- icon={<Codicon name="link-external" size="0.8125rem" />}
- label={t.preview.openInBrowser}
- onSelect={onOpenExternal}
- />
+ {onPopIn ? (
+ <PaneStripGlyph
+ icon={<Codicon name="screen-normal" size="0.8125rem" />}
+ label={t.preview.popIn}
+ onSelect={onPopIn}
+ />
+ ) : onPopOut ? (
+ <PaneStripGlyph
+ icon={<Codicon name="empty-window" size="0.8125rem" />}
+ label={t.preview.popOut}
+ onSelect={onPopOut}
+ />
+ ) : onOpenExternal ? (
+ <PaneStripGlyph
+ icon={<Codicon name="link-external" size="0.8125rem" />}
+ label={t.preview.openInBrowser}
+ onSelect={onOpenExternal}
+ />
+ ) : null}
<PaneStripGlyph
active={consoleOpen}
icon={<Codicon name="terminal" size="0.8125rem" />}
diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
index 31def253333..cfbfc8beb61 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx
@@ -18,7 +18,16 @@ import { reachablePreviewUrl } from '@/lib/preview-reach'
import { rafCoalesce } from '@/lib/raf-coalesce'
import { cn } from '@/lib/utils'
import { notify, notifyError } from '@/store/notifications'
-import { $previewServerRestart, failPreviewServerRestart, noteBrowserPage, type PreviewTarget } from '@/store/preview'
+import {
+ $browserPages,
+ $previewServerRestart,
+ commitBrowserTabLocation,
+ failPreviewServerRestart,
+ noteBrowserPage,
+ popOutBrowserTab,
+ type PreviewTarget
+} from '@/store/preview'
+import { canOpenBrowserWindow, isBrowserWindow } from '@/store/windows'
import { ArtifactPreview } from './preview-artifact'
import { PreviewBrowserBar } from './preview-browser-bar'
@@ -61,6 +70,20 @@ type PreviewWebview = HTMLElement & {
sendInputEvent?: (event: PreviewInputEvent) => void
}
+/** Electron throws if getURL/getTitle run before attach + dom-ready, or after
+ * the guest has been removed. Optional chaining does not help — the method
+ * exists, it just refuses. */
+function guestPage(webview: PreviewWebview | null | undefined, fallbackUrl = ''): { title: string; url: string } {
+ try {
+ return {
+ title: webview?.getTitle?.() ?? '',
+ url: webview?.getURL?.() || fallbackUrl
+ }
+ } catch {
+ return { title: '', url: fallbackUrl }
+ }
+}
+
/** The raw Chromium params riding the webview tag's `context-menu` event. */
interface GuestContextMenuParams {
dictionarySuggestions?: string[]
@@ -213,6 +236,8 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
const consoleHeight = useStore(consoleState.$height)
const consoleOpen = useStore(consoleState.$open)
const [currentUrl, setCurrentUrl] = useState(target.url)
+ const liveUrlRef = useRef(currentUrl)
+ liveUrlRef.current = currentUrl
const [devtoolsOpen, setDevtoolsOpen] = useState(false)
const [history, setHistory] = useState({ back: false, forward: false })
const [loading, setLoading] = useState(true)
@@ -228,6 +253,27 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
const isRemoteHtmlTarget =
target.kind === 'file' && target.previewKind === 'html' && Boolean(target.dataUrl || target.transient)
+ // Hand the live address to storage when this guest is about to go away
+ // (pop-out, dock-back, tab close). The other renderer builds from
+ // `target.url`; without this it would reopen the tab's original page.
+ useEffect(() => {
+ if (target.kind !== 'url' || !tabId) {
+ return
+ }
+
+ const persist = () => {
+ const page = $browserPages.get()[tabId]
+ commitBrowserTabLocation(tabId, page?.url || liveUrlRef.current, page?.title)
+ }
+
+ window.addEventListener('pagehide', persist)
+
+ return () => {
+ window.removeEventListener('pagehide', persist)
+ persist()
+ }
+ }, [tabId, target.kind])
+
const isRemoteHtml = isRemoteHtmlTarget && target.renderMode !== 'source' && Boolean(target.dataUrl)
const remoteHtmlDocument = useMemo(
@@ -459,8 +505,7 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
return {
text: typeof text === 'string' ? text : '',
- title: webview.getTitle?.() ?? '',
- url: webview.getURL?.() ?? ''
+ ...guestPage(webview)
}
})
}, [isWebPreview, tabId])
@@ -741,14 +786,19 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
if ((detail.level ?? 0) >= 3 && isModuleMimeError(message)) {
setLoadError({
description: copy.moduleMimeDescription,
- url: webview.getURL?.() || target.url
+ url: guestPage(webview, target.url).url
})
setLoading(false)
}
}
- const syncHistory = () =>
- setHistory({ back: webview.canGoBack?.() ?? false, forward: webview.canGoForward?.() ?? false })
+ const syncHistory = () => {
+ try {
+ setHistory({ back: webview.canGoBack?.() ?? false, forward: webview.canGoForward?.() ?? false })
+ } catch {
+ // Same attach / dom-ready rule as getURL.
+ }
+ }
// Tell the strip what this Browser is showing, so its tab renames itself
// like a tab anywhere else. Deliberately NOT written back into the tab's
@@ -759,7 +809,7 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
return
}
- noteBrowserPage(tabId, { title: webview.getTitle?.() ?? '', url: webview.getURL?.() || target.url })
+ noteBrowserPage(tabId, guestPage(webview, target.url))
}
const onNavigate = (event: Event) => {
@@ -799,7 +849,7 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
setLoadError({
code: errorCode,
description: detail.errorDescription || copy.unreachableDescription,
- url: detail.validatedURL || webview.getURL?.() || target.url
+ url: detail.validatedURL || guestPage(webview, target.url).url
})
setLoading(false)
}
@@ -981,7 +1031,15 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =
onBack={goBack}
onForward={goForward}
onNavigate={navigateTo}
- onOpenExternal={() => void window.hermesDesktop?.openExternal(currentUrl)}
+ onOpenExternal={
+ !isBrowserWindow() && !canOpenBrowserWindow()
+ ? () => void window.hermesDesktop?.openExternal(currentUrl)
+ : undefined
+ }
+ onPopIn={isBrowserWindow() ? () => window.close() : undefined}
+ onPopOut={
+ isBrowserWindow() || !tabId || !canOpenBrowserWindow() ? undefined : () => popOutBrowserTab(tabId)
+ }
onReload={reloadPreview}
onToggleConsole={() => consoleState.setOpen(open => !open)}
onToggleDevTools={toggleDevTools}
diff --git a/apps/desktop/src/app/contrib/controller.tsx b/apps/desktop/src/app/contrib/controller.tsx
index 2fe447b0780..30fd949c5ea 100644
--- a/apps/desktop/src/app/contrib/controller.tsx
+++ b/apps/desktop/src/app/contrib/controller.tsx
@@ -72,8 +72,9 @@ import { $currentCwd, $selectedStoredSessionId, $sessions, $yoloActive, sessionM
import { watchSessionPins } from '@/store/session-pin-sync'
import { watchUnreadWriteGuard } from '@/store/session-unread-remote'
import { $statusbarVisible } from '@/store/statusbar-prefs'
-import { isHudWindow } from '@/store/windows'
+import { isBrowserWindow, isHudWindow } from '@/store/windows'
+import { BrowserPopoutShell } from '../chat/browser-popout-shell'
import type { SessionDragPayload } from '../chat/composer/inline-refs'
import { watchPreviewTiles } from '../chat/preview-tile'
import { watchRouteTiles } from '../chat/route-tile'
@@ -451,10 +452,14 @@ discoverBundledPlugins()
watchContributedPanes()
// Session + route (page) tiles: persisted splits register panes docked beside
-// main.
-watchSessionTiles()
-watchRouteTiles()
-watchPreviewTiles()
+// 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()) {
+ watchSessionTiles()
+ watchRouteTiles()
+ watchPreviewTiles()
+}
// Composer pop-out state is keyed by layout zone, so drop entries for zones the
// user has since closed or merged away — otherwise a long-lived install keeps a
@@ -821,6 +826,14 @@ export function ContribController() {
)
}
+ if (isBrowserWindow()) {
+ return (
+ <ContribWiring>
+ <BrowserPopoutShell />
+ </ContribWiring>
+ )
+ }
+
return (
<SidebarProvider
className="h-screen min-h-0 flex-col bg-background"
diff --git a/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts b/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
index f44e96017b1..9cd069c2538 100644
--- a/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
@@ -25,7 +25,7 @@ import {
} from '@/store/session'
import { onSessionsChanged } from '@/store/session-sync'
import { openUpdatesWindow, startUpdatePoller, stopUpdatePoller } from '@/store/updates'
-import { isHudWindow, isSecondaryWindow } from '@/store/windows'
+import { isBrowserWindow, isHudWindow, isSecondaryWindow } from '@/store/windows'
import type { SessionInfo } from '@/types/hermes'
import { requestComposerFocus, requestComposerInsert } from '../../chat/composer/focus'
@@ -97,7 +97,7 @@ export function useDesktopIntegrations({
// This ref is a one-time lifecycle latch, not a mirror of reactive atom state.
// eslint-disable-next-line no-restricted-syntax
useEffect(() => {
- if (!profileReady || isHudWindow()) {
+ if (!profileReady || isHudWindow() || isBrowserWindow()) {
return
}
@@ -332,7 +332,7 @@ export function useDesktopIntegrations({
// Another window mutated the shared session list -> re-pull the sidebar.
useEffect(() => {
- if (isSecondaryWindow()) {
+ if (isSecondaryWindow() || isBrowserWindow()) {
return
}
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index 782a3034a2c..4d1847bda86 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -83,7 +83,7 @@ import { requestForSessionProfile, type SessionOwnerScope } from '@/store/sessio
import { $focusedStoredSessionId, sessionTileOwnerRoute, storedSessionIdForRuntimeId } from '@/store/session-states'
import { clearSessionTodos, setSessionTodos, todosForHydration } from '@/store/todos'
import { armWakeWord, stopClientCapture } from '@/store/wake-word'
-import { isAuxiliaryWindow, isHudWindow } from '@/store/windows'
+import { isAuxiliaryWindow, isBrowserWindow, isHudWindow } from '@/store/windows'
import { useSkinCommand } from '@/themes/use-skin-command'
import { closeWorkspaceTab } from '../chat/close-tab'
@@ -1175,10 +1175,10 @@ export function ContribWiring({ children }: { children: ReactNode }) {
} as CSSProperties
}
>
- {/* HUD mode has no titlebar to hang these off — the clusters are
- `fixed`, so without this they'd float over the chat as orphaned
- buttons. Exits are the ⌘⇧H toggle and ⌘W. */}
- {!isHudWindow() && (
+ {/* HUD and the popped-out Browser have no titlebar to hang these off —
+ the clusters are `fixed`, so without this they'd float over the
+ surface as orphaned buttons. */}
+ {!isHudWindow() && !isBrowserWindow() && (
<TitlebarControls
leftTools={leftTitlebarTools}
onOpenSettings={() => navigate(SETTINGS_ROUTE)}
@@ -1298,11 +1298,11 @@ export function ContribWiring({ children }: { children: ReactNode }) {
{/* Petdex floating mascot — renders nothing unless installed + enabled.
Never in the HUD: that window is the chat bar and nothing else. */}
- {!isHudWindow() && <FloatingPet />}
+ {!isHudWindow() && !isBrowserWindow() && <FloatingPet />}
{/* Single persistent xterm host chasing the terminal pane's slot rect.
The HUD has no terminal pane, so it has nothing to chase. */}
- {!isHudWindow() && <PersistentTerminal onAddSelectionToChat={composer.addTerminalSelectionAttachment} />}
+ {!isHudWindow() && !isBrowserWindow() && <PersistentTerminal onAddSelectionToChat={composer.addTerminalSelectionAttachment} />}
</ContribWiringContext.Provider>
)
}
diff --git a/apps/desktop/src/components/pane-shell/tree/store.ts b/apps/desktop/src/components/pane-shell/tree/store.ts
index ffb6016225a..e4b7d15c476 100644
--- a/apps/desktop/src/components/pane-shell/tree/store.ts
+++ b/apps/desktop/src/components/pane-shell/tree/store.ts
@@ -13,7 +13,7 @@ import { translateNow } from '@/i18n'
import { readJson, readKey, writeJson, writeKey } from '@/lib/storage'
import { notify } from '@/store/notifications'
import { clearAllPaneSizeOverrides } from '@/store/panes'
-import { isSecondaryWindow } from '@/store/windows'
+import { isBrowserWindow, isSecondaryWindow } from '@/store/windows'
import {
allPaneIds,
@@ -65,7 +65,8 @@ function loadPersisted(): LayoutNode | null {
function persist(tree: LayoutNode | null) {
// A secondary window (single-chat pop-out) shares the origin's localStorage;
// writing its stripped-down DEFAULT tree back would wipe the primary's layout.
- if (isSecondaryWindow()) {
+ // A popped-out Browser is the same class of window.
+ if (isSecondaryWindow() || isBrowserWindow()) {
return
}
@@ -75,7 +76,9 @@ function persist(tree: LayoutNode | null) {
/** The live tree (null until a default is declared). A secondary window ignores
* the persisted (primary) layout and boots to the default — nothing but its
* own routed session. */
-export const $layoutTree = atom<LayoutNode | null>(isSecondaryWindow() ? null : loadPersisted())
+export const $layoutTree = atom<LayoutNode | null>(
+ isSecondaryWindow() || isBrowserWindow() ? null : loadPersisted()
+)
/**
* Which layout preset the current tree came from; `'custom'` after the user
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 8236d26aea4..eb018b7344b 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -2328,6 +2328,8 @@ export const ar = defineLocale({
openPreview: 'فتح المعاينة',
openInBrowser: 'فتح في المتصفح',
openInExternal: 'فتح في الخارج',
+ popIn: 'إدخال',
+ popOut: 'إخراج',
linkHint: '⌘/Ctrl-نقر لجزء المعاينة',
sourceLineTitle: 'انقر للتحديد · shift-نقر للتوسيع · اسحب إلى المُنشئ',
source: 'المصدر',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index b0c21591143..19d3fd770e8 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2971,6 +2971,8 @@ export const en: Translations = {
openPreview: 'Open preview',
openInBrowser: 'Open in browser',
openInExternal: 'Open in external',
+ popIn: 'Pop in',
+ popOut: 'Pop out',
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 896c755792c..7d89e577eab 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2625,6 +2625,8 @@ export const ja = defineLocale({
openPreview: 'プレビューを開く',
openInBrowser: 'ブラウザで開く',
openInExternal: '外部で開く',
+ popIn: 'ポップイン',
+ popOut: 'ポップアウト',
linkHint: '⌘/Ctrl+クリックでプレビューペイン',
sourceLineTitle: 'クリックして選択 · Shift クリックで拡張 · コンポーザーにドラッグ',
source: 'ソース',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index c5f3eff99f0..1b1962d4aad 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2536,6 +2536,8 @@ export interface Translations {
openPreview: string
openInBrowser: string
openInExternal: string
+ popIn: string
+ popOut: 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 e850dd80154..005ad3d1dd1 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2536,6 +2536,8 @@ export const zhHant = defineLocale({
openPreview: '開啟預覽',
openInBrowser: '在瀏覽器中開啟',
openInExternal: '在外部開啟',
+ popIn: '彈回',
+ popOut: '彈出',
linkHint: '⌘/Ctrl+點擊在預覽窗格開啟',
sourceLineTitle: '點擊選取 · shift 點擊擴展 · 拖曳至輸入框',
source: '原始碼',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 0c4c3fd8882..fd56a1a6187 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3135,6 +3135,8 @@ export const zh: Translations = {
openPreview: '打开预览',
openInBrowser: '在浏览器中打开',
openInExternal: '在外部打开',
+ popIn: '弹回',
+ popOut: '弹出',
linkHint: '⌘/Ctrl+点击在预览面板打开',
sourceLineTitle: '点击选择 · shift 点击扩展 · 拖到输入框',
source: '源码',
diff --git a/apps/desktop/src/store/preview.test.ts b/apps/desktop/src/store/preview.test.ts
index f53ebbd695c..a2c1c6b4dc8 100644
--- a/apps/desktop/src/store/preview.test.ts
+++ b/apps/desktop/src/store/preview.test.ts
@@ -6,11 +6,13 @@ import {
$previewServerRestartStatus,
$previewTabs,
$previewTarget,
+ adoptPersistedBrowserTab,
beginPreviewServerRestart,
closePreviewForSource,
closePreviewMatching,
closeRightRail,
closeRightRailTab,
+ commitBrowserTabLocation,
newBrowserTab,
openPreview,
previewTabId,
@@ -84,6 +86,18 @@ describe('preview store', () => {
expect($rightRailActiveTabId.get()).toBe(urlTabs[0].id)
})
+ it('commits the live page onto a Browser tab without changing its id', () => {
+ openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
+ const id = $previewTabs.get()[0].id
+
+ commitBrowserTabLocation(id, 'https://news.ycombinator.com/item?id=1', 'Item')
+
+ expect($previewTabs.get()).toHaveLength(1)
+ expect($previewTabs.get()[0].id).toBe(id)
+ expect($previewTabs.get()[0].target.url).toBe('https://news.ycombinator.com/item?id=1')
+ expect($previewTabs.get()[0].target.label).toBe('Item')
+ })
+
it('opens more than one Browser on request, each holding its own page', () => {
openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
newBrowserTab()
diff --git a/apps/desktop/src/store/preview.ts b/apps/desktop/src/store/preview.ts
index 1da31019f1b..6e3e685e68f 100644
--- a/apps/desktop/src/store/preview.ts
+++ b/apps/desktop/src/store/preview.ts
@@ -1,9 +1,11 @@
import { atom, computed } from 'nanostores'
import { persistentAtom } from '@/lib/persisted'
+import { readKey } from '@/lib/storage'
import { normalize } from '@/lib/text'
import { $rightRailActiveTabId, type RightRailTabId, selectRightRailTab } from './layout'
+import { canOpenBrowserWindow, openBrowserInNewWindow } from './windows'
/**
* PREVIEW RAIL — one list of tabs, one way in.
@@ -206,6 +208,124 @@ export function forgetBrowserPage(tabId: string) {
}
}
+/** Write the page a Browser is showing back onto its persisted tab. The
+ * webview is built from `target.url`, so this is for hand-off (pop-out /
+ * dock-back), not for every in-page hop — that would tear the guest down. */
+export function commitBrowserTabLocation(tabId: string, url: string, title?: string) {
+ const nextUrl = url.trim()
+
+ if (!tabId || !nextUrl) {
+ return
+ }
+
+ const tabs = $previewTabs.get()
+ const index = tabs.findIndex(tab => tab.id === tabId)
+
+ if (index === -1) {
+ return
+ }
+
+ const tab = tabs[index]
+ const nextTitle = title?.trim()
+
+ if (tab.target.kind !== 'url' || (tab.target.url === nextUrl && (!nextTitle || tab.target.label === nextTitle))) {
+ return
+ }
+
+ $previewTabs.set(
+ tabs.map((item, i) =>
+ i === index
+ ? {
+ ...item,
+ target: {
+ ...item.target,
+ ...(nextTitle ? { label: nextTitle } : {}),
+ url: nextUrl
+ }
+ }
+ : item
+ )
+ )
+}
+
+/** Pull one tab from storage into this renderer's atom. A sibling window
+ * (the pop-out) may have committed a newer URL that we never saw. */
+export function adoptPersistedBrowserTab(tabId: string) {
+ if (!tabId) {
+ return
+ }
+
+ try {
+ const raw = readKey(TABS_STORAGE_KEY)
+
+ if (!raw) {
+ return
+ }
+
+ const persisted = decodePreviewTabs(raw).find(tab => tab.id === tabId)
+
+ if (!persisted || persisted.target.kind !== 'url') {
+ return
+ }
+
+ commitBrowserTabLocation(tabId, persisted.target.url, persisted.target.label)
+ } catch {
+ // Storage can throw; the in-memory tab stays as it was.
+ }
+}
+
+/** Pop the in-app Browser into its own OS window. Shared by the address-bar
+ * glyph and the tab context menu so they cannot drift. */
+export function popOutBrowserTab(tabId: string) {
+ if (!tabId || !canOpenBrowserWindow()) {
+ return
+ }
+
+ const tab = $previewTabs.get().find(item => item.id === tabId)
+
+ if (!tab || tab.target.kind !== 'url') {
+ return
+ }
+
+ const page = $browserPages.get()[tabId]
+
+ markBrowserTabPopped(tabId, true)
+ commitBrowserTabLocation(tabId, page?.url || tab.target.url, page?.title)
+ void openBrowserInNewWindow(tabId).then(ok => {
+ if (!ok) {
+ markBrowserTabPopped(tabId, false)
+ }
+ })
+}
+
+/** Tabs currently shown in a popped-out Browser window. The docked tree
+ * hides them so the page isn't in two places; closing the window docks
+ * them again. Memory-only — a relaunch with no pop-out window restores. */
+export const $poppedBrowserTabIds = atom<ReadonlySet<string>>(new Set())
+
+export function markBrowserTabPopped(tabId: string, popped: boolean) {
+ const current = $poppedBrowserTabIds.get()
+
+ if (current.has(tabId) === popped) {
+ return
+ }
+
+ const next = new Set(current)
+
+ if (popped) {
+ next.add(tabId)
+ } else {
+ next.delete(tabId)
+ }
+
+ $poppedBrowserTabIds.set(next)
+}
+
+/** Preview tabs that still belong in the layout tree (not popped out). */
+export const $dockedPreviewTabs = computed([$previewTabs, $poppedBrowserTabIds], (tabs, popped) =>
+ popped.size === 0 ? tabs : tabs.filter(tab => !popped.has(tab.id))
+)
+
export const $previewReloadRequest = atom(0)
export const $previewServerRestart = atom<PreviewServerRestart | null>(null)
export const $previewServerRestartStatus = computed($previewServerRestart, restart => restart?.status ?? 'idle')
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index 1711bc898ab..05ad65a8f61 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -51,7 +51,7 @@ import {
} from './session'
import { requestForSessionProfile, type SessionOwnerScope, type SessionProfileRoute } from './session-request-router'
import { ackStoredSessionId, markSessionUnreadFinished } from './session-unread'
-import { isSecondaryWindow } from './windows'
+import { isBrowserWindow, isSecondaryWindow } from './windows'
// ---------------------------------------------------------------------------
// Reactive per-runtime session state (view mirror of the wiring cache).
@@ -687,13 +687,15 @@ const profileKey = () => normalizeProfileKey($activeGatewayProfile.get())
// A secondary window (single-chat pop-out) shows ONLY its routed session — no
// tiles, and no repopulation on a profile switch.
export const $sessionTiles = atom<SessionTile[]>(
- isSecondaryWindow() ? [] : [...(tilesByProfile[profileKey()] ?? []), ...(tilesByProfile[BOTS_TILE_BUCKET] ?? [])]
+ isSecondaryWindow() || isBrowserWindow()
+ ? []
+ : [...(tilesByProfile[profileKey()] ?? []), ...(tilesByProfile[BOTS_TILE_BUCKET] ?? [])]
)
function persistTiles() {
- // Shares the origin's storage; a secondary window holds no tiles, so a write
- // back would only wipe the primary's set.
- if (isSecondaryWindow()) {
+ // Shares the origin's storage; a secondary / browser pop-out holds no tiles,
+ // so a write back would only wipe the primary's set.
+ if (isSecondaryWindow() || isBrowserWindow()) {
return
}
@@ -725,7 +727,7 @@ function saveTiles(tiles: SessionTile[]) {
// they re-resume against the now-current gateway. (Fires immediately on
// subscribe; harmless — the init value already matches.) A secondary window
// never carries tiles, so it stays out of this entirely.
-if (!isSecondaryWindow()) {
+if (!isSecondaryWindow() && !isBrowserWindow()) {
$activeGatewayProfile.subscribe(() => {
$sessionTiles.set([...(tilesByProfile[profileKey()] ?? []), ...(tilesByProfile[BOTS_TILE_BUCKET] ?? [])])
})
diff --git a/apps/desktop/src/store/session-unread.ts b/apps/desktop/src/store/session-unread.ts
index 64f3cdf115e..c3e12122f55 100644
--- a/apps/desktop/src/store/session-unread.ts
+++ b/apps/desktop/src/store/session-unread.ts
@@ -13,7 +13,7 @@ import {
sessionMatchesStoredId,
sessionPinId
} from './session'
-import { isSecondaryWindow } from './windows'
+import { isBrowserWindow, isSecondaryWindow } from './windows'
/**
* PERSISTED UNREAD ("finished — unread" green dot) — the durable layer under
@@ -554,7 +554,7 @@ function onListChange(): void {
// (single-chat pop-out, watch window) sees a sliver of the session lists, and
// letting it seed/ack against that partial view would clobber the primary's
// whole-record writes — same isolation rule as the persisted session tiles.
-if (!isSecondaryWindow()) {
+if (!isSecondaryWindow() && !isBrowserWindow()) {
$sessions.listen(onListChange)
$cronSessions.listen(onListChange)
$messagingSessions.listen(onListChange)