@depup/react-native__dev-middleware 0.84.1-depup.1 → 0.85.0-depup.0

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.
Files changed (44) hide show
  1. package/README.md +3 -4
  2. package/changes.json +2 -6
  3. package/dist/createDevMiddleware.d.ts +18 -9
  4. package/dist/createDevMiddleware.js +7 -17
  5. package/dist/createDevMiddleware.js.flow +21 -12
  6. package/dist/index.d.ts +4 -3
  7. package/dist/index.js +4 -4
  8. package/dist/index.js.flow +4 -3
  9. package/dist/inspector-proxy/CustomMessageHandler.js.flow +3 -3
  10. package/dist/inspector-proxy/Device.d.ts +6 -3
  11. package/dist/inspector-proxy/Device.js +197 -161
  12. package/dist/inspector-proxy/Device.js.flow +9 -6
  13. package/dist/inspector-proxy/DeviceEventReporter.d.ts +0 -3
  14. package/dist/inspector-proxy/DeviceEventReporter.js +0 -10
  15. package/dist/inspector-proxy/DeviceEventReporter.js.flow +5 -8
  16. package/dist/inspector-proxy/InspectorProxy.d.ts +3 -2
  17. package/dist/inspector-proxy/InspectorProxy.js +47 -15
  18. package/dist/inspector-proxy/InspectorProxy.js.flow +3 -2
  19. package/dist/inspector-proxy/__docs__/README.md +324 -0
  20. package/dist/inspector-proxy/cdp-types/messages.js.flow +3 -3
  21. package/dist/inspector-proxy/types.d.ts +24 -9
  22. package/dist/inspector-proxy/types.js.flow +36 -22
  23. package/dist/middleware/openDebuggerMiddleware.d.ts +4 -6
  24. package/dist/middleware/openDebuggerMiddleware.js +12 -22
  25. package/dist/middleware/openDebuggerMiddleware.js.flow +5 -7
  26. package/dist/types/{BrowserLauncher.js.flow → DevToolLauncher.d.ts} +10 -13
  27. package/dist/types/{BrowserLauncher.d.ts → DevToolLauncher.js.flow} +14 -12
  28. package/dist/types/EventReporter.d.ts +24 -27
  29. package/dist/types/EventReporter.js.flow +1 -7
  30. package/dist/types/Experiments.d.ts +8 -4
  31. package/dist/types/Experiments.js.flow +9 -5
  32. package/dist/types/Logger.js.flow +1 -1
  33. package/dist/types/ReadonlyURL.d.ts +53 -0
  34. package/dist/types/ReadonlyURL.js +1 -0
  35. package/dist/types/ReadonlyURL.js.flow +54 -0
  36. package/dist/utils/{DefaultBrowserLauncher.d.ts → DefaultToolLauncher.d.ts} +7 -11
  37. package/dist/utils/{DefaultBrowserLauncher.js → DefaultToolLauncher.js} +21 -4
  38. package/dist/utils/DefaultToolLauncher.js.flow +25 -0
  39. package/dist/utils/getDevToolsFrontendUrl.d.ts +2 -3
  40. package/dist/utils/getDevToolsFrontendUrl.js +3 -6
  41. package/dist/utils/getDevToolsFrontendUrl.js.flow +3 -4
  42. package/package.json +10 -14
  43. package/dist/utils/DefaultBrowserLauncher.js.flow +0 -29
  44. /package/dist/types/{BrowserLauncher.js → DevToolLauncher.js} +0 -0
@@ -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) {
@@ -27,7 +28,6 @@ const WS_CLOSE_REASON = (exports.WS_CLOSE_REASON = {
27
28
  "[NEW_DEBUGGER_OPENED] New debugger opened for the same app instance",
28
29
  });
29
30
  const FILE_PREFIX = "file://";
30
- let fuseboxConsoleNoticeLogged = false;
31
31
  const REACT_NATIVE_RELOADABLE_PAGE_ID = "-1";
32
32
  class Device {
33
33
  #id;
@@ -35,7 +35,7 @@ class Device {
35
35
  #app;
36
36
  #deviceSocket;
37
37
  #pages = new Map();
38
- #debuggerConnection = null;
38
+ #debuggerConnections = new Map();
39
39
  #lastConnectedLegacyReactNativePage = null;
40
40
  #isLegacyPageReloading = false;
41
41
  #lastGetPagesMessage = "";
@@ -43,11 +43,12 @@ class Device {
43
43
  #deviceEventReporter;
44
44
  #pagesPollingIntervalId;
45
45
  #createCustomMessageHandler;
46
- #connectedPageIds = new Set();
47
46
  #deviceRelativeBaseUrl;
48
47
  #serverRelativeBaseUrl;
49
48
  #cdpDebugLogging;
49
+ #experiments;
50
50
  constructor(deviceOptions) {
51
+ this.#experiments = deviceOptions.experiments;
51
52
  this.#dangerouslyConstruct(deviceOptions);
52
53
  }
53
54
  #dangerouslyConstruct({
@@ -125,14 +126,27 @@ class Device {
125
126
  }
126
127
  });
127
128
  }
128
- #terminateDebuggerConnection(code, reason) {
129
- const debuggerConnection = this.#debuggerConnection;
130
- if (debuggerConnection) {
131
- this.#sendDisconnectEventToDevice(
132
- this.#mapToDevicePageId(debuggerConnection.pageId),
133
- );
134
- debuggerConnection.socket.close(code, reason);
135
- 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
+ }
136
150
  }
137
151
  }
138
152
  dangerouslyRecreateDevice(deviceOptions) {
@@ -140,7 +154,7 @@ class Device {
140
154
  deviceOptions.id === this.#id,
141
155
  "dangerouslyRecreateDevice() can only be used for the same device ID",
142
156
  );
143
- const oldDebugger = this.#debuggerConnection;
157
+ const oldDebuggerConnections = new Map(this.#debuggerConnections);
144
158
  if (this.#app !== deviceOptions.app || this.#name !== deviceOptions.name) {
145
159
  this.#deviceSocket.close(
146
160
  WS_CLOSURE_CODE.NORMAL,
@@ -151,19 +165,21 @@ class Device {
151
165
  WS_CLOSE_REASON.RECREATING_DEVICE,
152
166
  );
153
167
  }
154
- this.#debuggerConnection = null;
155
- if (oldDebugger) {
156
- oldDebugger.socket.removeAllListeners();
168
+ this.#debuggerConnections.clear();
169
+ if (oldDebuggerConnections.size > 0) {
157
170
  this.#deviceSocket.close(
158
171
  WS_CLOSURE_CODE.NORMAL,
159
172
  WS_CLOSE_REASON.RECREATING_DEVICE,
160
173
  );
174
+ }
175
+ this.#dangerouslyConstruct(deviceOptions);
176
+ for (const oldDebugger of oldDebuggerConnections.values()) {
177
+ oldDebugger.socket.removeAllListeners();
161
178
  this.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId, {
162
179
  debuggerRelativeBaseUrl: oldDebugger.debuggerRelativeBaseUrl,
163
180
  userAgent: oldDebugger.userAgent,
164
181
  });
165
182
  }
166
- this.#dangerouslyConstruct(deviceOptions);
167
183
  }
168
184
  getName() {
169
185
  return this.#name;
@@ -199,10 +215,18 @@ class Device {
199
215
  return;
200
216
  }
201
217
  this.#deviceEventReporter?.logDisconnection("debugger");
202
- this.#terminateDebuggerConnection(
203
- WS_CLOSURE_CODE.NORMAL,
204
- WS_CLOSE_REASON.NEW_DEBUGGER_OPENED,
205
- );
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();
206
230
  this.#deviceEventReporter?.logConnection("debugger", {
207
231
  pageId,
208
232
  frontendUserAgent: userAgent,
@@ -214,47 +238,47 @@ class Device {
214
238
  userAgent: userAgent,
215
239
  customHandler: null,
216
240
  debuggerRelativeBaseUrl,
241
+ sessionId,
217
242
  };
218
- this.#debuggerConnection = debuggerInfo;
243
+ this.#debuggerConnections.set(sessionId, debuggerInfo);
219
244
  debug(
220
245
  `Got new debugger connection via ${debuggerRelativeBaseUrl.href} for ` +
221
- `page ${pageId} of ${this.#name}`,
246
+ `page ${pageId} of ${this.#name} with sessionId ${sessionId}`,
222
247
  );
223
- if (this.#debuggerConnection && this.#createCustomMessageHandler) {
224
- this.#debuggerConnection.customHandler = this.#createCustomMessageHandler(
225
- {
226
- page,
227
- debugger: {
228
- userAgent: debuggerInfo.userAgent,
229
- sendMessage: (message) => {
230
- try {
231
- const payload = JSON.stringify(message);
232
- this.#cdpDebugLogging.log("ProxyToDebugger", payload);
233
- socket.send(payload);
234
- } catch {}
235
- },
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 {}
236
259
  },
237
- device: {
238
- appId: this.#app,
239
- id: this.#id,
240
- name: this.#name,
241
- sendMessage: (message) => {
242
- try {
243
- const payload = JSON.stringify({
244
- event: "wrappedEvent",
245
- payload: {
246
- pageId: this.#mapToDevicePageId(pageId),
247
- wrappedEvent: JSON.stringify(message),
248
- },
249
- });
250
- this.#cdpDebugLogging.log("DebuggerToProxy", payload);
251
- this.#deviceSocket.send(payload);
252
- } catch {}
253
- },
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 {}
254
278
  },
255
279
  },
256
- );
257
- if (this.#debuggerConnection.customHandler) {
280
+ });
281
+ if (debuggerInfo.customHandler) {
258
282
  debug("Created new custom message handler for debugger connection");
259
283
  } else {
260
284
  debug(
@@ -262,22 +286,18 @@ class Device {
262
286
  );
263
287
  }
264
288
  }
265
- this.#sendConnectEventToDevice(this.#mapToDevicePageId(pageId));
289
+ this.#sendConnectEventToDevice(this.#mapToDevicePageId(pageId), sessionId);
266
290
  socket.on("message", (message) => {
267
291
  this.#cdpDebugLogging.log("DebuggerToProxy", message);
268
292
  const debuggerRequest = JSON.parse(message);
269
293
  this.#deviceEventReporter?.logRequest(debuggerRequest, "debugger", {
270
- pageId: this.#debuggerConnection?.pageId ?? null,
294
+ pageId: debuggerInfo.pageId,
271
295
  frontendUserAgent: userAgent,
272
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(
273
- this.#debuggerConnection?.pageId,
274
- ),
275
296
  });
276
297
  let processedReq = debuggerRequest;
277
298
  if (
278
- this.#debuggerConnection?.customHandler?.handleDebuggerMessage(
279
- debuggerRequest,
280
- ) === true
299
+ debuggerInfo.customHandler?.handleDebuggerMessage(debuggerRequest) ===
300
+ true
281
301
  ) {
282
302
  return;
283
303
  }
@@ -294,16 +314,17 @@ class Device {
294
314
  payload: {
295
315
  pageId: this.#mapToDevicePageId(pageId),
296
316
  wrappedEvent: JSON.stringify(processedReq),
317
+ sessionId,
297
318
  },
298
319
  });
299
320
  }
300
321
  });
301
322
  socket.on("close", () => {
302
- debug(`Debugger for page ${pageId} and ${this.#name} disconnected.`);
323
+ debug(
324
+ `Debugger for page ${pageId} and ${this.#name} disconnected (sessionId: ${sessionId}).`,
325
+ );
303
326
  this.#deviceEventReporter?.logDisconnection("debugger");
304
- if (this.#debuggerConnection?.socket === socket) {
305
- this.#terminateDebuggerConnection();
306
- }
327
+ this.#terminateDebuggerConnection(undefined, undefined, sessionId);
307
328
  });
308
329
  const cdpDebugLogging = this.#cdpDebugLogging;
309
330
  const sendFunc = socket.send;
@@ -312,27 +333,21 @@ class Device {
312
333
  return sendFunc.call(socket, message);
313
334
  };
314
335
  }
315
- #sendConnectEventToDevice(devicePageId) {
316
- if (this.#connectedPageIds.has(devicePageId)) {
317
- return;
318
- }
319
- this.#connectedPageIds.add(devicePageId);
336
+ #sendConnectEventToDevice(devicePageId, sessionId) {
320
337
  this.#sendMessageToDevice({
321
338
  event: "connect",
322
339
  payload: {
323
340
  pageId: devicePageId,
341
+ sessionId,
324
342
  },
325
343
  });
326
344
  }
327
- #sendDisconnectEventToDevice(devicePageId) {
328
- if (!this.#connectedPageIds.has(devicePageId)) {
329
- return;
330
- }
331
- this.#connectedPageIds.delete(devicePageId);
345
+ #sendDisconnectEventToDevice(devicePageId, sessionId) {
332
346
  this.#sendMessageToDevice({
333
347
  event: "disconnect",
334
348
  payload: {
335
349
  pageId: devicePageId,
350
+ sessionId,
336
351
  },
337
352
  });
338
353
  }
@@ -350,14 +365,24 @@ class Device {
350
365
  }
351
366
  #handleMessageFromDevice(message) {
352
367
  if (message.event === "getPages") {
368
+ const shouldDisableMultipleDebuggers =
369
+ !this.#experiments.enableStandaloneFuseboxShell;
353
370
  this.#pages = new Map(
354
- message.payload.map(({ capabilities, ...page }) => [
355
- page.id,
356
- {
357
- ...page,
358
- capabilities: capabilities ?? {},
359
- },
360
- ]),
371
+ message.payload.map(({ capabilities: rawCapabilities, ...page }) => {
372
+ const capabilities = shouldDisableMultipleDebuggers
373
+ ? {
374
+ ...(rawCapabilities ?? {}),
375
+ supportsMultipleDebuggers: false,
376
+ }
377
+ : (rawCapabilities ?? {});
378
+ return [
379
+ page.id,
380
+ {
381
+ ...page,
382
+ capabilities,
383
+ },
384
+ ];
385
+ }),
361
386
  );
362
387
  if (message.payload.length !== this.#pages.size) {
363
388
  const duplicateIds = new Set();
@@ -375,7 +400,6 @@ class Device {
375
400
  }
376
401
  for (const page of this.#pages.values()) {
377
402
  if (this.#pageHasCapability(page, "nativePageReloads")) {
378
- this.#logFuseboxConsoleNotice();
379
403
  continue;
380
404
  }
381
405
  if (page.title.includes("React")) {
@@ -387,31 +411,62 @@ class Device {
387
411
  }
388
412
  } else if (message.event === "disconnect") {
389
413
  const pageId = message.payload.pageId;
414
+ const sessionId = message.payload.sessionId;
390
415
  const page = this.#pages.get(pageId);
391
416
  if (page != null && this.#pageHasCapability(page, "nativePageReloads")) {
392
417
  return;
393
418
  }
394
- const debuggerSocket = this.#debuggerConnection
395
- ? this.#debuggerConnection.socket
396
- : null;
397
- if (debuggerSocket && debuggerSocket.readyState === _ws.default.OPEN) {
419
+ if (sessionId != null) {
420
+ const debuggerConnection = this.#debuggerConnections.get(sessionId);
398
421
  if (
399
- this.#debuggerConnection != null &&
400
- this.#debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID
422
+ debuggerConnection &&
423
+ debuggerConnection.socket.readyState === _ws.default.OPEN
401
424
  ) {
402
- debug(`Legacy page ${pageId} is reloading.`);
403
- debuggerSocket.send(
404
- JSON.stringify({
405
- method: "reload",
406
- }),
407
- );
425
+ if (debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID) {
426
+ debug(
427
+ `Legacy page ${pageId} is reloading (sessionId: ${sessionId}).`,
428
+ );
429
+ debuggerConnection.socket.send(
430
+ JSON.stringify({
431
+ method: "reload",
432
+ }),
433
+ );
434
+ }
435
+ }
436
+ } else {
437
+ for (const debuggerConnection of this.#debuggerConnections.values()) {
438
+ if (
439
+ debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID &&
440
+ debuggerConnection.socket.readyState === _ws.default.OPEN
441
+ ) {
442
+ debug(`Legacy page ${pageId} is reloading.`);
443
+ debuggerConnection.socket.send(
444
+ JSON.stringify({
445
+ method: "reload",
446
+ }),
447
+ );
448
+ }
408
449
  }
409
450
  }
410
451
  } else if (message.event === "wrappedEvent") {
411
- if (this.#debuggerConnection == null) {
452
+ const sessionId = message.payload.sessionId;
453
+ let debuggerConnection = null;
454
+ if (sessionId != null) {
455
+ debuggerConnection = this.#debuggerConnections.get(sessionId);
456
+ } else {
457
+ if (this.#debuggerConnections.size > 1) {
458
+ debug(
459
+ "WARNING: Device sent message without sessionId but multiple debuggers are connected. " +
460
+ "This indicates a device/proxy version mismatch.",
461
+ );
462
+ }
463
+ debuggerConnection =
464
+ this.#debuggerConnections.values().next().value ?? null;
465
+ }
466
+ if (debuggerConnection == null) {
412
467
  return;
413
468
  }
414
- const debuggerSocket = this.#debuggerConnection.socket;
469
+ const debuggerSocket = debuggerConnection.socket;
415
470
  if (
416
471
  debuggerSocket == null ||
417
472
  debuggerSocket.readyState !== _ws.default.OPEN
@@ -419,33 +474,26 @@ class Device {
419
474
  return;
420
475
  }
421
476
  const parsedPayload = JSON.parse(message.payload.wrappedEvent);
422
- const pageId = this.#debuggerConnection?.pageId ?? null;
477
+ const pageId = debuggerConnection.pageId;
423
478
  if ("id" in parsedPayload) {
424
479
  this.#deviceEventReporter?.logResponse(parsedPayload, "device", {
425
480
  pageId,
426
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
427
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
481
+ frontendUserAgent: debuggerConnection.userAgent ?? null,
428
482
  });
429
483
  }
430
- const debuggerConnection = this.#debuggerConnection;
431
- if (debuggerConnection != null) {
432
- if (
433
- debuggerConnection.customHandler?.handleDeviceMessage(
434
- parsedPayload,
435
- ) === true
436
- ) {
437
- return;
438
- }
439
- this.#processMessageFromDeviceLegacy(
440
- parsedPayload,
441
- debuggerConnection,
442
- pageId,
443
- );
444
- const messageToSend = JSON.stringify(parsedPayload);
445
- debuggerSocket.send(messageToSend);
446
- } else {
447
- debuggerSocket.send(message.payload.wrappedEvent);
484
+ if (
485
+ debuggerConnection.customHandler?.handleDeviceMessage(parsedPayload) ===
486
+ true
487
+ ) {
488
+ return;
448
489
  }
490
+ this.#processMessageFromDeviceLegacy(
491
+ parsedPayload,
492
+ debuggerConnection,
493
+ pageId,
494
+ );
495
+ const messageToSend = JSON.stringify(parsedPayload);
496
+ debuggerSocket.send(messageToSend);
449
497
  }
450
498
  }
451
499
  #sendMessageToDevice(message) {
@@ -459,10 +507,14 @@ class Device {
459
507
  }
460
508
  #newLegacyReactNativePage(page) {
461
509
  debug(`React Native page updated to ${page.id}`);
462
- if (
463
- this.#debuggerConnection == null ||
464
- this.#debuggerConnection.pageId !== REACT_NATIVE_RELOADABLE_PAGE_ID
465
- ) {
510
+ let reloadablePageDebugger = null;
511
+ for (const debuggerConnection of this.#debuggerConnections.values()) {
512
+ if (debuggerConnection.pageId === REACT_NATIVE_RELOADABLE_PAGE_ID) {
513
+ reloadablePageDebugger = debuggerConnection;
514
+ break;
515
+ }
516
+ }
517
+ if (reloadablePageDebugger == null) {
466
518
  this.#lastConnectedLegacyReactNativePage = page;
467
519
  return;
468
520
  }
@@ -470,9 +522,12 @@ class Device {
470
522
  this.#lastConnectedLegacyReactNativePage = page;
471
523
  this.#isLegacyPageReloading = true;
472
524
  if (oldPageId != null) {
473
- this.#sendDisconnectEventToDevice(oldPageId);
525
+ this.#sendDisconnectEventToDevice(
526
+ oldPageId,
527
+ reloadablePageDebugger.sessionId,
528
+ );
474
529
  }
475
- this.#sendConnectEventToDevice(page.id);
530
+ this.#sendConnectEventToDevice(page.id, reloadablePageDebugger.sessionId);
476
531
  const toSend = [
477
532
  {
478
533
  method: "Runtime.enable",
@@ -484,17 +539,17 @@ class Device {
484
539
  },
485
540
  ];
486
541
  for (const message of toSend) {
487
- const pageId = this.#debuggerConnection?.pageId ?? null;
542
+ const pageId = reloadablePageDebugger.pageId;
488
543
  this.#deviceEventReporter?.logRequest(message, "proxy", {
489
544
  pageId,
490
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
491
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
545
+ frontendUserAgent: reloadablePageDebugger.userAgent ?? null,
492
546
  });
493
547
  this.#sendMessageToDevice({
494
548
  event: "wrappedEvent",
495
549
  payload: {
496
550
  pageId: this.#mapToDevicePageId(page.id),
497
551
  wrappedEvent: JSON.stringify(message),
552
+ sessionId: reloadablePageDebugger.sessionId,
498
553
  },
499
554
  });
500
555
  }
@@ -587,17 +642,15 @@ class Device {
587
642
  id: 0,
588
643
  };
589
644
  this.#deviceEventReporter?.logRequest(resumeMessage, "proxy", {
590
- pageId: this.#debuggerConnection?.pageId ?? null,
591
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
592
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(
593
- this.#debuggerConnection?.pageId,
594
- ),
645
+ pageId: debuggerInfo.pageId,
646
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
595
647
  });
596
648
  this.#sendMessageToDevice({
597
649
  event: "wrappedEvent",
598
650
  payload: {
599
651
  pageId: this.#mapToDevicePageId(debuggerInfo.pageId),
600
652
  wrappedEvent: JSON.stringify(resumeMessage),
653
+ sessionId: debuggerInfo.sessionId,
601
654
  },
602
655
  });
603
656
  this.#isLegacyPageReloading = false;
@@ -622,7 +675,7 @@ class Device {
622
675
  case "Debugger.setBreakpointByUrl":
623
676
  return this.#processDebuggerSetBreakpointByUrl(req, debuggerInfo);
624
677
  case "Debugger.getScriptSource":
625
- void this.#processDebuggerGetScriptSource(req, socket);
678
+ void this.#processDebuggerGetScriptSource(req, socket, debuggerInfo);
626
679
  return null;
627
680
  case "Network.loadNetworkResource":
628
681
  const response = {
@@ -636,11 +689,10 @@ class Device {
636
689
  },
637
690
  };
638
691
  socket.send(JSON.stringify(response));
639
- const pageId = this.#debuggerConnection?.pageId ?? null;
692
+ const pageId = debuggerInfo.pageId;
640
693
  this.#deviceEventReporter?.logResponse(response, "proxy", {
641
694
  pageId,
642
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
643
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
695
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
644
696
  });
645
697
  return null;
646
698
  default:
@@ -684,7 +736,7 @@ class Device {
684
736
  }
685
737
  return processedReq;
686
738
  }
687
- async #processDebuggerGetScriptSource(req, socket) {
739
+ async #processDebuggerGetScriptSource(req, socket, debuggerInfo) {
688
740
  const sendSuccessResponse = (scriptSource) => {
689
741
  const response = {
690
742
  id: req.id,
@@ -693,11 +745,10 @@ class Device {
693
745
  },
694
746
  };
695
747
  socket.send(JSON.stringify(response));
696
- const pageId = this.#debuggerConnection?.pageId ?? null;
748
+ const pageId = debuggerInfo.pageId;
697
749
  this.#deviceEventReporter?.logResponse(response, "proxy", {
698
750
  pageId,
699
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
700
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
751
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
701
752
  });
702
753
  };
703
754
  const sendErrorResponse = (error) => {
@@ -710,12 +761,11 @@ class Device {
710
761
  },
711
762
  };
712
763
  socket.send(JSON.stringify(response));
713
- this.#sendErrorToDebugger(error);
714
- const pageId = this.#debuggerConnection?.pageId ?? null;
764
+ this.#sendErrorToDebugger(error, debuggerInfo);
765
+ const pageId = debuggerInfo.pageId;
715
766
  this.#deviceEventReporter?.logResponse(response, "proxy", {
716
767
  pageId,
717
- frontendUserAgent: this.#debuggerConnection?.userAgent ?? null,
718
- prefersFuseboxFrontend: this.#isPageFuseboxFrontend(pageId),
768
+ frontendUserAgent: debuggerInfo.userAgent ?? null,
719
769
  });
720
770
  };
721
771
  const pathToSource = this.#scriptIdToSourcePathMapping.get(
@@ -769,8 +819,8 @@ class Device {
769
819
  }
770
820
  return text;
771
821
  }
772
- #sendErrorToDebugger(message) {
773
- const debuggerSocket = this.#debuggerConnection?.socket;
822
+ #sendErrorToDebugger(message, debuggerInfo) {
823
+ const debuggerSocket = debuggerInfo?.socket;
774
824
  if (debuggerSocket && debuggerSocket.readyState === _ws.default.OPEN) {
775
825
  debuggerSocket.send(
776
826
  JSON.stringify({
@@ -789,22 +839,8 @@ class Device {
789
839
  );
790
840
  }
791
841
  }
792
- #isPageFuseboxFrontend(pageId) {
793
- const page = pageId == null ? null : this.#pages.get(pageId);
794
- if (page == null) {
795
- return null;
796
- }
797
- return this.#pageHasCapability(page, "prefersFuseboxFrontend");
798
- }
799
842
  dangerouslyGetSocket() {
800
843
  return this.#deviceSocket;
801
844
  }
802
- #logFuseboxConsoleNotice() {
803
- if (fuseboxConsoleNoticeLogged) {
804
- return;
805
- }
806
- this.#deviceEventReporter?.logFuseboxConsoleNotice();
807
- fuseboxConsoleNoticeLogged = true;
808
- }
809
845
  }
810
846
  exports.default = Device;
@@ -9,6 +9,8 @@
9
9
  */
10
10
 
11
11
  import type { EventReporter } from "../types/EventReporter";
12
+ import type { Experiments } from "../types/Experiments";
13
+ import type { ReadonlyURL } from "../types/ReadonlyURL";
12
14
  import type { CreateCustomMessageHandlerFn } from "./CustomMessageHandler";
13
15
  import type { Page } from "./types";
14
16
 
@@ -23,16 +25,17 @@ declare export const WS_CLOSE_REASON: {
23
25
  NEW_DEBUGGER_OPENED: "[NEW_DEBUGGER_OPENED] New debugger opened for the same app instance",
24
26
  };
25
27
 
26
- export type DeviceOptions = $ReadOnly<{
28
+ export type DeviceOptions = Readonly<{
27
29
  id: string,
28
30
  name: string,
29
31
  app: string,
30
32
  socket: WS,
31
33
  eventReporter: ?EventReporter,
32
34
  createMessageMiddleware: ?CreateCustomMessageHandlerFn,
33
- deviceRelativeBaseUrl: URL,
34
- serverRelativeBaseUrl: URL,
35
+ deviceRelativeBaseUrl: ReadonlyURL,
36
+ serverRelativeBaseUrl: ReadonlyURL,
35
37
  isProfilingBuild: boolean,
38
+ experiments: Experiments,
36
39
  }>;
37
40
 
38
41
  /**
@@ -53,7 +56,7 @@ declare export default class Device {
53
56
  dangerouslyRecreateDevice(deviceOptions: DeviceOptions): void;
54
57
  getName(): string;
55
58
  getApp(): string;
56
- getPagesList(): $ReadOnlyArray<Page>;
59
+ getPagesList(): ReadonlyArray<Page>;
57
60
  // Handles new debugger connection to this device:
58
61
  // 1. Sends connect event to device
59
62
  // 2. Forwards all messages from the debugger to device as wrappedEvent
@@ -61,8 +64,8 @@ declare export default class Device {
61
64
  handleDebuggerConnection(
62
65
  socket: WS,
63
66
  pageId: string,
64
- $$PARAM_2$$: $ReadOnly<{
65
- debuggerRelativeBaseUrl: URL,
67
+ $$PARAM_2$$: Readonly<{
68
+ debuggerRelativeBaseUrl: ReadonlyURL,
66
69
  userAgent: string | null,
67
70
  }>,
68
71
  ): void;