Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('getDevToolsFrontendUrl', () => {
enableOpenDebuggerRedirect: false,
};

describe('relative: false (default)', () => {
describe('relative: false, launchId: undefined (default)', () => {
test('should return a valid url for all experiments off', async () => {
const actual = getDevToolsFrontendUrl(
experiments,
Expand Down Expand Up @@ -128,4 +128,61 @@ describe('getDevToolsFrontendUrl', () => {
);
});
});

describe('launchId: non-null', () => {
const launchId = 'dG8gdGhlIG1vb24h%21';

test('should return a valid url for all experiments off', async () => {
const actual = getDevToolsFrontendUrl(
experiments,
webSocketDebuggerUrl,
devServerUrl,
{
launchId,
},
);
const url = new URL(actual);
expect(url.pathname).toBe('/debugger-frontend/rn_inspector.html');
expect(url.searchParams.get('ws')).toBe(
'/inspector/debug?device=1a9372c&page=-1',
);
expect(url.searchParams.get('launchId')).toBe(launchId);
});

test('should return a valid url for enableNetworkInspector experiment on', async () => {
const actual = getDevToolsFrontendUrl(
{...experiments, enableNetworkInspector: true, enableNewDebugger: true},
webSocketDebuggerUrl,
devServerUrl,
{
launchId,
},
);
const url = new URL(actual);
expect(url.pathname).toBe('/debugger-frontend/rn_inspector.html');
expect(url.searchParams.get('unstable_enableNetworkPanel')).toBe('true');
expect(url.searchParams.get('ws')).toBe(
'/inspector/debug?device=1a9372c&page=-1',
);
expect(url.searchParams.get('launchId')).toBe(launchId);
});

test('should return a full WS URL if on a different host than the dev server', () => {
const otherWebSocketDebuggerUrl =
'ws://localhost:8082/inspector/debug?device=1a9372c&page=-1';
const actual = getDevToolsFrontendUrl(
experiments,
otherWebSocketDebuggerUrl,
devServerUrl,
{
launchId,
},
);
const url = new URL(actual);
expect(url.searchParams.get('ws')).toBe(
'localhost:8082/inspector/debug?device=1a9372c&page=-1',
);
expect(url.searchParams.get('launchId')).toBe(launchId);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {NextHandleFunction} from 'connect';
import type {IncomingMessage, ServerResponse} from 'http';

import getDevToolsFrontendUrl from '../utils/getDevToolsFrontendUrl';
import crypto from 'crypto';
import url from 'url';

const debuggerInstances = new Map<string, ?LaunchedBrowser>();
Expand Down Expand Up @@ -107,6 +108,8 @@ export default function openDebuggerMiddleware({
return;
}

const launchId = crypto.randomUUID();

try {
switch (launchType) {
case 'launch':
Expand All @@ -122,6 +125,7 @@ export default function openDebuggerMiddleware({
experiments,
target.webSocketDebuggerUrl,
serverBaseUrl,
{launchId},
),
),
);
Expand All @@ -133,7 +137,7 @@ export default function openDebuggerMiddleware({
experiments,
target.webSocketDebuggerUrl,
serverBaseUrl,
{relative: true},
{relative: true, launchId},
),
});
res.end();
Expand Down
4 changes: 4 additions & 0 deletions packages/dev-middleware/src/utils/getDevToolsFrontendUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function getDevToolsFrontendUrl(
devServerUrl: string,
options?: $ReadOnly<{
relative?: boolean,
launchId?: string,
}>,
): string {
const wsParam = getWsParam({
Expand All @@ -38,6 +39,9 @@ export default function getDevToolsFrontendUrl(
if (experiments.enableNetworkInspector) {
searchParams.append('unstable_enableNetworkPanel', 'true');
}
if (options?.launchId != null && options.launchId !== '') {
searchParams.append('launchId', options.launchId);
}

return appUrl + '?' + searchParams.toString();
}
Expand Down