// ============================================================================= // Open a URL in the user's default browser. Platform-specific, no dependencies. // ============================================================================= import { execFile } from "node:child_process"; const CONTROL_CHAR_REGEX = /[\u0000-\u001F\u007F]/; function isSafeHttpUrl(url: string): boolean { if (!url || CONTROL_CHAR_REGEX.test(url)) return false; try { const parsed = new URL(url); return parsed.protocol === "http:" || parsed.protocol === "https:"; } catch { return false; } } export function openUrl(url: string): void { if (!isSafeHttpUrl(url)) { return; } const platform = process.platform; let command = "xdg-open"; let args = [url]; if (platform === "darwin") { command = "open"; } else if (platform === "win32") { command = "rundll32"; args = ["url.dll,FileProtocolHandler", url]; } execFile(command, args, (err) => { if (err) { // Silently fail — the URL is always printed as fallback } }); }