diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index 96d224a7cb19fb..d0897f2eee313a 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -149,6 +149,9 @@ export default class InspectorProxy implements InspectorProxyQueries { webSocketDebuggerUrl, vm: page.vm, deviceName: device.getName(), + reactNative: { + logicalDeviceId: deviceId, + }, }; } diff --git a/packages/dev-middleware/src/inspector-proxy/types.js b/packages/dev-middleware/src/inspector-proxy/types.js index dc52c5d2cb604d..2d326ded6d44b0 100644 --- a/packages/dev-middleware/src/inspector-proxy/types.js +++ b/packages/dev-middleware/src/inspector-proxy/types.js @@ -79,6 +79,10 @@ export type PageDescription = { devtoolsFrontendUrl: string, type: string, webSocketDebuggerUrl: string, + // Metadata specific to React Native + reactNative: { + logicalDeviceId: string, + }, ... }; export type JsonPagesListResponse = Array; diff --git a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js index 14ee05051a6099..6767a45d086523 100644 --- a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js +++ b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js @@ -57,7 +57,7 @@ export default function openDebuggerMiddleware({ (experiments.enableOpenDebuggerRedirect && req.method === 'GET') ) { const {query} = url.parse(req.url, true); - const {appId} = query; + const {appId, device}: {appId?: string, device?: string, ...} = query; const targets = inspectorProxy.getPageDescriptions().filter( // Only use targets with better reloading support @@ -69,12 +69,19 @@ export default function openDebuggerMiddleware({ const launchType: 'launch' | 'redirect' = req.method === 'POST' ? 'launch' : 'redirect'; - if (typeof appId === 'string') { + if (typeof appId === 'string' || typeof device === 'string') { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') + ' JS debugger (experimental)...', ); - target = targets.find(_target => _target.description === appId); + if (typeof device === 'string') { + target = targets.find( + _target => _target.reactNative.logicalDeviceId === device, + ); + } + if (!target && typeof appId === 'string') { + target = targets.find(_target => _target.description === appId); + } } else { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') + @@ -101,9 +108,13 @@ export default function openDebuggerMiddleware({ try { switch (launchType) { case 'launch': - await debuggerInstances.get(appId)?.kill(); + const frontendInstanceId = + device != null + ? 'device:' + device + : 'app:' + (appId ?? ''); + await debuggerInstances.get(frontendInstanceId)?.kill(); debuggerInstances.set( - appId, + frontendInstanceId, await browserLauncher.launchDebuggerAppWindow( getDevToolsFrontendUrl( target.webSocketDebuggerUrl, @@ -130,7 +141,8 @@ export default function openDebuggerMiddleware({ type: 'launch_debugger_frontend', launchType, status: 'success', - appId, + appId: appId ?? null, + deviceId: device ?? null, }); return; } catch (e) { diff --git a/packages/dev-middleware/src/types/EventReporter.js b/packages/dev-middleware/src/types/EventReporter.js index ec8e77d521b0fc..51ae36d081dd45 100644 --- a/packages/dev-middleware/src/types/EventReporter.js +++ b/packages/dev-middleware/src/types/EventReporter.js @@ -36,7 +36,7 @@ export type ReportableEvent = type: 'launch_debugger_frontend', launchType: 'launch' | 'redirect', ... - | SuccessResult<{appId: string}> + | SuccessResult<{appId: string | null, deviceId: string | null}> | ErrorResult | CodedErrorResult<'NO_APPS_FOUND'>, }