/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/dev-middleware/src/utils/DefaultBrowserLauncher.js
92 строки
2 KB
Moti Zilberman
Work around Electron Windows command-line args quirk (#53510)
28 авг 2025, 20:27
28 авг 2025, 20:27
d1a9990
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ import type {DebuggerShellPreparationResult} from '../'; const { unstable_prepareDebuggerShell, unstable_spawnDebuggerShellWithArgs, } = require('@react-native/debugger-shell'); 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 * machine. */ const DefaultBrowserLauncher = { /** * Attempt to open the debugger frontend in a Google Chrome or Microsoft Edge * app window. */ launchDebuggerAppWindow: async (url: string): Promise<void> => { let chromePath; try { // 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) { // 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']; return new Promise((resolve, reject) => { const childProcess = spawn(chromePath, chromeFlags, { detached: true, stdio: 'ignore', }); childProcess.on('data', () => { resolve(); }); childProcess.on('close', (code: number) => { if (code !== 0) { reject( new Error( `Failed to launch debugger app window: ${chromePath} exited with code ${code}`, ), ); } }); }); }, async unstable_showFuseboxShell( url: string, windowKey: string, ): Promise<void> { return await unstable_spawnDebuggerShellWithArgs( ['--frontendUrl=' + url, '--windowKey=' + windowKey], { mode: 'detached', flavor: process.env.RNDT_DEV === '1' ? 'dev' : 'prebuilt', }, ); }, async unstable_prepareFuseboxShell(): Promise<DebuggerShellPreparationResult> { return await unstable_prepareDebuggerShell( process.env.RNDT_DEV === '1' ? 'dev' : 'prebuilt', ); }, }; export default DefaultBrowserLauncher;