resolveRenderBrowser locates the browser binary to drive, in order of precedence: explicit CHATCLI_WEBFETCH_RENDER_BROWSER path, rod's own system lookup (Chrome/Chromium/Edge), Chromium-based fallbacks rod does not know about (Brave), and finally the opt-in auto-provision. Empty bin with ok=true mea
()
| 125 | // not know about (Brave), and finally the opt-in auto-provision. Empty bin |
| 126 | // with ok=true means "let rod download its pinned snapshot". |
| 127 | func resolveRenderBrowser() (bin string, ok bool, err error) { |
| 128 | if explicit := strings.TrimSpace(os.Getenv("CHATCLI_WEBFETCH_RENDER_BROWSER")); explicit != "" { |
| 129 | // Canonicalize and require an absolute path: the override names one |
| 130 | // specific binary, so relative segments (PATH ambiguity, ../ |
| 131 | // traversal) are rejected rather than resolved. |
| 132 | explicit = filepath.Clean(explicit) |
| 133 | if !filepath.IsAbs(explicit) { |
| 134 | return "", false, fmt.Errorf("render browser override %q must be an absolute path (check CHATCLI_WEBFETCH_RENDER_BROWSER)", explicit) |
| 135 | } |
| 136 | if _, statErr := os.Stat(explicit); statErr != nil { |
| 137 | return "", false, fmt.Errorf("render browser override %q is not accessible (check CHATCLI_WEBFETCH_RENDER_BROWSER): %w", explicit, statErr) |
| 138 | } |
| 139 | return explicit, true, nil |
| 140 | } |
| 141 | if path, found := systemBrowserLookup(); found { |
| 142 | return path, true, nil |
| 143 | } |
| 144 | if path, found := lookupFallbackBrowser(); found { |
| 145 | return path, true, nil |
| 146 | } |
| 147 | if boolEnvTrue("CHATCLI_WEBFETCH_RENDER_AUTOPROVISION") { |
| 148 | return "", true, nil |
| 149 | } |
| 150 | return "", false, fmt.Errorf( |
| 151 | "no Chrome/Chromium/Edge found for JS rendering: install one, point CHATCLI_WEBFETCH_RENDER_BROWSER at a Chromium-based binary, or set CHATCLI_WEBFETCH_RENDER_AUTOPROVISION=true to let chatcli download a pinned Chromium (~150 MB, one time)") |
| 152 | } |
| 153 | |
| 154 | // systemBrowserLookup locates a rod-known system browser. A variable so |
| 155 | // tests can simulate hosts with no browser installed — rod's LookPath |