From 561093876ea44e0490b02c0d245ccf8b64118713 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 27 May 2024 02:53:36 -0700 Subject: [PATCH] Add default browser fallback to debugger launch flow (#44673) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44673 Changelog: [Internal] Reviewed By: hoxyq Differential Revision: D57726648 fbshipit-source-id: 66eaab1dd0d53fe2befb3dc96d5deb426b86e3e7 --- .../src/utils/DefaultBrowserLauncher.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/dev-middleware/src/utils/DefaultBrowserLauncher.js b/packages/dev-middleware/src/utils/DefaultBrowserLauncher.js index 94c745de3ffb2e..67e5b899c2c191 100644 --- a/packages/dev-middleware/src/utils/DefaultBrowserLauncher.js +++ b/packages/dev-middleware/src/utils/DefaultBrowserLauncher.js @@ -14,6 +14,7 @@ import type {BrowserLauncher} from '../types/BrowserLauncher'; const {spawn} = require('child_process'); const ChromeLauncher = require('chrome-launcher'); const {Launcher: EdgeLauncher} = require('chromium-edge-launcher'); +const open = require('open'); /** * Default `BrowserLauncher` implementation which opens URLs on the host @@ -31,15 +32,15 @@ const DefaultBrowserLauncher: BrowserLauncher = { // Locate Chrome installation path, will throw if not found chromePath = ChromeLauncher.getChromePath(); } catch (e) { + // Fall back to Microsoft Edge chromePath = EdgeLauncher.getFirstInstallation(); + } - if (chromePath == null) { - throw new Error( - 'Unable to find a browser on the host to open the debugger. ' + - 'Supported browsers: Google Chrome, Microsoft Edge.\n' + - url, - ); - } + if (chromePath == null) { + // Fall back to default browser - the frontend will warn if the browser + // is not supported. + await open(url); + return; } const chromeFlags = [`--app=${url}`, '--window-size=1200,600'];