()
| 13 | * @returns True if the tool should attempt to launch a browser. |
| 14 | */ |
| 15 | export function shouldAttemptBrowserLaunch(): boolean { |
| 16 | // A list of browser names that indicate we should not attempt to open a |
| 17 | // web browser for the user. |
| 18 | const browserBlocklist = ['www-browser']; |
| 19 | const browserEnv = process.env['BROWSER']; |
| 20 | if (browserEnv && browserBlocklist.includes(browserEnv)) { |
| 21 | return false; |
| 22 | } |
| 23 | // Common environment variables used in CI/CD or other non-interactive shells. |
| 24 | if ( |
| 25 | process.env['CI'] || |
| 26 | process.env['DEBIAN_FRONTEND'] === 'noninteractive' |
| 27 | ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | // The presence of SSH_CONNECTION indicates a remote session. |
| 32 | // We should not attempt to launch a browser unless a display is explicitly available |
| 33 | // (checked below for Linux). |
| 34 | const isSSH = !!process.env['SSH_CONNECTION']; |
| 35 | |
| 36 | // On Linux, the presence of a display server is a strong indicator of a GUI. |
| 37 | if (process.platform === 'linux') { |
| 38 | // These are environment variables that can indicate a running compositor on |
| 39 | // Linux. |
| 40 | const displayVariables = ['DISPLAY', 'WAYLAND_DISPLAY', 'MIR_SOCKET']; |
| 41 | const hasDisplay = displayVariables.some((v) => !!process.env[v]); |
| 42 | if (!hasDisplay) { |
| 43 | return false; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // If in an SSH session on a non-Linux OS (e.g., macOS), don't launch browser. |
| 48 | // The Linux case is handled above (it's allowed if DISPLAY is set). |
| 49 | if (isSSH && process.platform !== 'linux') { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // For non-Linux OSes, we generally assume a GUI is available |
| 54 | // unless other signals (like SSH) suggest otherwise. |
| 55 | // The `open` command's error handling will catch final edge cases. |
| 56 | return true; |
| 57 | } |
no outgoing calls
no test coverage detected