diff --git a/src/renderer/src/components/settings/BrowserPane.tsx b/src/renderer/src/components/settings/BrowserPane.tsx index 280729597..a553a0fd7 100644 --- a/src/renderer/src/components/settings/BrowserPane.tsx +++ b/src/renderer/src/components/settings/BrowserPane.tsx @@ -16,10 +16,15 @@ import { } from '../../../../shared/browser-url' import { SearchableSetting } from './SearchableSetting' import { matchesSettingsSearch } from './settings-search' -import { BROWSER_PANE_SEARCH_ENTRIES } from './browser-search' +import { BROWSER_PANE_SEARCH_ENTRIES as BROWSER_CORE_SEARCH_ENTRIES } from './browser-search' +import { BROWSER_USE_PANE_SEARCH_ENTRIES } from './browser-use-search' import { BrowserProfileRow } from './BrowserProfileRow' +import { BrowserUseSetup } from './BrowserUsePane' -export { BROWSER_PANE_SEARCH_ENTRIES } +export const BROWSER_PANE_SEARCH_ENTRIES = [ + ...BROWSER_USE_PANE_SEARCH_ENTRIES, + ...BROWSER_CORE_SEARCH_ENTRIES +] type BrowserPaneProps = { settings: GlobalSettings @@ -51,13 +56,36 @@ export function BrowserPane({ settings, updateSettings }: BrowserPaneProps): Rea setHomePageDraft(browserDefaultUrl ?? '') }, [browserDefaultUrl]) - const showHomePage = matchesSettingsSearch(searchQuery, [BROWSER_PANE_SEARCH_ENTRIES[0]]) - const showSearchEngine = matchesSettingsSearch(searchQuery, [BROWSER_PANE_SEARCH_ENTRIES[1]]) - const showLinkRouting = matchesSettingsSearch(searchQuery, [BROWSER_PANE_SEARCH_ENTRIES[2]]) - const showCookies = matchesSettingsSearch(searchQuery, [BROWSER_PANE_SEARCH_ENTRIES[3]]) + const showHomePage = matchesSettingsSearch(searchQuery, [BROWSER_CORE_SEARCH_ENTRIES[0]]) + const showSearchEngine = matchesSettingsSearch(searchQuery, [BROWSER_CORE_SEARCH_ENTRIES[1]]) + const showLinkRouting = matchesSettingsSearch(searchQuery, [BROWSER_CORE_SEARCH_ENTRIES[2]]) + const showCookies = matchesSettingsSearch(searchQuery, [BROWSER_CORE_SEARCH_ENTRIES[3]]) + const showBrowserUse = matchesSettingsSearch(searchQuery, BROWSER_USE_PANE_SEARCH_ENTRIES) + + const scrollToSessionCookies = (): void => { + // Why: the "Session & Cookies" block is search-gated, so if the user has + // filtered to a query that excludes it the target element won't be in the + // DOM. Clear the search first, then scroll on the next frame so the block + // has mounted. + useAppStore.getState().setSettingsSearchQuery('') + // Why: double RAF to ensure React has committed the re-render triggered by + // the store update before we query the DOM — a single RAF can fire before + // commit and miss the newly-mounted element. + requestAnimationFrame(() => { + requestAnimationFrame(() => { + const el = document.getElementById('browser-session-cookies') + if (!el) { + return + } + el.scrollIntoView({ behavior: 'smooth', block: 'start' }) + }) + }) + } return ( -
+
+ {showBrowserUse ? : null} + {showHomePage ? ( { + try { + await window.api.ui.writeClipboardText(text) + toast.success(`Copied ${label}.`) + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to copy.') + } +} + +export function BrowserUseExamples(): React.JSX.Element { + return ( +
+
+ +

Try it — example prompts

+
+

+ Paste any of these into Claude Code, Codex, or another agent in a project where the skill is + installed. +

+
    + {EXAMPLE_PROMPTS.map((prompt) => ( +
  • +

    + “{prompt}” +

    + + + + + + + Copy + + + +
  • + ))} +
+
+ ) +} diff --git a/src/renderer/src/components/settings/BrowserUsePane.tsx b/src/renderer/src/components/settings/BrowserUsePane.tsx new file mode 100644 index 000000000..f7852ae8a --- /dev/null +++ b/src/renderer/src/components/settings/BrowserUsePane.tsx @@ -0,0 +1,386 @@ +import { useEffect, useState } from 'react' +import { Import, Loader2 } from 'lucide-react' +import { toast } from 'sonner' +import type { CliInstallStatus } from '../../../../shared/cli-install-types' +import { Button } from '../ui/button' +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuPortal, + DropdownMenuSeparator, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, + DropdownMenuTrigger +} from '../ui/dropdown-menu' +import { useAppStore } from '../../store' +import { BROWSER_FAMILY_LABELS } from '../../../../shared/constants' +import { SearchableSetting } from './SearchableSetting' +import { matchesSettingsSearch } from './settings-search' +import { BROWSER_USE_PANE_SEARCH_ENTRIES } from './browser-use-search' +import { BrowserUseExamples } from './BrowserUseExamples' +import { StepBadge } from './BrowserUseStepBadge' +import { BrowserUseSkillStep } from './BrowserUseSkillStep' + +const ORCA_SKILL_INSTALL_COMMAND = + 'npx skills add https://github.com/stablyai/orca --skill orca-cli' + +type BrowserUseSetupProps = { + onConfigureMoreBrowsers?: () => void +} + +export function BrowserUseSetup({ + onConfigureMoreBrowsers +}: BrowserUseSetupProps = {}): React.JSX.Element { + const searchQuery = useAppStore((s) => s.settingsSearchQuery) + const browserSessionProfiles = useAppStore((s) => s.browserSessionProfiles) + const detectedBrowsers = useAppStore((s) => s.detectedBrowsers) + const fetchBrowserSessionProfiles = useAppStore((s) => s.fetchBrowserSessionProfiles) + const fetchDetectedBrowsers = useAppStore((s) => s.fetchDetectedBrowsers) + const browserSessionImportState = useAppStore((s) => s.browserSessionImportState) + + const [cliStatus, setCliStatus] = useState(null) + const [cliLoading, setCliLoading] = useState(true) + const [cliBusy, setCliBusy] = useState(false) + + // Why: the toggle gates only whether we show the setup instructions. We + // persist it in localStorage instead of global settings because it has no + // functional effect elsewhere in the app — it's a UI affordance local to + // this pane, consistent with the skill-installed marker below. + const [browserUseEnabled, setBrowserUseEnabled] = useState(() => { + return localStorage.getItem('orca.browserUse.enabled') === '1' + }) + + const toggleBrowserUse = (value: boolean): void => { + setBrowserUseEnabled(value) + localStorage.setItem('orca.browserUse.enabled', value ? '1' : '0') + } + + const refreshCli = async (): Promise => { + setCliLoading(true) + try { + setCliStatus(await window.api.cli.getInstallStatus()) + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to load CLI status.') + } finally { + setCliLoading(false) + } + } + + useEffect(() => { + // Why: skip IPC work when the feature is toggled off — the component + // returns early below and none of this data is rendered. + if (!browserUseEnabled) { + return + } + void refreshCli() + void fetchBrowserSessionProfiles() + void fetchDetectedBrowsers() + }, [browserUseEnabled, fetchBrowserSessionProfiles, fetchDetectedBrowsers]) + + const defaultProfile = browserSessionProfiles.find((p) => p.id === 'default') + // Why: this step explicitly imports into the default profile, so completion + // must track that profile only. Marking done when a non-default profile has + // cookies would mislead users into thinking agents can reach their logins + // when the default profile — the one agents use — is still empty. + const cookiesImported = !!defaultProfile?.source + + const cliEnabled = cliStatus?.state === 'installed' + const cliSupported = cliStatus?.supported ?? false + + // Why: the skill install step is a copy-and-run command that happens in the + // user's terminal. We cannot detect completion from the app, so we let the + // user mark it done explicitly after copying — this avoids falsely implying + // progress and keeps the guided flow honest. + const [skillInstalled, setSkillInstalled] = useState(() => { + return localStorage.getItem('orca.browserUse.skillInstalled') === '1' + }) + + const markSkillInstalled = (value: boolean): void => { + setSkillInstalled(value) + localStorage.setItem('orca.browserUse.skillInstalled', value ? '1' : '0') + } + + const handleEnableCli = async (): Promise => { + setCliBusy(true) + try { + const next = await window.api.cli.install() + setCliStatus(next) + toast.success('Registered `orca` in PATH.') + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to register `orca` in PATH.') + } finally { + setCliBusy(false) + } + } + + const handleCopySkillCommand = async (): Promise => { + try { + await window.api.ui.writeClipboardText(ORCA_SKILL_INSTALL_COMMAND) + toast.success('Copied install command. Run it in your agent project.') + } catch (error) { + toast.error(error instanceof Error ? error.message : 'Failed to copy command.') + } + } + + const handleImportFromBrowser = async ( + browserFamily: string, + browserProfile?: string + ): Promise => { + const profileId = 'default' + const result = await useAppStore + .getState() + .importCookiesFromBrowser(profileId, browserFamily, browserProfile) + if (result.ok) { + const browser = detectedBrowsers.find((b) => b.family === browserFamily) + toast.success( + `Imported ${result.summary.importedCookies} cookies from ${browser?.label ?? browserFamily}${browserProfile ? ` (${browserProfile})` : ''}.` + ) + } else { + toast.error(result.reason) + } + } + + const handleImportFromFile = async (): Promise => { + const result = await useAppStore.getState().importCookiesToProfile('default') + if (result.ok) { + toast.success(`Imported ${result.summary.importedCookies} cookies from file.`) + } else if (result.reason !== 'canceled') { + toast.error(result.reason) + } + } + + const isImportingDefault = + browserSessionImportState?.profileId === 'default' && + browserSessionImportState.status === 'importing' + + const showStep1 = matchesSettingsSearch(searchQuery, [BROWSER_USE_PANE_SEARCH_ENTRIES[0]]) + const showStep2 = matchesSettingsSearch(searchQuery, [BROWSER_USE_PANE_SEARCH_ENTRIES[1]]) + const showStep3 = matchesSettingsSearch(searchQuery, [BROWSER_USE_PANE_SEARCH_ENTRIES[2]]) + + const completedCount = [cliEnabled, skillInstalled, cookiesImported].filter(Boolean).length + + const sourceLabel = defaultProfile?.source + ? `${BROWSER_FAMILY_LABELS[defaultProfile.source.browserFamily] ?? defaultProfile.source.browserFamily}${defaultProfile.source.profileName ? ` (${defaultProfile.source.profileName})` : ''}` + : null + + const toggleSwitch = ( + + ) + + if (!browserUseEnabled) { + return ( +
+
+

Agent Browser Use

+

+ Let coding agents drive this browser with your logins. +

+
+ {toggleSwitch} +
+ ) + } + + return ( +
+
+
+

Agent Browser Use

+

+ Let coding agents drive this browser with your logins. Finish the three steps below. +

+
+
+ + {completedCount}/3 + + {toggleSwitch} +
+
+ + {showStep1 ? ( + +
+ +
+

Enable Orca CLI

+

+ Registers the orca{' '} + command so agents can orchestrate the browser from their shell. +

+ {cliStatus?.commandPath && cliEnabled ? ( +

+ Installed at{' '} + {cliStatus.commandPath} +

+ ) : null} +
+ + + + + + + + {!cliSupported && !cliLoading && cliStatus?.detail ? ( + + {cliStatus.detail} + + ) : null} + + +
+
+ ) : null} + + {showStep2 ? ( + + void handleCopySkillCommand()} + onToggleInstalled={() => markSkillInstalled(!skillInstalled)} + /> + + ) : null} + + {showStep3 ? ( + +
+ +
+

Import Browser Cookies

+

+ Bring your existing logins into Orca so agents can reach authenticated pages. + Imports into the default profile. +

+ {sourceLabel ? ( +

+ Last imported from {sourceLabel} +

+ ) : null} + {onConfigureMoreBrowsers ? ( + + ) : null} +
+ + + + + + {detectedBrowsers.map((browser) => + browser.profiles.length > 1 ? ( + + From {browser.label} + + + {browser.profiles.map((bp) => ( + + void handleImportFromBrowser(browser.family, bp.directory) + } + > + {bp.name} + + ))} + + + + ) : ( + void handleImportFromBrowser(browser.family)} + > + From {browser.label} + + ) + )} + {detectedBrowsers.length > 0 ? : null} + void handleImportFromFile()}> + From File… + + + +
+
+ ) : null} + + +
+ ) +} diff --git a/src/renderer/src/components/settings/BrowserUseSkillStep.tsx b/src/renderer/src/components/settings/BrowserUseSkillStep.tsx new file mode 100644 index 000000000..b744dd932 --- /dev/null +++ b/src/renderer/src/components/settings/BrowserUseSkillStep.tsx @@ -0,0 +1,72 @@ +import { Copy } from 'lucide-react' +import { Button } from '../ui/button' +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip' +import { StepBadge } from './BrowserUseStepBadge' + +type Props = { + command: string + skillInstalled: boolean + disabled?: boolean + onCopy: () => void + onToggleInstalled: () => void +} + +export function BrowserUseSkillStep({ + command, + skillInstalled, + disabled = false, + onCopy, + onToggleInstalled +}: Props): React.JSX.Element { + return ( +
+ +
+
+

Install Browser Use Skill

+

+ Run this in your agent project — once per project — so Claude Code, Codex, and other + agents learn to drive Orca's browser. +

+
+
+ + {command} + + + + + + + + Copy + + + +
+
+ + {skillInstalled + ? 'Marked as installed on this machine.' + : "Check off once you've run it in your project."} + + +
+
+
+ ) +} diff --git a/src/renderer/src/components/settings/BrowserUseStepBadge.tsx b/src/renderer/src/components/settings/BrowserUseStepBadge.tsx new file mode 100644 index 000000000..91edb50f2 --- /dev/null +++ b/src/renderer/src/components/settings/BrowserUseStepBadge.tsx @@ -0,0 +1,31 @@ +import { Check, Loader2 } from 'lucide-react' + +export type StepState = 'pending' | 'done' | 'in-progress' + +export function StepBadge({ + index, + state +}: { + index: number + state: StepState +}): React.JSX.Element { + if (state === 'done') { + return ( +
+ +
+ ) + } + if (state === 'in-progress') { + return ( +
+ +
+ ) + } + return ( +
+ {index} +
+ ) +} diff --git a/src/renderer/src/components/settings/SearchableSetting.tsx b/src/renderer/src/components/settings/SearchableSetting.tsx index 61c4b17bc..d53fd2167 100644 --- a/src/renderer/src/components/settings/SearchableSetting.tsx +++ b/src/renderer/src/components/settings/SearchableSetting.tsx @@ -5,6 +5,7 @@ import { matchesSettingsSearch, type SettingsSearchEntry } from './settings-sear type SearchableSettingProps = SettingsSearchEntry & { children: React.ReactNode className?: string + id?: string } export function SearchableSetting({ @@ -12,12 +13,17 @@ export function SearchableSetting({ description, keywords, children, - className + className, + id }: SearchableSettingProps): React.JSX.Element | null { const query = useAppStore((state) => state.settingsSearchQuery) if (!matchesSettingsSearch(query, { title, description, keywords })) { return null } - return
{children}
+ return ( +
+ {children} +
+ ) } diff --git a/src/renderer/src/components/settings/browser-use-search.ts b/src/renderer/src/components/settings/browser-use-search.ts new file mode 100644 index 000000000..1574ae341 --- /dev/null +++ b/src/renderer/src/components/settings/browser-use-search.ts @@ -0,0 +1,39 @@ +import type { SettingsSearchEntry } from './settings-search' + +export const BROWSER_USE_PANE_SEARCH_ENTRIES: SettingsSearchEntry[] = [ + { + title: 'Enable Orca CLI', + description: 'Register the orca shell command so agents can drive the browser.', + keywords: ['browser use', 'cli', 'orca', 'path', 'command', 'shell', 'enable', 'setup'] + }, + { + title: 'Install Browser Use Skill', + description: 'Install the orca-cli agent skill so agents know how to use the browser.', + keywords: [ + 'browser use', + 'skill', + 'agent', + 'install', + 'orca-cli', + 'npx', + 'agent-browser', + 'automation' + ] + }, + { + title: 'Import Browser Cookies', + description: + 'Import cookies from Chrome, Edge, or other browsers so agents can reuse your logins.', + keywords: [ + 'browser use', + 'cookies', + 'session', + 'import', + 'login', + 'auth', + 'chrome', + 'edge', + 'arc' + ] + } +]