diff --git a/code/core/src/core-server/utils/open-browser/open-in-browser.ts b/code/core/src/core-server/utils/open-browser/open-in-browser.ts index 8e1475c8d22e..8cbd3a765969 100644 --- a/code/core/src/core-server/utils/open-browser/open-in-browser.ts +++ b/code/core/src/core-server/utils/open-browser/open-in-browser.ts @@ -6,28 +6,41 @@ import { dedent } from 'ts-dedent'; import { openBrowser } from './opener'; export async function openInBrowser(address: string) { - let errorOccured = false; + let errorOccurred = false; + let openBrowserResult: boolean | undefined; try { - await openBrowser(address); + openBrowserResult = await openBrowser(address); } catch (error) { - errorOccured = true; + errorOccurred = true; + } + + // If openBrowser returned false, it means BROWSER=none was set intentionally + // In this case, don't try to open a browser at all (fixes #24191) + if (openBrowserResult === false) { + return; } try { - if (errorOccured) { + if (errorOccurred) { await open(address); - errorOccured = false; + errorOccurred = false; } } catch (error) { - errorOccured = true; + errorOccurred = true; } - if (errorOccured) { + if (errorOccurred) { + const browserEnv = process.env.BROWSER; + const browserHint = browserEnv + ? `\n\nNote: BROWSER environment variable is set to "${browserEnv}". ` + + `To disable browser opening, use BROWSER=none or the --ci flag.` + : ''; + logger.error(dedent` Could not open ${address} inside a browser. If you're running this command inside a docker container or on a CI, you need to pass the '--ci' flag to prevent opening a - browser by default. + browser by default.${browserHint} `); } }