/** * Open a URL in the user's default browser, best-effort. * * Used by `spectral desktop` (the browser *is* the desktop UI now that the * Electron shell is gone) and kept separate from `auth-helper.ts`'s inline * variant so both the login flow and the desktop launcher can share one * implementation. * * Never throws: headless boxes, containers and CI have no browser and no * `xdg-open`. Callers print the URL themselves when `opened` is false, so a * missing browser degrades to "copy this link" instead of a failed command. * * Two hard rules, because this hands a URL to a process launcher: * - only `http(s)` URLs are accepted — anything else (`file:`, `javascript:`, * a bare string with shell metacharacters) is refused before a process is * spawned, and * - the fallback launches the platform opener by argv, never through a shell, * so no quoting or re-interpretation of the URL can occur. */ import { spawn } from "node:child_process"; export interface OpenBrowserResult { opened: boolean; /** Platform command that was attempted — surfaced in failure messages. */ command: string; error?: string; } export interface OpenBrowserDeps { /** Injectable spawn (tests). */ spawn?: typeof spawn; /** Injectable `open` module loader (tests). */ loadOpen?: () => Promise; /** How long to wait for a launched opener to confirm (defaults to 2 s). */ confirmTimeoutMs?: number; } /** How long an opener child gets to report a clean exit. */ export declare const OPEN_CONFIRM_TIMEOUT_MS = 2000; export declare function isSafeBrowserUrl(url: string): boolean; /** Build the shell command for the current platform (mirrors auth-helper). */ export declare function browserOpenCommand(url: string, platform?: NodeJS.Platform): string; /** * The same launch as argv for `spawn(..., { shell: false })`. `start` is a * `cmd.exe` builtin, so Windows goes through `cmd /c start` with the URL as a * separate argument — still no shell string to inject into. */ export declare function browserOpenArgv(url: string, platform?: NodeJS.Platform): { command: string; args: string[]; }; /** * Best-effort browser open. Tries the `open` npm package first (it handles * flatpak/WSL and sandbox edge cases) but only accepts it once its child exits * 0, then the plain platform opener by argv. */ export declare function openBrowser(url: string, platform?: NodeJS.Platform, deps?: OpenBrowserDeps): Promise; //# sourceMappingURL=open-browser.d.ts.map