Skip to content

Commit

Permalink
Inspector: Support /open-debugger specifying target param (facebo…
Browse files Browse the repository at this point in the history
…ok#45138)

Summary:
Pull Request resolved: facebook#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
  • Loading branch information
robhogan authored and facebook-github-bot committed Jun 24, 2024
1 parent b709831 commit 246d1c8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/dev-middleware/src/middleware/openDebuggerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,25 +76,21 @@ export default function openDebuggerMiddleware({
);

let target;
let preciseTarget = true;

const launchType: 'launch' | 'redirect' =
req.method === 'POST' ? 'launch' : 'redirect';

if (typeof appId === 'string' || typeof device === 'string') {
logger?.info(
(launchType === 'launch' ? 'Launching' : 'Redirecting to') +
' JS debugger (experimental)...',
);
if (typeof targetId === 'string') {
target = targets.find(_target => _target.id === targetId);
} else if (typeof appId === 'string' || typeof device === 'string') {
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') +
` JS debugger${targets.length === 1 ? '' : ' for most recently connected target'}...`,
);
preciseTarget = targets.length === 1;
target = targets[targets.length - 1];
}

Expand All @@ -106,6 +109,11 @@ export default function openDebuggerMiddleware({
return;
}

logger?.info(
(launchType === 'launch' ? 'Launching' : 'Redirecting to') +
` JS debugger (Experimental) ${preciseTarget ? '' : ' for most recently connected target'}...`,
);

const useFuseboxEntryPoint =
target.reactNative.capabilities?.prefersFuseboxFrontend;

Expand Down

0 comments on commit 246d1c8

Please sign in to comment.