From d07accbd0981de1de1d7c010042f26779e4d9574 Mon Sep 17 00:00:00 2001 From: Pierre Bertet Date: Sun, 5 Mar 2017 16:42:13 +0000 Subject: [PATCH] Fix openBrowser() when BROWSER=open on macOS (#1690) * Fix openBrowser() when BROWSER=open on macOS * Tweaks --- packages/react-dev-utils/openBrowser.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/openBrowser.js b/packages/react-dev-utils/openBrowser.js index a3623515e0a..4577dc93b79 100644 --- a/packages/react-dev-utils/openBrowser.js +++ b/packages/react-dev-utils/openBrowser.js @@ -17,7 +17,7 @@ function openBrowser(url) { // Attempt to honor this environment variable. // It is specific to the operating system. // See https://github.com/sindresorhus/opn#app for documentation. - const browser = process.env.BROWSER; + let browser = process.env.BROWSER; // Special case: BROWSER="none" will prevent opening completely. if (browser === 'none') { @@ -50,6 +50,14 @@ function openBrowser(url) { } } + // Another special case: on OS X, check if BROWSER has been set to "open". + // In this case, instead of passing `open` to `opn` (which won't work), + // just ignore it (thus ensuring the intended behavior, i.e. opening the system browser): + // https://github.com/facebookincubator/create-react-app/pull/1690#issuecomment-283518768 + if (process.platform === 'darwin' && browser === 'open') { + browser = undefined; + } + // Fallback to opn // (It will always open new tab) try {