From bfeb1c98aa23f018a32e32055f5b449526a76dd8 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 24 Jun 2024 08:24:29 -0700 Subject: [PATCH 1/2] Inspector: Enforce device and appId filters if both are given to /open-debugger Summary: Previously, if the `/open-debugger` endpoint was provided with both `device` and `appId` query params, we would: - Try to find a target with a matching `device` (note that these logical "devices" are unique per-app) - if found, use it. Otherwise, - Try to find a target with a matching `appId` - if found, use that. This could go "wrong" in two ways: - If a `device` is given with a spurious `appId`, we'd open to a target with an `appId` differing from the one specified. - If the `device` has gone away but there is a different target with the same app, we'd use that as a fallback (right app, wrong device). This applies the filters more strictly so that if both are given, both must match. Changelog: [General][Changed]: Inspector: Enforce device and appId filters if both are given to /open-debugger Differential Revision: D58951952 --- .../src/middleware/openDebuggerMiddleware.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js index 7aa102ab7baa..413ce6447e1d 100644 --- a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js +++ b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js @@ -78,14 +78,11 @@ export default function openDebuggerMiddleware({ (launchType === 'launch' ? 'Launching' : 'Redirecting to') + ' JS debugger (experimental)...', ); - if (typeof device === 'string') { - target = targets.find( - _target => _target.reactNative.logicalDeviceId === device, - ); - } - if (!target && typeof appId === 'string') { - target = targets.find(_target => _target.description === appId); - } + target = targets.find( + _target => + (appId == null || _target.description === appId) && + (device == null || _target.reactNative.logicalDeviceId === device), + ); } else if (targets.length > 0) { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') + From 54b03612f7298bd6a155265054e3875756219941 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 24 Jun 2024 08:38:23 -0700 Subject: [PATCH 2/2] Inspector: Support `/open-debugger` specifying `target` param (#45138) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45138 Add a new `/open-debugger` endpoint format that allows specifying `target` - the proxy-unique target `id`. This is logically equivalent to specifying both device and page. Changelog: [General][Added]: Inspector: Support `/open-debugger` specifying `target` param Differential Revision: D58950622 --- .../src/middleware/openDebuggerMiddleware.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js index 413ce6447e1d..56793f983bd9 100644 --- a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js +++ b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js @@ -59,7 +59,14 @@ export default function openDebuggerMiddleware({ appId, device, launchId, - }: {appId?: string, device?: string, launchId?: string, ...} = query; + target: targetId, + }: { + appId?: string, + device?: string, + launchId?: string, + target?: string, + ... + } = query; const targets = inspectorProxy.getPageDescriptions().filter( // Only use targets with better reloading support @@ -73,13 +80,18 @@ export default function openDebuggerMiddleware({ const launchType: 'launch' | 'redirect' = req.method === 'POST' ? 'launch' : 'redirect'; - if (typeof appId === 'string' || typeof device === 'string') { + if ( + typeof targetId === 'string' || + typeof appId === 'string' || + typeof device === 'string' + ) { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') + ' JS debugger (experimental)...', ); target = targets.find( _target => + (targetId == null || _target.id === targetId) && (appId == null || _target.description === appId) && (device == null || _target.reactNative.logicalDeviceId === device), );