Skip to content

Commit

Permalink
Add support for launch ID (facebook#43585)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

Related PR: facebookexperimental/rn-chrome-devtools-frontend#27

Differential Revision: D55164646
  • Loading branch information
EdmondChuiHW authored and facebook-github-bot committed Mar 21, 2024
1 parent 0267ca0 commit 4dd060a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
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: non-null (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);
});
});
});
10 changes: 8 additions & 2 deletions packages/dev-middleware/src/middleware/openDebuggerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export default function openDebuggerMiddleware({
(experiments.enableOpenDebuggerRedirect && req.method === 'GET')
) {
const {query} = url.parse(req.url, true);
const {appId, device}: {appId?: string, device?: string, ...} = query;
const {
appId,
device,
launchId,
}: {appId?: string, device?: string, launchId?: string, ...} = query;
console.log('query', query);

const targets = inspectorProxy.getPageDescriptions().filter(
// Only use targets with better reloading support
Expand Down Expand Up @@ -122,6 +127,7 @@ export default function openDebuggerMiddleware({
experiments,
target.webSocketDebuggerUrl,
serverBaseUrl,
{launchId},
),
),
);
Expand All @@ -133,7 +139,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

0 comments on commit 4dd060a

Please sign in to comment.