From 48fe70b8c84bbf273ad418f6c4fe88fd81f79fe6 Mon Sep 17 00:00:00 2001 From: Pierre Bertet Date: Wed, 1 Mar 2017 20:34:54 +0000 Subject: [PATCH 1/2] Fix openBrowser() when BROWSER=open on macOS --- packages/react-dev-utils/openBrowser.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/openBrowser.js b/packages/react-dev-utils/openBrowser.js index a3623515e0a..24372275227 100644 --- a/packages/react-dev-utils/openBrowser.js +++ b/packages/react-dev-utils/openBrowser.js @@ -50,10 +50,16 @@ function openBrowser(url) { } } + // On OS X, check if BROWSER has been set to "open", + // and if so, do not pass it to the opn() options. + const isBrowserValid = !( + process.platform === 'darwin' && browser === 'open' + ); + // Fallback to opn // (It will always open new tab) try { - var options = {app: browser}; + var options = {app: isBrowserValid? browser : ''}; opn(url, options).catch(() => {}); // Prevent `unhandledRejection` error. return true; } catch (err) { From 967db643fc9f85e1f8c84fff4708307c5f006e4f Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 5 Mar 2017 16:37:46 +0000 Subject: [PATCH 2/2] Tweaks --- packages/react-dev-utils/openBrowser.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/react-dev-utils/openBrowser.js b/packages/react-dev-utils/openBrowser.js index 24372275227..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,16 +50,18 @@ function openBrowser(url) { } } - // On OS X, check if BROWSER has been set to "open", - // and if so, do not pass it to the opn() options. - const isBrowserValid = !( - process.platform === 'darwin' && browser === 'open' - ); - + // 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 { - var options = {app: isBrowserValid? browser : ''}; + var options = {app: browser}; opn(url, options).catch(() => {}); // Prevent `unhandledRejection` error. return true; } catch (err) {