@react-native/dev-middleware 0.85.0-nightly-20260126-490c5e8dc → 0.85.0-nightly-20260128-36f07a1b2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import type { EventReporter } from "../types/EventReporter";
12
+ import type { Experiments } from "../types/Experiments";
12
13
  import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
13
14
  import type { Page } from "./types";
14
15
  import WS from "ws";
@@ -29,6 +30,7 @@ export type DeviceOptions = Readonly<{
29
30
  deviceRelativeBaseUrl: URL;
30
31
  serverRelativeBaseUrl: URL;
31
32
  isProfilingBuild: boolean;
33
+ experiments: Experiments;
32
34
  }>;
33
35
  /**
34
36
  * Device class represents single device connection to Inspector Proxy. Each device
@@ -8,6 +8,7 @@ var _CdpDebugLogging = _interopRequireDefault(require("./CdpDebugLogging"));
8
8
  var _DeviceEventReporter = _interopRequireDefault(
9
9
  require("./DeviceEventReporter"),
10
10
  );
11
+ var _crypto = _interopRequireDefault(require("crypto"));
11
12
  var _invariant = _interopRequireDefault(require("invariant"));
12
13
  var _ws = _interopRequireDefault(require("ws"));
13
14
  function _interopRequireDefault(e) {
@@ -34,7 +35,7 @@ class Device {
34
35
  #app;
35
36
  #deviceSocket;
36
37
  #pages = new Map();
37
- #debuggerConnection = null;
38
+ #debuggerConnections = new Map();
38
39
  #lastConnectedLegacyReactNativePage = null;
39
40
  #isLegacyPageReloading = false;
40
41
  #lastGetPagesMessage = "";
@@ -42,11 +43,12 @@ class Device {
42
43
  #deviceEventReporter;
43
44
  #pagesPollingIntervalId;
44
45
  #createCustomMessageHandler;
45
- #connectedPageIds = new Set();
46
46
  #deviceRelativeBaseUrl;
47
47
  #serverRelativeBaseUrl;
48
48
  #cdpDebugLogging;
49
+ #experiments;
49
50
  constructor(deviceOptions) {
51
+ this.#experiments = deviceOptions.experiments;
50
52
  this.#dangerouslyConstruct(deviceOptions);
51
53
  }
52
54
  #dangerouslyConstruct({
@@ -124,14 +126,27 @@ class Device {
124
126
  }
125
127
  });
126
128
  }
127
- #terminateDebuggerConnection(code, reason) {
128
- const debuggerConnection = this.#debuggerConnection;
129
- if (debuggerConnection) {
130
- this.#sendDisconnectEventToDevice(
131
- this.#mapToDevicePageId(debuggerConnection.pageId),
132
- );
133
- debuggerConnection.socket.close(code, reason);
134
- this.#debuggerConnection = null;
129
+ #terminateDebuggerConnection(code, reason, sessionId) {
130
+ if (sessionId != null) {
131
+ const debuggerConnection = this.#debuggerConnections.get(sessionId);
132
+ if (debuggerConnection) {
133
+ this.#debuggerConnections.delete(sessionId);
134
+ this.#sendDisconnectEventToDevice(
135
+ this.#mapToDevicePageId(debuggerConnection.pageId),
136
+ sessionId,
137
+ );
138
+ debuggerConnection.socket.close(code, reason);
139
+ }
140
+ } else {
141
+ const connections = Array.from(this.#debuggerConnections.entries());
142
+ this.#debuggerConnections.clear();
143
+ for (const [sid, debuggerConnection] of connections) {
144
+ this.#sendDisconnectEventToDevice(
145
+ this.#mapToDevicePageId(debuggerConnection.pageId),
146
+ sid,
147
+ );
148
+ debuggerConnection.socket.close(code, reason);
149
+ }
135
150
  }
136
151
  }
137
152
  dangerouslyRecreateDevice(deviceOptions) {
@@ -139,7 +154,7 @@ class Device {
139
154
  deviceOptions.id === this.#id,
140
155
  "dangerouslyRecreateDevice() can only be used for the same device ID",
141
156
  );
142
- const oldDebugger = this.#debuggerConnection;
157
+ const oldDebuggerConnections = new Map(this.#debuggerConnections);
143
158
  if (this.#app !== deviceOptions.app || this.#name !== deviceOptions.name) {
144
159
  this.#deviceSocket.close(
145
160
  WS_CLOSURE_CODE.NORMAL,
@@ -150,19 +165,21 @@ class Device {
150
165
  WS_CLOSE_REASON.RECREATING_DEVICE,
151
166
  );
152
167
  }
153
- this.#debuggerConnection = null;
154
- if (oldDebugger) {
155
- oldDebugger.socket.removeAllListeners();
168
+ this.#debuggerConnections.clear();
169
+ if (oldDebuggerConnections.size > 0) {
156
170
  this.#deviceSocket.close(
157
171
  WS_CLOSURE_CODE.NORMAL,
158
172
  WS_CLOSE_REASON.RECREATING_DEVICE,
159
173
  );
174
+ }
175
+ this.#dangerouslyConstruct(deviceOptions);
176
+ for (const oldDebugger of oldDebuggerConnections.values()) {
177
+ oldDebugger.socket.removeAllListeners();
160
178
  this.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId, {
161
179
  debuggerRelativeBaseUrl: oldDebugger.debuggerRelativeBaseUrl,
162
180
  userAgent: oldDebugger.userAgent,
163
181
  });
164
182
  }
165
- this.#dangerouslyConstruct(deviceOptions);
166
183
  }
167
184
  getName() {
168
185
  return this.#name;
@@ -198,10 +215,18 @@ class Device {
198
215
  return;
199
216
  }
200
217
  this.#deviceEventReporter?.logDisconnection("debugger");
201
- this.#terminateDebuggerConnection(
202
- WS_CLOSURE_CODE.NORMAL,
203
- WS_CLOSE_REASON.NEW_DEBUGGER_OPENED,
204
- );
218
+ if (!this.#pageHasCapability(page, "supportsMultipleDebuggers")) {
219
+ for (const [sid, conn] of this.#debuggerConnections) {
220
+ if (conn.pageId === pageId) {
221
+ this.#terminateDebuggerConnection(
222
+ WS_CLOSURE_CODE.NORMAL,
223
+ WS_CLOSE_REASON.NEW_DEBUGGER_OPENED,
224
+ sid,
225
+ );
226
+ }
227
+ }
228
+ }
229
+ const sessionId = _crypto.default.randomUUID();
205
230
  this.#deviceEventReporter?.logConnection("debugger", {
206
231
  pageId,
207
232
  frontendUserAgent: userAgent,
@@ -213,47 +238,47 @@ class Device {
213
238
  userAgent: userAgent,
214
239
  customHandler: null,
215
240
  debuggerRelativeBaseUrl,
241
+ sessionId,
216
242
  };
217
- this.#debuggerConnection = debuggerInfo;
243
+ this.#debuggerConnections.set(sessionId, debuggerInfo);
218
244
  debug(
219
245
  `Got new debugger connection via ${debuggerRelativeBaseUrl.href} for ` +
220
- `page ${pageId} of ${this.#name}`,
246
+ `page ${pageId} of ${this.#name} with sessionId ${sessionId}`,
221
247
  );
222
- if (this.#debuggerConnection && this.#createCustomMessageHandler) {
223
- this.#debuggerConnection.customHandler = this.#createCustomMessageHandler(
224
- {
225
- page,
226
- debugger: {
227
- userAgent: debuggerInfo.userAgent,
228
- sendMessage: (message) => {
229
- try {
230
- const payload = JSON.stringify(message);
231
- this.#cdpDebugLogging.log("ProxyToDebugger", payload);
232
- socket.send(payload);
233
- } catch {}
234
- },
248
+ if (this.#createCustomMessageHandler) {
249
+ debuggerInfo.customHandler = this.#createCustomMessageHandler({
250
+ page,
251
+ debugger: {
252
+ userAgent: debuggerInfo.userAgent,
253
+ sendMessage: (message) => {
254
+ try {
255
+ const payload = JSON.stringify(message);
256
+ this.#cdpDebugLogging.log("ProxyToDebugger", payload);
257
+ socket.send(payload);
258
+ } catch {}
235
259
  },
236
- device: {
237
- appId: this.#app,
238
- id: this.#id,
239
- name: this.#name,
240
- sendMessage: (message) => {
241
- try {
242
- const payload = JSON.stringify({
243
- event: "wrappedEvent",
244
- payload: {
245
- pageId: this.#mapToDevicePageId(pageId),
246
- wrappedEvent: JSON.stringify(message),
247
- },
248
- });
249
- this.#cdpDebugLogging.log("DebuggerToProxy", payload);
250
- this.#deviceSocket.send(payload);
251
- } catch {}
252
- },
260
+ },
261
+ device: {
262
+ appId: this.#app,
263
+ id: this.#id,
264
+ name: this.#name,
265
+ sendMessage: (message) => {
266
+ try {
267
+ const payload = JSON.stringify({
268
+ event: "wrappedEvent",
269
+ payload: {
270
+ pageId: this.#mapToDevicePageId(pageId),
271
+ wrappedEvent: JSON.stringify(message),
272
+ sessionId,
273
+ },
274
+ });
275
+ this.#cdpDebugLogging.log("DebuggerToProxy", payload);
276
+ this.#deviceSocket.send(payload);
277
+ } catch {}
253
278
  },
254
279
  },
255
- );
256
- if (this.#debuggerConnection.customHandler) {
280
+ });
281
+ if (debuggerInfo.customHandler) {
257
282
  debug("Created new custom message handler for debugger connection");
258
283
  } else {
259
284
  debug(
@@ -261,22 +286,21 @@ class Device {
261
286
  );
262
287
  }
263
288
  }
264
- this.#sendConnectEventToDevice(this.#mapToDevicePageId(pageId));
289
+ this.#sendConnectEventToDevice(this.#mapToDevicePageId(pageId), sessionId);
265
290
  socket.on("message", (message) => {
266
291
  this.#cdpDebugLogging.log("DebuggerToProxy", message);
267
292
  const debuggerRequest = JSON.parse(message);
268
293
  this.#deviceEventReporter?.logRequest(debuggerRequest, "debugger", {
269
- pageId: this.#debuggerConnection?.pageId ?? null,
294
+ pageId: debuggerInfo.pageId,
270
295
  frontendUserAgent: userAgent,
271
296
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(
272
- this.#debuggerConnection?.pageId,
297
+ debuggerInfo.pageId,
273
298
  ),
274
299
  });
275
300
  let processedReq = debuggerRequest;
276
301
  if (
277
- this.#debuggerConnection?.customHandler?.handleDebuggerMessage(
278
- debuggerRequest,
279
- ) === true
302
+ debuggerInfo.customHandler?.handleDebuggerMessage(debuggerRequest) ===
303
+ true
280
304
  ) {
281
305
  return;
282
306
  }
@@ -293,16 +317,17 @@ class Device {
293
317
  payload: {
294
318
  pageId: this.#mapToDevicePageId(pageId),
295
319
  wrappedEvent: JSON.stringify(processedReq),
320
+ sessionId,
296
321
  },
297
322
  });
298
323
  }
299
324
  });
300
325
  socket.on("close", () => {
301
- debug(`Debugger for page ${pageId} and ${this.#name} disconnected.`);
326
+ debug(
327
+ `Debugger for page ${pageId} and ${this.#name} disconnected (sessionId: ${sessionId}).`,
328
+ );
302
329
  this.#deviceEventReporter?.logDisconnection("debugger");
303
- if (this.#debuggerConnection?.socket === socket) {
304
- this.#terminateDebuggerConnection();
305
- }
330
+ this.#terminateDebuggerConnection(undefined, undefined, sessionId);
306
331
  });
307
332
  const cdpDebugLogging = this.#cdpDebugLogging;
308
333
  const sendFunc = socket.send;
@@ -311,27 +336,21 @@ class Device {
311
336
  return sendFunc.call(socket, message);
312
337
  };
313
338
  }
314
- #sendConnectEventToDevice(devicePageId) {
315
- if (this.#connectedPageIds.has(devicePageId)) {
316
- return;
317
- }
318
- this.#connectedPageIds.add(devicePageId);
339
+ #sendConnectEventToDevice(devicePageId, sessionId) {
319
340
  this.#sendMessageToDevice({
320
341
  event: "connect",
321
342
  payload: {
322
343
  pageId: devicePageId,
344
+ sessionId,
323
345
  },
324
346
  });
325
347
  }
326
- #sendDisconnectEventToDevice(devicePageId) {
327
- if (!this.#connectedPageIds.has(devicePageId)) {
328
- return;
329
- }
330
- this.#connectedPageIds.delete(devicePageId);
348
+ #sendDisconnectEventToDevice(devicePageId, sessionId) {
331
349
  this.#sendMessageToDevice({
332
350
  event: "disconnect",
333
351
  payload: {
334
352
  pageId: devicePageId,
353
+ sessionId,
335
354
  },
336
355
  });
337
356
  }
@@ -349,14 +368,24 @@ class Device {
349
368
  }
350
369
  #handleMessageFromDevice(message) {
351
370
  if (message.event === "getPages") {
371
+ const shouldDisableMultipleDebuggers =
372
+ !this.#experiments.enableStandaloneFuseboxShell;
352
373
  this.#pages = new Map(
353
- message.payload.map(({ capabilities, ...page }) => [
354
- page.id,
355
- {
356
- ...page,
357
- capabilities: capabilities ?? {},
358
- },
359
- ]),
374
+ message.payload.map(({ capabilities: rawCapabilities, ...page }) => {
375
+ const capabilities = shouldDisableMultipleDebuggers
376
+ ? {
377
+ ...(rawCapabilities ?? {}),
378
+ supportsMultipleDebuggers: false,
379
+ }
380
+ : (rawCapabilities ?? {});
381
+ return [
382
+ page.id,
383
+ {
384
+ ...page,
385
+ capabilities,
386
+ },
387
+ ];
388
+ }),
360
389
  );
361
390
  if (message.payload.length !== this.#pages.size) {
362
391
  const duplicateIds = new Set();
@@ -385,31 +414,62 @@ class Device {
385
414
  }
386
415
  } else if (message.event === "disconnect") {
387
416
  const pageId = message.payload.pageId;
417
+ const sessionId = message.payload.sessionId;
388
418
  const page = this.#pages.get(pageId);
389
419
  if (page != null && this.#pageHasCapability(page, "nativePageReloads")) {
390
420
  return;
391
421
  }
392
- const debuggerSocket = this.#debuggerConnection
393
- ? this.#debuggerConnection.socket
394
- : null;
395
- if (debuggerSocket && debuggerSocket.readyState === _ws.default.OPEN) {
422
+ if (sessionId != null) {
423
+ const debuggerConnection = this.#debuggerConnections.get(sessionId);
396
424
  if (
397
- this.#debuggerConnection != null &&
398
- this.#debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID
425
+ debuggerConnection &&
426
+ debuggerConnection.socket.readyState === _ws.default.OPEN
399
427
  ) {
400
- debug(`Legacy page ${pageId} is reloading.`);
401
- debuggerSocket.send(
402
- JSON.stringify({
403
- method: "reload",
404
- }),
405
- );
428
+ if (debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID) {
429
+ debug(
430
+ `Legacy page ${pageId} is reloading (sessionId: ${sessionId}).`,
431
+ );
432
+ debuggerConnection.socket.send(
433
+ JSON.stringify({
434
+ method: "reload",
435
+ }),
436
+ );
437
+ }
438
+ }
439
+ } else {
440
+ for (const debuggerConnection of this.#debuggerConnections.values()) {
441
+ if (
442
+ debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID &&
443
+ debuggerConnection.socket.readyState === _ws.default.OPEN
444
+ ) {
445
+ debug(`Legacy page ${pageId} is reloading.`);
446
+ debuggerConnection.socket.send(
447
+ JSON.stringify({
448
+ method: "reload",
449
+ }),
450
+ );
451
+ }
406
452
  }
407
453
  }
408
454
  } else if (message.event === "wrappedEvent") {
409
- if (this.#debuggerConnection == null) {
455
+ const sessionId = message.payload.sessionId;
456
+ let debuggerConnection = null;
457
+ if (sessionId != null) {
458
+ debuggerConnection = this.#debuggerConnections.get(sessionId);
459
+ } else {
460
+ if (this.#debuggerConnections.size > 1) {
461
+ debug(
462
+ "WARNING: Device sent message without sessionId but multiple debuggers are connected. " +
463
+ "This indicates a device/proxy version mismatch.",
464
+ );
465
+ }
466
+ debuggerConnection =
467
+ this.#debuggerConnections.values().next().value ?? null;
468
+ }
469
+ if (debuggerConnection == null) {
410
470
  return;
411
471
  }
412
- const debuggerSocket = this.#debuggerConnection.socket;
472
+ const debuggerSocket = debuggerConnection.socket;
413
473
  if (
414
474
  debuggerSocket == null ||
415
475
  debuggerSocket.readyState !== _ws.default.OPEN
@@ -417,33 +477,27 @@ class Device {
417
477
  return;
418
478
  }
419
479
  const parsedPayload = JSON.parse(message.payload.wrappedEvent);
420
- const pageId = this.#debuggerConnection?.pageId ?? null;
480
+ const pageId = debuggerConnection.pageId;
421
481
  if ("id" in parsedPayload) {
422
482
  this.#deviceEventReporter?.logResponse(parsedPayload, "device", {
423
483
  pageId,
424
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
484
+ frontendUserAgent: debuggerConnection.userAgent ?? null,
425
485
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
426
486
  });
427
487
  }
428
- const debuggerConnection = this.#debuggerConnection;
429
- if (debuggerConnection != null) {
430
- if (
431
- debuggerConnection.customHandler?.handleDeviceMessage(
432
- parsedPayload,
433
- ) === true
434
- ) {
435
- return;
436
- }
437
- this.#processMessageFromDeviceLegacy(
438
- parsedPayload,
439
- debuggerConnection,
440
- pageId,
441
- );
442
- const messageToSend = JSON.stringify(parsedPayload);
443
- debuggerSocket.send(messageToSend);
444
- } else {
445
- debuggerSocket.send(message.payload.wrappedEvent);
488
+ if (
489
+ debuggerConnection.customHandler?.handleDeviceMessage(parsedPayload) ===
490
+ true
491
+ ) {
492
+ return;
446
493
  }
494
+ this.#processMessageFromDeviceLegacy(
495
+ parsedPayload,
496
+ debuggerConnection,
497
+ pageId,
498
+ );
499
+ const messageToSend = JSON.stringify(parsedPayload);
500
+ debuggerSocket.send(messageToSend);
447
501
  }
448
502
  }
449
503
  #sendMessageToDevice(message) {
@@ -457,10 +511,14 @@ class Device {
457
511
  }
458
512
  #newLegacyReactNativePage(page) {
459
513
  debug(`React Native page updated to ${page.id}`);
460
- if (
461
- this.#debuggerConnection == null ||
462
- this.#debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID
463
- ) {
514
+ let reloadablePageDebugger = null;
515
+ for (const debuggerConnection of this.#debuggerConnections.values()) {
516
+ if (debuggerConnection.pageId === REACT_NATIVE_RELOADABLE_PAGE_ID) {
517
+ reloadablePageDebugger = debuggerConnection;
518
+ break;
519
+ }
520
+ }
521
+ if (reloadablePageDebugger == null) {
464
522
  this.#lastConnectedLegacyReactNativePage = page;
465
523
  return;
466
524
  }
@@ -468,9 +526,12 @@ class Device {
468
526
  this.#lastConnectedLegacyReactNativePage = page;
469
527
  this.#isLegacyPageReloading = true;
470
528
  if (oldPageId != null) {
471
- this.#sendDisconnectEventToDevice(oldPageId);
529
+ this.#sendDisconnectEventToDevice(
530
+ oldPageId,
531
+ reloadablePageDebugger.sessionId,
532
+ );
472
533
  }
473
- this.#sendConnectEventToDevice(page.id);
534
+ this.#sendConnectEventToDevice(page.id, reloadablePageDebugger.sessionId);
474
535
  const toSend = [
475
536
  {
476
537
  method: "Runtime.enable",
@@ -482,10 +543,10 @@ class Device {
482
543
  },
483
544
  ];
484
545
  for (const message of toSend) {
485
- const pageId = this.#debuggerConnection?.pageId ?? null;
546
+ const pageId = reloadablePageDebugger.pageId;
486
547
  this.#deviceEventReporter?.logRequest(message, "proxy", {
487
548
  pageId,
488
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
549
+ frontendUserAgent: reloadablePageDebugger.userAgent ?? null,
489
550
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
490
551
  });
491
552
  this.#sendMessageToDevice({
@@ -493,6 +554,7 @@ class Device {
493
554
  payload: {
494
555
  pageId: this.#mapToDevicePageId(page.id),
495
556
  wrappedEvent: JSON.stringify(message),
557
+ sessionId: reloadablePageDebugger.sessionId,
496
558
  },
497
559
  });
498
560
  }
@@ -585,10 +647,10 @@ class Device {
585
647
  id: 0,
586
648
  };
587
649
  this.#deviceEventReporter?.logRequest(resumeMessage, "proxy", {
588
- pageId: this.#debuggerConnection?.pageId ?? null,
589
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
650
+ pageId: debuggerInfo.pageId,
651
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
590
652
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(
591
- this.#debuggerConnection?.pageId,
653
+ debuggerInfo.pageId,
592
654
  ),
593
655
  });
594
656
  this.#sendMessageToDevice({
@@ -596,6 +658,7 @@ class Device {
596
658
  payload: {
597
659
  pageId: this.#mapToDevicePageId(debuggerInfo.pageId),
598
660
  wrappedEvent: JSON.stringify(resumeMessage),
661
+ sessionId: debuggerInfo.sessionId,
599
662
  },
600
663
  });
601
664
  this.#isLegacyPageReloading = false;
@@ -620,7 +683,7 @@ class Device {
620
683
  case "Debugger.setBreakpointByUrl":
621
684
  return this.#processDebuggerSetBreakpointByUrl(req, debuggerInfo);
622
685
  case "Debugger.getScriptSource":
623
- void this.#processDebuggerGetScriptSource(req, socket);
686
+ void this.#processDebuggerGetScriptSource(req, socket, debuggerInfo);
624
687
  return null;
625
688
  case "Network.loadNetworkResource":
626
689
  const response = {
@@ -634,10 +697,10 @@ class Device {
634
697
  },
635
698
  };
636
699
  socket.send(JSON.stringify(response));
637
- const pageId = this.#debuggerConnection?.pageId ?? null;
700
+ const pageId = debuggerInfo.pageId;
638
701
  this.#deviceEventReporter?.logResponse(response, "proxy", {
639
702
  pageId,
640
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
703
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
641
704
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
642
705
  });
643
706
  return null;
@@ -682,7 +745,7 @@ class Device {
682
745
  }
683
746
  return processedReq;
684
747
  }
685
- async #processDebuggerGetScriptSource(req, socket) {
748
+ async #processDebuggerGetScriptSource(req, socket, debuggerInfo) {
686
749
  const sendSuccessResponse = (scriptSource) => {
687
750
  const response = {
688
751
  id: req.id,
@@ -691,10 +754,10 @@ class Device {
691
754
  },
692
755
  };
693
756
  socket.send(JSON.stringify(response));
694
- const pageId = this.#debuggerConnection?.pageId ?? null;
757
+ const pageId = debuggerInfo.pageId;
695
758
  this.#deviceEventReporter?.logResponse(response, "proxy", {
696
759
  pageId,
697
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
760
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
698
761
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
699
762
  });
700
763
  };
@@ -708,11 +771,11 @@ class Device {
708
771
  },
709
772
  };
710
773
  socket.send(JSON.stringify(response));
711
- this.#sendErrorToDebugger(error);
712
- const pageId = this.#debuggerConnection?.pageId ?? null;
774
+ this.#sendErrorToDebugger(error, debuggerInfo);
775
+ const pageId = debuggerInfo.pageId;
713
776
  this.#deviceEventReporter?.logResponse(response, "proxy", {
714
777
  pageId,
715
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
778
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
716
779
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
717
780
  });
718
781
  };
@@ -767,8 +830,8 @@ class Device {
767
830
  }
768
831
  return text;
769
832
  }
770
- #sendErrorToDebugger(message) {
771
- const debuggerSocket = this.#debuggerConnection?.socket;
833
+ #sendErrorToDebugger(message, debuggerInfo) {
834
+ const debuggerSocket = debuggerInfo?.socket;
772
835
  if (debuggerSocket && debuggerSocket.readyState === _ws.default.OPEN) {
773
836
  debuggerSocket.send(
774
837
  JSON.stringify({
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import type { EventReporter } from "../types/EventReporter";
12
+ import type { Experiments } from "../types/Experiments";
12
13
  import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
13
14
  import type { Page } from "./types";
14
15
 
@@ -33,6 +34,7 @@ export type DeviceOptions = Readonly<{
33
34
  deviceRelativeBaseUrl: URL,
34
35
  serverRelativeBaseUrl: URL,
35
36
  isProfilingBuild: boolean,
37
+ experiments: Experiments,
36
38
  }>;
37
39
 
38
40
  /**
@@ -263,6 +263,7 @@ class InspectorProxy {
263
263
  deviceRelativeBaseUrl,
264
264
  serverRelativeBaseUrl: this.#serverBaseUrl,
265
265
  isProfilingBuild,
266
+ experiments: this.#experiments,
266
267
  };
267
268
  if (oldDevice) {
268
269
  oldDevice.dangerouslyRecreateDevice(deviceOptions);
@@ -35,6 +35,15 @@ export type TargetCapabilityFlags = Readonly<{
35
35
  * In the launch flow, this controls the Chrome DevTools entrypoint that is used.
36
36
  */
37
37
  prefersFuseboxFrontend?: boolean;
38
+ /**
39
+ * The target supports multiple concurrent debugger connections.
40
+ *
41
+ * When true, the proxy allows multiple debuggers to connect to the same
42
+ * page simultaneously, each identified by a unique session ID.
43
+ * When false (default/legacy), connecting a new debugger disconnects
44
+ * any existing debugger connection to that page.
45
+ */
46
+ supportsMultipleDebuggers?: boolean;
38
47
  }>;
39
48
  export type PageFromDevice = Readonly<{
40
49
  id: string;
@@ -52,17 +61,29 @@ export type Page = Readonly<
52
61
  keyof { capabilities: NonNullable<PageFromDevice["capabilities"]> }
53
62
  > & { capabilities: NonNullable<PageFromDevice["capabilities"]> }
54
63
  >;
55
- export type WrappedEvent = Readonly<{
64
+ export type WrappedEventFromDevice = Readonly<{
56
65
  event: "wrappedEvent";
57
- payload: Readonly<{ pageId: string; wrappedEvent: string }>;
66
+ payload: Readonly<{
67
+ pageId: string;
68
+ wrappedEvent: string;
69
+ sessionId?: string;
70
+ }>;
71
+ }>;
72
+ export type WrappedEventToDevice = Readonly<{
73
+ event: "wrappedEvent";
74
+ payload: Readonly<{
75
+ pageId: string;
76
+ wrappedEvent: string;
77
+ sessionId: string;
78
+ }>;
58
79
  }>;
59
80
  export type ConnectRequest = Readonly<{
60
81
  event: "connect";
61
- payload: Readonly<{ pageId: string }>;
82
+ payload: Readonly<{ pageId: string; sessionId: string }>;
62
83
  }>;
63
84
  export type DisconnectRequest = Readonly<{
64
85
  event: "disconnect";
65
- payload: Readonly<{ pageId: string }>;
86
+ payload: Readonly<{ pageId: string; sessionId: string }>;
66
87
  }>;
67
88
  export type GetPagesRequest = { event: "getPages" };
68
89
  export type GetPagesResponse = {
@@ -71,11 +92,11 @@ export type GetPagesResponse = {
71
92
  };
72
93
  export type MessageFromDevice =
73
94
  | GetPagesResponse
74
- | WrappedEvent
95
+ | WrappedEventFromDevice
75
96
  | DisconnectRequest;
76
97
  export type MessageToDevice =
77
98
  | GetPagesRequest
78
- | WrappedEvent
99
+ | WrappedEventToDevice
79
100
  | ConnectRequest
80
101
  | DisconnectRequest;
81
102
  export type PageDescription = Readonly<{
@@ -37,6 +37,16 @@ export type TargetCapabilityFlags = Readonly<{
37
37
  * In the launch flow, this controls the Chrome DevTools entrypoint that is used.
38
38
  */
39
39
  prefersFuseboxFrontend?: boolean,
40
+
41
+ /**
42
+ * The target supports multiple concurrent debugger connections.
43
+ *
44
+ * When true, the proxy allows multiple debuggers to connect to the same
45
+ * page simultaneously, each identified by a unique session ID.
46
+ * When false (default/legacy), connecting a new debugger disconnects
47
+ * any existing debugger connection to that page.
48
+ */
49
+ supportsMultipleDebuggers?: boolean,
40
50
  }>;
41
51
 
42
52
  // Page information received from the device. New page is created for
@@ -59,12 +69,23 @@ export type Page = Readonly<{
59
69
  capabilities: NonNullable<PageFromDevice["capabilities"]>,
60
70
  }>;
61
71
 
62
- // Chrome Debugger Protocol message/event passed between device and debugger.
63
- export type WrappedEvent = Readonly<{
72
+ // Chrome Debugger Protocol message/event passed from device to proxy.
73
+ export type WrappedEventFromDevice = Readonly<{
74
+ event: "wrappedEvent",
75
+ payload: Readonly<{
76
+ pageId: string,
77
+ wrappedEvent: string,
78
+ sessionId?: string,
79
+ }>,
80
+ }>;
81
+
82
+ // Chrome Debugger Protocol message/event passed from proxy to device.
83
+ export type WrappedEventToDevice = Readonly<{
64
84
  event: "wrappedEvent",
65
85
  payload: Readonly<{
66
86
  pageId: string,
67
87
  wrappedEvent: string,
88
+ sessionId: string,
68
89
  }>,
69
90
  }>;
70
91
 
@@ -72,14 +93,14 @@ export type WrappedEvent = Readonly<{
72
93
  // to particular page.
73
94
  export type ConnectRequest = Readonly<{
74
95
  event: "connect",
75
- payload: Readonly<{ pageId: string }>,
96
+ payload: Readonly<{ pageId: string, sessionId: string }>,
76
97
  }>;
77
98
 
78
99
  // Request sent from Inspector Proxy to Device to notify that debugger is
79
100
  // disconnected.
80
101
  export type DisconnectRequest = Readonly<{
81
102
  event: "disconnect",
82
- payload: Readonly<{ pageId: string }>,
103
+ payload: Readonly<{ pageId: string, sessionId: string }>,
83
104
  }>;
84
105
 
85
106
  // Request sent from Inspector Proxy to Device to get a list of pages.
@@ -94,13 +115,13 @@ export type GetPagesResponse = {
94
115
  // Union type for all possible messages sent from device to Inspector Proxy.
95
116
  export type MessageFromDevice =
96
117
  | GetPagesResponse
97
- | WrappedEvent
118
+ | WrappedEventFromDevice
98
119
  | DisconnectRequest;
99
120
 
100
121
  // Union type for all possible messages sent from Inspector Proxy to device.
101
122
  export type MessageToDevice =
102
123
  | GetPagesRequest
103
- | WrappedEvent
124
+ | WrappedEventToDevice
104
125
  | ConnectRequest
105
126
  | DisconnectRequest;
106
127
 
@@ -24,6 +24,10 @@ export type Experiments = Readonly<{
24
24
  * Launch the Fusebox frontend in a standalone shell instead of a browser.
25
25
  * When this is enabled, we will use the optional unstable_showFuseboxShell
26
26
  * method on the BrowserLauncher, or throw an error if the method is missing.
27
+ *
28
+ * NOTE: Disabling this also disables support for concurrent sessions in the
29
+ * inspector proxy. Without the standalone shell, the proxy remains responsible
30
+ * for keeping only one debugger frontend active at a time per page.
27
31
  */
28
32
  enableStandaloneFuseboxShell: boolean;
29
33
  }>;
@@ -27,6 +27,10 @@ export type Experiments = Readonly<{
27
27
  * Launch the Fusebox frontend in a standalone shell instead of a browser.
28
28
  * When this is enabled, we will use the optional unstable_showFuseboxShell
29
29
  * method on the BrowserLauncher, or throw an error if the method is missing.
30
+ *
31
+ * NOTE: Disabling this also disables support for concurrent sessions in the
32
+ * inspector proxy. Without the standalone shell, the proxy remains responsible
33
+ * for keeping only one debugger frontend active at a time per page.
30
34
  */
31
35
  enableStandaloneFuseboxShell: boolean,
32
36
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/dev-middleware",
3
- "version": "0.85.0-nightly-20260126-490c5e8dc",
3
+ "version": "0.85.0-nightly-20260128-36f07a1b2",
4
4
  "description": "Dev server middleware for React Native",
5
5
  "keywords": [
6
6
  "react-native",
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@isaacs/ttlcache": "^1.4.1",
29
- "@react-native/debugger-frontend": "0.85.0-nightly-20260126-490c5e8dc",
30
- "@react-native/debugger-shell": "0.85.0-nightly-20260126-490c5e8dc",
29
+ "@react-native/debugger-frontend": "0.85.0-nightly-20260128-36f07a1b2",
30
+ "@react-native/debugger-shell": "0.85.0-nightly-20260128-36f07a1b2",
31
31
  "chrome-launcher": "^0.15.2",
32
32
  "chromium-edge-launcher": "^0.3.0",
33
33
  "connect": "^3.6.5",
@@ -39,7 +39,7 @@
39
39
  "ws": "^7.5.10"
40
40
  },
41
41
  "devDependencies": {
42
- "@react-native/debugger-shell": "0.85.0-nightly-20260126-490c5e8dc",
42
+ "@react-native/debugger-shell": "0.85.0-nightly-20260128-36f07a1b2",
43
43
  "selfsigned": "^4.0.0",
44
44
  "undici": "^5.29.0",
45
45
  "wait-for-expect": "^3.0.2"