MCPcopy Index your code
hub / github.com/react/create-react-app / startBrowserProcess

Function startBrowserProcess

packages/react-dev-utils/openBrowser.js:67–132  ·  view source on GitHub ↗
(browser, url, args)

Source from the content-addressed store, hash-verified

65}
66
67function startBrowserProcess(browser, url, args) {
68 // If we're on OS X, the user hasn't specifically
69 // requested a different browser, we can try opening
70 // Chrome with AppleScript. This lets us reuse an
71 // existing tab when possible instead of creating a new one.
72 const shouldTryOpenChromiumWithAppleScript =
73 process.platform === 'darwin' &&
74 (typeof browser !== 'string' || browser === OSX_CHROME);
75
76 if (shouldTryOpenChromiumWithAppleScript) {
77 // Will use the first open browser found from list
78 const supportedChromiumBrowsers = [
79 'Google Chrome Canary',
80 'Google Chrome',
81 'Microsoft Edge',
82 'Brave Browser',
83 'Vivaldi',
84 'Chromium',
85 ];
86
87 for (let chromiumBrowser of supportedChromiumBrowsers) {
88 try {
89 // Try our best to reuse existing tab
90 // on OSX Chromium-based browser with AppleScript
91 execSync('ps cax | grep "' + chromiumBrowser + '"');
92 execSync(
93 'osascript openChrome.applescript "' +
94 encodeURI(url) +
95 '" "' +
96 chromiumBrowser +
97 '"',
98 {
99 cwd: __dirname,
100 stdio: 'ignore',
101 }
102 );
103 return true;
104 } catch (err) {
105 // Ignore errors.
106 }
107 }
108 }
109
110 // Another special case: on OS X, check if BROWSER has been set to "open".
111 // In this case, instead of passing `open` to `opn` (which won't work),
112 // just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
113 // https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
114 if (process.platform === 'darwin' && browser === 'open') {
115 browser = undefined;
116 }
117
118 // If there are arguments, they must be passed as array with the browser
119 if (typeof browser === 'string' && args.length > 0) {
120 browser = [browser].concat(args);
121 }
122
123 // Fallback to open
124 // (It will always open new tab)

Callers 1

openBrowserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected