diff --git a/src/main/browser/browser-cookie-import.helium.test.ts b/src/main/browser/browser-cookie-import.helium.test.ts new file mode 100644 index 000000000..1c551ac00 --- /dev/null +++ b/src/main/browser/browser-cookie-import.helium.test.ts @@ -0,0 +1,219 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type * as childProcessModule from 'node:child_process' +import type * as fsModule from 'node:fs' + +const { sessionFromPartitionMock, dialogShowOpenDialogMock } = vi.hoisted(() => ({ + sessionFromPartitionMock: vi.fn(), + dialogShowOpenDialogMock: vi.fn() +})) + +vi.mock('electron', () => ({ + BrowserWindow: { fromWebContents: vi.fn() }, + dialog: { showOpenDialog: dialogShowOpenDialogMock }, + session: { fromPartition: sessionFromPartitionMock } +})) + +import { BROWSER_FAMILY_LABELS } from '../../shared/constants' + +function slashPath(pathValue: string): string { + return pathValue.replaceAll('\\', '/') +} + +describe('detectInstalledBrowsers — Helium', () => { + const originalPlatform = process.platform + const originalHome = process.env.HOME + + beforeEach(() => { + // Why: browser-cookie-import.ts uses destructured named imports from + // 'node:fs' which are bound at module-load time. resetModules must run + // BEFORE each doMock so the next import() picks up the fresh mock factory. + vi.resetModules() + Object.defineProperty(process, 'platform', { value: 'darwin' }) + process.env.HOME = '/Users/test' + }) + + afterEach(() => { + Object.defineProperty(process, 'platform', { value: originalPlatform }) + process.env.HOME = originalHome + vi.restoreAllMocks() + }) + + it('detects Helium under its bundle-id data dir via the legacy Cookies path', async () => { + vi.doMock('node:fs', async () => { + const actual = await vi.importActual('node:fs') + return { + ...actual, + existsSync: (p: string) => { + const normalizedPath = slashPath(p) + // Why: Helium stores cookies at the legacy /Cookies path, so the + // newer Network/Cookies probe must miss and the legacy fallback must fire. + if (normalizedPath.includes('net.imput.helium/Default/Network/Cookies')) { + return false + } + if (normalizedPath.endsWith('net.imput.helium/Default/Cookies')) { + return true + } + if (normalizedPath.includes('net.imput.helium/Local State')) { + return true + } + return false + }, + readFileSync: (p: string, enc?: string) => { + if (typeof p === 'string' && slashPath(p).includes('net.imput.helium/Local State')) { + return JSON.stringify({ profile: { info_cache: { Default: { name: 'Default' } } } }) + } + return actual.readFileSync(p as never, enc as never) + } + } + }) + + const { detectInstalledBrowsers } = await import('./browser-cookie-import') + const detected = detectInstalledBrowsers() + const helium = detected.find((b) => b.family === 'helium') + expect(helium).toBeDefined() + expect(helium?.label).toBe('Helium') + expect(slashPath(helium?.cookiesPath ?? '')).toContain('net.imput.helium/Default/Cookies') + expect(slashPath(helium?.cookiesPath ?? '')).not.toContain('Network/Cookies') + expect(helium?.keychainService).toBe('Helium Storage Key') + expect(helium?.keychainAccount).toBe('Helium') + }) + + it('does not list Helium when its data directory is absent', async () => { + vi.doMock('node:fs', async () => { + const actual = await vi.importActual('node:fs') + return { + ...actual, + existsSync: () => false + } + }) + + const { detectInstalledBrowsers } = await import('./browser-cookie-import') + const detected = detectInstalledBrowsers() + expect(detected.find((b) => b.family === 'helium')).toBeUndefined() + }) + + it('enumerates all Helium profiles from Local State info_cache', async () => { + vi.doMock('node:fs', async () => { + const actual = await vi.importActual('node:fs') + return { + ...actual, + existsSync: (p: string) => { + const normalizedPath = slashPath(p) + if (normalizedPath.endsWith('net.imput.helium/Default/Cookies')) { + return true + } + if (normalizedPath.includes('net.imput.helium/Local State')) { + return true + } + return false + }, + readFileSync: (p: string, enc?: string) => { + if (typeof p === 'string' && slashPath(p).includes('net.imput.helium/Local State')) { + return JSON.stringify({ + profile: { + info_cache: { + Default: { name: 'Personal' }, + 'Profile 1': { name: 'Work' } + } + } + }) + } + return actual.readFileSync(p as never, enc as never) + } + } + }) + + const { detectInstalledBrowsers } = await import('./browser-cookie-import') + const detected = detectInstalledBrowsers() + const helium = detected.find((b) => b.family === 'helium') + expect(helium).toBeDefined() + const directories = helium!.profiles.map((p) => p.directory).sort() + expect(directories).toEqual(['Default', 'Profile 1']) + }) + + it('rejects explicit Helium profile selections that escape the browser root', async () => { + vi.doMock('node:fs', async () => { + const actual = await vi.importActual('node:fs') + return { + ...actual, + existsSync: (p: string) => slashPath(p).includes('Application Support/Outside/Cookies') + } + }) + + const { selectBrowserProfile } = await import('./browser-cookie-import') + const selected = selectBrowserProfile( + { + family: 'helium', + label: 'Helium', + cookiesPath: '/Users/test/Library/Application Support/net.imput.helium/Default/Cookies', + keychainService: 'Helium Storage Key', + keychainAccount: 'Helium', + profiles: [{ name: 'Outside', directory: '../Outside' }], + selectedProfile: 'Default' + }, + '../Outside' + ) + + expect(selected).toBeNull() + }) +}) + +describe('getUserAgentForBrowser — Helium', () => { + const originalPlatform = process.platform + + beforeEach(() => { + vi.resetModules() + Object.defineProperty(process, 'platform', { value: 'darwin' }) + }) + + afterEach(() => { + Object.defineProperty(process, 'platform', { value: originalPlatform }) + vi.restoreAllMocks() + }) + + it('returns a Chrome-shaped UA string when Helium plist version reads successfully', async () => { + vi.doMock('node:child_process', async () => { + const actual = await vi.importActual('node:child_process') + return { + ...actual, + execFileSync: (cmd: string, args: readonly string[]) => { + if (cmd === 'defaults' && args[1]?.includes('/Applications/Helium.app/Contents/Info')) { + return '120.0.6099.71\n' + } + return actual.execFileSync(cmd, args as never) + } + } + }) + + const { getUserAgentForBrowser } = await import('./browser-cookie-import') + const ua = getUserAgentForBrowser('helium') + + expect(ua).not.toBeNull() + expect(ua).toContain('Macintosh; Intel Mac OS X 10_15_7') + expect(ua).toContain('AppleWebKit/537.36') + expect(ua).toContain('Chrome/120.0.6099.71') + expect(ua).toContain('Safari/537.36') + }) + + it('returns null when reading the Helium plist version throws', async () => { + vi.doMock('node:child_process', async () => { + const actual = await vi.importActual('node:child_process') + return { + ...actual, + execFileSync: () => { + throw new Error('defaults: domain not found') + } + } + }) + + const { getUserAgentForBrowser } = await import('./browser-cookie-import') + const ua = getUserAgentForBrowser('helium') + expect(ua).toBeNull() + }) +}) + +describe('BROWSER_FAMILY_LABELS — Helium', () => { + it('maps the helium family key to the user-facing label "Helium"', () => { + expect(BROWSER_FAMILY_LABELS.helium).toBe('Helium') + }) +}) diff --git a/src/main/browser/browser-cookie-import.test.ts b/src/main/browser/browser-cookie-import.test.ts index ff8d82e72..767f35931 100644 --- a/src/main/browser/browser-cookie-import.test.ts +++ b/src/main/browser/browser-cookie-import.test.ts @@ -347,7 +347,16 @@ describe('detectInstalledBrowsers', () => { it('each detected browser has a valid family', () => { const browsers = detectInstalledBrowsers() - const validFamilies = ['chrome', 'edge', 'arc', 'chromium', 'firefox', 'safari', 'comet'] + const validFamilies = [ + 'chrome', + 'edge', + 'arc', + 'chromium', + 'firefox', + 'safari', + 'comet', + 'helium' + ] for (const browser of browsers) { expect(validFamilies).toContain(browser.family) } diff --git a/src/main/browser/browser-cookie-import.ts b/src/main/browser/browser-cookie-import.ts index 921460243..bf568abfe 100644 --- a/src/main/browser/browser-cookie-import.ts +++ b/src/main/browser/browser-cookie-import.ts @@ -153,6 +153,16 @@ const CHROMIUM_BROWSERS: ChromiumBrowserDef[] = [ macRoot: 'Comet', winRoot: 'Comet/User Data' // linuxRoot intentionally omitted — Comet does not ship a Linux build as of 2026-05-15 + }, + { + family: 'helium', + // Why: Helium deviates from the ' Safe Storage'/'' convention — + // its Keychain entry is literally service 'Helium Storage Key', account 'Helium'. + label: 'Helium', + keychainService: 'Helium Storage Key', + keychainAccount: 'Helium', + macRoot: 'net.imput.helium' + // winRoot/linuxRoot intentionally omitted — only the macOS install is verified } ] @@ -767,6 +777,12 @@ export function getUserAgentForBrowser( const v = readBrowserVersion('/Applications/Comet.app') return v ? `Mozilla/5.0 (${platform}) ${chromeBase} Chrome/${v} Safari/537.36` : null } + case 'helium': { + // Why: Helium is Chromium-based and ships a Chrome-shaped version in its plist. + // Use the same UA shape as Chrome itself so Google-bound auth cookies survive import. + const v = readBrowserVersion('/Applications/Helium.app') + return v ? `Mozilla/5.0 (${platform}) ${chromeBase} Chrome/${v} Safari/537.36` : null + } case 'firefox': case 'safari': case 'manual': diff --git a/src/renderer/src/components/browser-pane/browser-detected-browsers-summary.test.ts b/src/renderer/src/components/browser-pane/browser-detected-browsers-summary.test.ts index a82bf20ec..d2302d815 100644 --- a/src/renderer/src/components/browser-pane/browser-detected-browsers-summary.test.ts +++ b/src/renderer/src/components/browser-pane/browser-detected-browsers-summary.test.ts @@ -7,6 +7,7 @@ const SUPPORTED_LABELS = [ 'Arc', 'Brave', 'Comet', + 'Helium', 'Firefox', 'Safari' ] @@ -46,7 +47,7 @@ describe('formatBrowserImportSummary', () => { detectedBrowsersLoaded: false, supportedImportLabels: SUPPORTED_LABELS }) - ).toBe('Import from: Google Chrome, Microsoft Edge, Arc, Brave, +3 more.') + ).toBe('Import from: Google Chrome, Microsoft Edge, Arc, Brave, +4 more.') }) it('falls back to supported import sources when detection finds nothing', () => { @@ -56,6 +57,6 @@ describe('formatBrowserImportSummary', () => { detectedBrowsersLoaded: true, supportedImportLabels: SUPPORTED_LABELS }) - ).toBe('Import from: Google Chrome, Microsoft Edge, Arc, Brave, +3 more.') + ).toBe('Import from: Google Chrome, Microsoft Edge, Arc, Brave, +4 more.') }) }) diff --git a/src/shared/browser-cookie-import-sources.test.ts b/src/shared/browser-cookie-import-sources.test.ts index 8351df168..8d5a00322 100644 --- a/src/shared/browser-cookie-import-sources.test.ts +++ b/src/shared/browser-cookie-import-sources.test.ts @@ -9,6 +9,7 @@ describe('getBrowserCookieImportSourceLabels', () => { 'Arc', 'Brave', 'Comet', + 'Helium', 'Firefox', 'Safari' ]) diff --git a/src/shared/browser-cookie-import-sources.ts b/src/shared/browser-cookie-import-sources.ts index 81a1abe61..0e2186a06 100644 --- a/src/shared/browser-cookie-import-sources.ts +++ b/src/shared/browser-cookie-import-sources.ts @@ -5,7 +5,8 @@ const CHROMIUM_COOKIE_IMPORT_SOURCES = [ { label: 'Microsoft Edge', mac: true, win: true, linux: true }, { label: 'Arc', mac: true, win: false, linux: false }, { label: 'Brave', mac: true, win: true, linux: true }, - { label: 'Comet', mac: true, win: true, linux: false } + { label: 'Comet', mac: true, win: true, linux: false }, + { label: 'Helium', mac: true, win: false, linux: false } ] as const export function getBrowserCookieImportSourceLabels( diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 4a3757159..f92046b75 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -73,6 +73,7 @@ export const BROWSER_FAMILY_LABELS: Record = { chrome: 'Google Chrome', chromium: 'Chromium', comet: 'Comet', + helium: 'Helium', arc: 'Arc', edge: 'Microsoft Edge', brave: 'Brave', diff --git a/src/shared/types.ts b/src/shared/types.ts index 7a7f28080..52a12a4e7 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -938,7 +938,16 @@ export type BrowserTab = BrowserWorkspace export type BrowserSessionProfileScope = 'default' | 'isolated' | 'imported' export type BrowserSessionProfileSource = { - browserFamily: 'chrome' | 'chromium' | 'arc' | 'edge' | 'firefox' | 'safari' | 'comet' | 'manual' + browserFamily: + | 'chrome' + | 'chromium' + | 'arc' + | 'edge' + | 'firefox' + | 'safari' + | 'comet' + | 'helium' + | 'manual' profileName?: string importedAt: number }