diff --git a/packages/dev-middleware/src/__tests__/InspectorProxyCdpTransport-test.js b/packages/dev-middleware/src/__tests__/InspectorProxyCdpTransport-test.js index 7e33c2decb59..dd2d7f346c5d 100644 --- a/packages/dev-middleware/src/__tests__/InspectorProxyCdpTransport-test.js +++ b/packages/dev-middleware/src/__tests__/InspectorProxyCdpTransport-test.js @@ -21,7 +21,6 @@ import {createDeviceMock} from './InspectorDeviceUtils'; import {sendFromDebuggerToTarget} from './InspectorProtocolUtils'; import {withAbortSignalForEachTest} from './ResourceUtils'; import {withServerForEachTest} from './ServerUtils'; -import nullthrows from 'nullthrows'; import until from 'wait-for-expect'; // WebSocket is unreliable when using fake timers. @@ -155,136 +154,6 @@ describe.each(['HTTP', 'HTTPS'])( } }); - test('multiple debuggers to the same page on the same device', async () => { - let device, debugger1, debugger2; - try { - // Connect a device to the proxy. - device = await createDeviceMock( - `${serverRef.serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`, - autoCleanup.signal, - ); - // Capture a log of events so we can assert on their order later. - const events: Array< - | ConnectRequest - | DisconnectRequest - | {event: 'create-debugger-mock', name: string}, - > = []; - device.disconnect.mockImplementation(message => { - events.push(message); - }); - device.connect.mockImplementation(message => { - events.push(message); - }); - // Set up the page. - device.getPages.mockImplementation(() => [ - { - app: 'bar-app', - id: 'page1', - title: 'bar-title', - vm: 'bar-vm', - }, - ]); - let pageList: Array = []; - await until(async () => { - pageList = (await fetchJson( - `${serverRef.serverBaseUrl}/json`, - // $FlowFixMe[unclear-type] - )) as any; - expect(pageList).toHaveLength(1); - }); - const [{webSocketDebuggerUrl}] = pageList; - - // Connect the first debugger and send a message. - events.push({event: 'create-debugger-mock', name: 'debugger1'}); - debugger1 = await createDebuggerMock( - webSocketDebuggerUrl, - autoCleanup.signal, - ); - await sendFromDebuggerToTarget(debugger1, device, 'page1', { - method: 'Runtime.enable', - id: 0, - }); - - // Connect the second debugger. - events.push({event: 'create-debugger-mock', name: 'debugger2'}); - debugger2 = await createDebuggerMock( - webSocketDebuggerUrl, - autoCleanup.signal, - ); - - // The first debugger gets disconnected. TODO: In the future, we should - // amend the protocol to allow for multiple debuggers to connect at the - // same time. - await until(async () => { - expect([ - // CLOSING - 3, - // CLOSED - 4, - ]).toContain(debugger1.socket.readyState); - }); - - // Send a message from the second debugger. - await sendFromDebuggerToTarget(debugger2, device, 'page1', { - method: 'Debugger.enable', - id: 1, - }); - - // Check the order of `connect` and `disconnect` events received by the - // device. `create-debugger-mock` events are included for convenience. - expect(events).toEqual([ - { - event: 'create-debugger-mock', - name: 'debugger1', - }, - { - event: 'connect', - payload: { - pageId: 'page1', - sessionId: expect.any(String), - }, - }, - { - event: 'create-debugger-mock', - name: 'debugger2', - }, - { - // NOTE: For debugger1 - event: 'disconnect', - payload: { - pageId: 'page1', - sessionId: expect.any(String), - }, - }, - { - // NOTE: For debugger2 - event: 'connect', - payload: { - pageId: 'page1', - sessionId: expect.any(String), - }, - }, - ]); - // Verify that disconnect and second connect use different session IDs - // (disconnect is for first debugger, connect is for second debugger) - const disconnectEvent = nullthrows( - events.find(e => e.event === 'disconnect'), - ); - const connectEvents = events.filter(e => e.event === 'connect'); - expect(connectEvents).toHaveLength(2); - expect(disconnectEvent.payload.sessionId).toBe( - connectEvents[0].payload.sessionId, - ); - expect(disconnectEvent?.payload.sessionId).not.toBe( - connectEvents[1].payload.sessionId, - ); - } finally { - device?.close(); - debugger1?.close(); - debugger2?.close(); - } - }); - test('debugger connection to a nonexistent page is rejected', async () => { let device, debugger_; try { @@ -665,23 +534,19 @@ describe.each(['HTTP', 'HTTPS'])( } }); - test('page with supportsMultipleDebuggers allows concurrent debugger connections', async () => { + test('allows concurrent debugger connections to a page', async () => { let device, debugger1, debugger2; try { device = await createDeviceMock( `${serverRef.serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`, autoCleanup.signal, ); - // Page with supportsMultipleDebuggers capability device.getPages.mockImplementation(() => [ { app: 'bar-app', id: 'page1', title: 'bar-title', vm: 'bar-vm', - capabilities: { - supportsMultipleDebuggers: true, - }, }, ]); let pageList: Array = []; diff --git a/packages/dev-middleware/src/__tests__/InspectorProxyConcurrentSessions-test.js b/packages/dev-middleware/src/__tests__/InspectorProxyConcurrentSessions-test.js index 168bc20b42e4..fa6f7fd1b380 100644 --- a/packages/dev-middleware/src/__tests__/InspectorProxyConcurrentSessions-test.js +++ b/packages/dev-middleware/src/__tests__/InspectorProxyConcurrentSessions-test.js @@ -8,7 +8,11 @@ * @format */ -import type {JsonPagesListResponse} from '../inspector-proxy/types'; +import type { + ConnectRequest, + DisconnectRequest, + JsonPagesListResponse, +} from '../inspector-proxy/types'; import {fetchJson} from './FetchUtils'; import {createDebuggerMock} from './InspectorDebuggerUtils'; @@ -26,7 +30,7 @@ describe('inspector proxy concurrent sessions', () => { const autoCleanup = withAbortSignalForEachTest(); describe('enableStandaloneFuseboxShell experiment disabled', () => { - test('page reporting supportsMultipleDebuggers:true is treated as false', async () => { + test('connecting a second debugger disconnects the first', async () => { // Create a server with the experiment disabled const {server} = await createServer({ logger: undefined, @@ -39,20 +43,23 @@ describe('inspector proxy concurrent sessions', () => { let device, debugger1, debugger2; try { - // Connect a device with a page that explicitly reports supportsMultipleDebuggers: true device = await createDeviceMock( `${serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`, autoCleanup.signal, ); + const events: Array = []; + device.connect.mockImplementation(message => { + events.push(message); + }); + device.disconnect.mockImplementation(message => { + events.push(message); + }); device.getPages.mockImplementation(() => [ { id: 'page1', app: 'bar-app', title: 'bar-title', vm: 'bar-vm', - capabilities: { - supportsMultipleDebuggers: true, - }, }, ]); @@ -66,11 +73,6 @@ describe('inspector proxy concurrent sessions', () => { expect(pageList).toHaveLength(1); }); - // Verify the capability is reported as false in the page list - expect( - pageList[0].reactNative?.capabilities?.supportsMultipleDebuggers, - ).toBe(false); - const webSocketDebuggerUrl = pageList[0].webSocketDebuggerUrl; // Connect first debugger @@ -95,9 +97,23 @@ describe('inspector proxy concurrent sessions', () => { // Second debugger should be open expect(debugger2.socket.readyState).toBe(1); // OPEN - // Device should have received disconnect for first session and connect for second - await until(() => expect(device.disconnect).toHaveBeenCalledTimes(1)); - await until(() => expect(device.connect).toHaveBeenCalledTimes(2)); + // Device should receive disconnect for the first session before + // connect for the second + await until(() => expect(events).toHaveLength(3)); + const [connect1, disconnect1, connect2] = events; + expect(connect1).toEqual({ + event: 'connect', + payload: {pageId: 'page1', sessionId: expect.any(String)}, + }); + expect(disconnect1).toEqual({ + event: 'disconnect', + payload: {pageId: 'page1', sessionId: connect1.payload.sessionId}, + }); + expect(connect2).toEqual({ + event: 'connect', + payload: {pageId: 'page1', sessionId: expect.any(String)}, + }); + expect(connect2.payload.sessionId).not.toBe(connect1.payload.sessionId); } finally { device?.close(); debugger1?.close(); diff --git a/packages/dev-middleware/src/__tests__/InspectorProxyDeviceHandoff-test.js b/packages/dev-middleware/src/__tests__/InspectorProxyDeviceHandoff-test.js index e47c7a063e4f..7fd1e7fcef0c 100644 --- a/packages/dev-middleware/src/__tests__/InspectorProxyDeviceHandoff-test.js +++ b/packages/dev-middleware/src/__tests__/InspectorProxyDeviceHandoff-test.js @@ -151,7 +151,6 @@ describe('inspector-proxy device socket handoff', () => { test('device ID collision with multiple debuggers connected restores all connections', async () => { let device1, device2, debugger1, debugger2, webSocketDebuggerUrl; try { - // Connect device with a page that supports multiple debuggers ({ device: device1, pageList: [{webSocketDebuggerUrl}], @@ -161,9 +160,6 @@ describe('inspector-proxy device socket handoff', () => { { ...PAGE_DEFAULTS, vm: 'bar-vm', - capabilities: { - supportsMultipleDebuggers: true, - }, }, ], )); @@ -192,9 +188,6 @@ describe('inspector-proxy device socket handoff', () => { { ...PAGE_DEFAULTS, vm: 'bar-vm-updated', - capabilities: { - supportsMultipleDebuggers: true, - }, }, ], )); diff --git a/packages/dev-middleware/src/__tests__/InspectorProxyHttpApi-test.js b/packages/dev-middleware/src/__tests__/InspectorProxyHttpApi-test.js index d122bfb5f556..4b053e2edc2c 100644 --- a/packages/dev-middleware/src/__tests__/InspectorProxyHttpApi-test.js +++ b/packages/dev-middleware/src/__tests__/InspectorProxyHttpApi-test.js @@ -199,9 +199,7 @@ describe('inspector proxy HTTP API', () => { devtoolsFrontendUrl: expect.any(String), id: 'device1-page1', reactNative: { - capabilities: { - supportsMultipleDebuggers: false, - }, + capabilities: {}, logicalDeviceId: 'device1', }, title: 'bar-title', @@ -216,9 +214,7 @@ describe('inspector proxy HTTP API', () => { devtoolsFrontendUrl: expect.any(String), id: 'device2-page1', reactNative: { - capabilities: { - supportsMultipleDebuggers: false, - }, + capabilities: {}, logicalDeviceId: 'device2', }, title: 'bar-title', diff --git a/packages/dev-middleware/src/inspector-proxy/Device.js b/packages/dev-middleware/src/inspector-proxy/Device.js index 0ea5ef97e1f8..d690e25b4c17 100644 --- a/packages/dev-middleware/src/inspector-proxy/Device.js +++ b/packages/dev-middleware/src/inspector-proxy/Device.js @@ -369,10 +369,7 @@ export default class Device { // Clear any commands we were waiting on. this.#deviceEventReporter?.logDisconnection('debugger'); - // Check if this specific page supports multiple debuggers. - // If not (legacy mode), disconnect existing debuggers for THIS PAGE only - // before connecting the new one. - if (!this.#pageHasCapability(page, 'supportsMultipleDebuggers')) { + if (!this.#experiments.enableStandaloneFuseboxShell) { for (const [sid, conn] of this.#debuggerConnections) { if (conn.pageId === pageId) { this.#terminateDebuggerConnection( @@ -554,22 +551,11 @@ export default class Device { #handleMessageFromDevice(message: MessageFromDevice) { if (message.event === 'getPages') { // Preserve ordering - getPages guarantees addition order. - const shouldDisableMultipleDebuggers = - !this.#experiments.enableStandaloneFuseboxShell; this.#pages = new Map( - message.payload.map(({capabilities: rawCapabilities, ...page}) => { - const capabilities: TargetCapabilityFlags = - shouldDisableMultipleDebuggers - ? {...(rawCapabilities ?? {}), supportsMultipleDebuggers: false} - : (rawCapabilities ?? {}); - return [ - page.id, - { - ...page, - capabilities, - }, - ]; - }), + message.payload.map(({capabilities, ...page}) => [ + page.id, + {...page, capabilities: capabilities ?? {}}, + ]), ); if (message.payload.length !== this.#pages.size) { diff --git a/packages/dev-middleware/src/inspector-proxy/__docs__/README.md b/packages/dev-middleware/src/inspector-proxy/__docs__/README.md index 97cd4af56886..5c0b13e9f871 100644 --- a/packages/dev-middleware/src/inspector-proxy/__docs__/README.md +++ b/packages/dev-middleware/src/inspector-proxy/__docs__/README.md @@ -127,14 +127,10 @@ interface Page { capabilities?: { nativePageReloads?: boolean; // Target keeps the socket open across reloads nativeSourceCodeFetching?: boolean; // Target supports Network.loadNetworkResource - supportsMultipleDebuggers?: boolean; // Supports concurrent debugger sessions }; } ``` -**Note**: The value of `supportsMultipleDebuggers` SHOULD be consistent across -all pages for a given device. - ### Connection Lifecycle **Device Registration:** @@ -186,29 +182,17 @@ its page, if `sessionId` is omitted). #### Multi-Debugger Support -Multiple debuggers can connect simultaneously to the same page when **both** the -proxy and device support session multiplexing: - -1. **Session IDs**: The proxy assigns a unique, non-empty `sessionId` to each - debugger connection. All messages include this `sessionId` for routing. This - SHOULD be a UUID or other suitably unique and ephemeral identifier. - -2. **Capability Detection**: Devices report `supportsMultipleDebuggers: true` in - their page capabilities to indicate session support. - -3. **Backwards Compatibility**: Legacy devices ignore `sessionId` fields in - incoming messages and don't include them in responses. +Multiple debuggers can connect simultaneously to the same page. The proxy +assigns a unique, non-empty `sessionId` to each debugger connection. All +messages include this `sessionId` for routing. This SHOULD be a UUID or other +suitably unique and ephemeral identifier. #### Connection Rules -1. **Session-Capable Device**: Multiple debuggers can connect to the same page +1. **Concurrent Sessions**: Multiple debuggers can connect to the same page simultaneously. Each connection has an independent session. -2. **Legacy Device (no `supportsMultipleDebuggers`)**: New debugger connections - to an already-connected page disconnect the existing debugger. The proxy MUST - NOT allow multiple debuggers to connect to the same page. - -3. **Device Reconnection**: If a device reconnects with the same `device` ID +2. **Device Reconnection**: If a device reconnects with the same `device` ID while debugger connections to the same logical device are open in the proxy, the proxy may attempt to preserve active debugger sessions by forwarding them to the new device. diff --git a/packages/dev-middleware/src/inspector-proxy/types.js b/packages/dev-middleware/src/inspector-proxy/types.js index 1c937eca6fe8..9a1abe384215 100644 --- a/packages/dev-middleware/src/inspector-proxy/types.js +++ b/packages/dev-middleware/src/inspector-proxy/types.js @@ -30,16 +30,6 @@ export type TargetCapabilityFlags = Readonly<{ * In the proxy, this disables source fetching emulation and host rewrites. */ nativeSourceCodeFetching?: boolean, - - /** - * The target supports multiple concurrent debugger connections. - * - * When true, the proxy allows multiple debuggers to connect to the same - * page simultaneously, each identified by a unique session ID. - * When false (default/legacy), connecting a new debugger disconnects - * any existing debugger connection to that page. - */ - supportsMultipleDebuggers?: boolean, }>; // Page information received from the device. New page is created for