Add in-app browser tabs (#430)

This commit is contained in:
Jinwoo Hong
2026-04-10 00:04:42 -07:00
committed by GitHub
parent fee1165747
commit c6ff6da3a8
45 changed files with 3953 additions and 345 deletions
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'
import { ORCA_BROWSER_BLANK_URL } from './constants'
import { normalizeBrowserNavigationUrl, normalizeExternalBrowserUrl } from './browser-url'
describe('browser-url helpers', () => {
it('normalizes manual local-dev inputs to http', () => {
expect(normalizeBrowserNavigationUrl('localhost:3000')).toBe('http://localhost:3000/')
expect(normalizeBrowserNavigationUrl('127.0.0.1:5173')).toBe('http://127.0.0.1:5173/')
})
it('keeps normal web URLs and blank tabs in the allowed set', () => {
expect(normalizeBrowserNavigationUrl('https://example.com')).toBe('https://example.com/')
expect(normalizeBrowserNavigationUrl('')).toBe(ORCA_BROWSER_BLANK_URL)
expect(normalizeBrowserNavigationUrl('about:blank')).toBe(ORCA_BROWSER_BLANK_URL)
})
it('rejects non-web schemes for in-app navigation', () => {
expect(normalizeBrowserNavigationUrl('file:///etc/passwd')).toBeNull()
expect(normalizeBrowserNavigationUrl('javascript:alert(1)')).toBeNull()
expect(normalizeExternalBrowserUrl('about:blank')).toBeNull()
})
})
+35
View File
@@ -0,0 +1,35 @@
import { ORCA_BROWSER_BLANK_URL } from './constants'
const LOCAL_ADDRESS_PATTERN =
/^(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[[0-9a-f:]+\])(?::\d+)?(?:\/.*)?$/i
export function normalizeBrowserNavigationUrl(rawUrl: string): string | null {
const trimmed = rawUrl.trim()
if (trimmed.length === 0 || trimmed === 'about:blank' || trimmed === ORCA_BROWSER_BLANK_URL) {
return ORCA_BROWSER_BLANK_URL
}
if (LOCAL_ADDRESS_PATTERN.test(trimmed)) {
try {
return new URL(`http://${trimmed}`).toString()
} catch {
return null
}
}
try {
const parsed = new URL(trimmed)
return parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.toString() : null
} catch {
try {
return new URL(`https://${trimmed}`).toString()
} catch {
return null
}
}
}
export function normalizeExternalBrowserUrl(rawUrl: string): string | null {
const normalized = normalizeBrowserNavigationUrl(rawUrl)
return normalized === ORCA_BROWSER_BLANK_URL ? null : normalized
}
+9
View File
@@ -10,6 +10,12 @@ import type {
import { DEFAULT_TERMINAL_FONT_WEIGHT } from './terminal-fonts'
export const SCHEMA_VERSION = 1
export const ORCA_BROWSER_PARTITION = 'persist:orca-browser'
// Why: blank browser tabs must start from an inert guest URL that does not
// navigate the privileged main window to about:blank. Renderer and main both
// need the exact same value so the attach policy can allow only this one safe
// data URL while still rejecting arbitrary renderer-provided data URLs.
export const ORCA_BROWSER_BLANK_URL = 'data:text/html,'
// Pick a default terminal font that is likely to exist on the current OS.
// buildFontFamily() adds the full cross-platform fallback chain, so this only
@@ -95,6 +101,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
// focus-follows-mouse never happens unexpectedly.
terminalFocusFollowsMouse: false,
terminalScrollbackBytes: 10_000_000,
openLinksInApp: false,
rightSidebarOpenByDefault: true,
notifications: getDefaultNotificationSettings(),
diffDefaultView: 'inline',
@@ -152,6 +159,8 @@ export function getDefaultWorkspaceSession(): WorkspaceSessionState {
tabsByWorktree: {},
terminalLayoutsByTabId: {},
openFilesByWorktree: {},
browserTabsByWorktree: {},
activeBrowserTabIdByWorktree: {},
activeFileIdByWorktree: {},
activeTabTypeByWorktree: {}
}
+32 -3
View File
@@ -56,7 +56,9 @@ export type WorktreeMeta = {
}
// ─── Unified Tab ────────────────────────────────────────────────────
export type TabContentType = 'terminal' | 'editor' | 'diff' | 'conflict-review'
export type TabContentType = 'terminal' | 'editor' | 'diff' | 'conflict-review' | 'browser'
export type WorkspaceVisibleTabType = 'terminal' | 'editor' | 'browser'
export type Tab = {
id: string // UUID for terminals, filePath for editors (preserves current convention)
@@ -93,6 +95,25 @@ export type TerminalTab = {
generation?: number
}
export type BrowserLoadError = {
code: number
description: string
validatedUrl: string
}
export type BrowserTab = {
id: string
worktreeId: string
url: string
title: string
loading: boolean
faviconUrl: string | null
canGoBack: boolean
canGoForward: boolean
loadError: BrowserLoadError | null
createdAt: number
}
export type TerminalPaneSplitDirection = 'vertical' | 'horizontal'
export type TerminalPaneLayoutNode =
@@ -147,8 +168,12 @@ export type WorkspaceSessionState = {
openFilesByWorktree?: Record<string, PersistedOpenFile[]>
/** Per-worktree active editor file ID (filePath) at shutdown. */
activeFileIdByWorktree?: Record<string, string | null>
/** Per-worktree active tab type (terminal vs editor) at shutdown. */
activeTabTypeByWorktree?: Record<string, 'terminal' | 'editor'>
/** Persisted browser tabs, keyed by worktree ID. */
browserTabsByWorktree?: Record<string, BrowserTab[]>
/** Per-worktree active browser tab ID at shutdown. */
activeBrowserTabIdByWorktree?: Record<string, string | null>
/** Per-worktree active tab type (terminal vs editor vs browser) at shutdown. */
activeTabTypeByWorktree?: Record<string, WorkspaceVisibleTabType>
/** Per-worktree last-active terminal tab ID at shutdown. */
activeTabIdByWorktree?: Record<string, string | null>
/** Unified tab model — present when saved by a build that includes TabsSlice.
@@ -314,6 +339,10 @@ export type GlobalSettings = {
terminalDividerThicknessPx: number
terminalFocusFollowsMouse: boolean
terminalScrollbackBytes: number
/** Why: opening arbitrary links inside Orca uses an isolated guest browser surface.
* The setting stays opt-in so existing workflows continue to use the system browser
* until the user explicitly wants worktree-scoped in-app browsing. */
openLinksInApp: boolean
rightSidebarOpenByDefault: boolean
diffDefaultView: 'inline' | 'side-by-side'
notifications: NotificationSettings