diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index 96d224a7cb19fb..f19bd719b68767 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -149,6 +149,7 @@ export default class InspectorProxy implements InspectorProxyQueries { webSocketDebuggerUrl, vm: page.vm, deviceName: device.getName(), + rnDeviceId: deviceId, }; } diff --git a/packages/dev-middleware/src/inspector-proxy/types.js b/packages/dev-middleware/src/inspector-proxy/types.js index dc52c5d2cb604d..026f395fc41a0b 100644 --- a/packages/dev-middleware/src/inspector-proxy/types.js +++ b/packages/dev-middleware/src/inspector-proxy/types.js @@ -79,6 +79,7 @@ export type PageDescription = { devtoolsFrontendUrl: string, type: string, webSocketDebuggerUrl: string, + rnDeviceId: 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..8371c0ec4da548 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,17 @@ 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.rnDeviceId === device); + } + if (!target && typeof appId === 'string') { + target = targets.find(_target => _target.description === appId); + } } else { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') + @@ -101,9 +106,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 +139,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'>, }