@multiplayer-app/session-recorder-browser 1.2.34 → 1.2.35

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.
package/dist/index.umd.js CHANGED
@@ -24317,7 +24317,7 @@ const DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE = 100000;
24317
24317
  const SESSION_RESPONSE = 'multiplayer-debug-session-response';
24318
24318
  const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
24319
24319
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
24320
- const PACKAGE_VERSION_EXPORT = "1.2.34" || 0;
24320
+ const PACKAGE_VERSION_EXPORT = "1.2.35" || 0;
24321
24321
  // Regex patterns for OpenTelemetry ignore URLs
24322
24322
  const OTEL_IGNORE_URLS = [
24323
24323
  // Traces endpoint
@@ -25564,91 +25564,84 @@ function _headersInitToObject(headersInit) {
25564
25564
  return result;
25565
25565
  }
25566
25566
  if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
25567
- // Store original fetch
25568
- const originalFetch = window.fetch;
25569
- // Override fetch
25570
- window.fetch = async function (input,
25571
- // eslint-disable-next-line
25572
- init) {
25573
- const networkRequest = {};
25574
- // Capture request data
25575
- const inputIsRequest = typeof Request !== 'undefined' && input instanceof Request;
25576
- const safeToConstructRequest = !inputIsRequest || !input.bodyUsed;
25577
- // Only construct a new Request when it's safe (i.e., body not already used)
25578
- let requestForMetadata = null;
25579
- if (safeToConstructRequest) {
25580
- try {
25581
- requestForMetadata = new Request(input, init);
25582
- }
25583
- catch (_a) {
25584
- // If construction fails for any reason, fall back to using available data
25585
- requestForMetadata = null;
25586
- }
25587
- }
25588
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
25589
- if (requestForMetadata) {
25590
- networkRequest.requestHeaders = _headersToObject(requestForMetadata.headers);
25591
- }
25592
- else if (inputIsRequest) {
25593
- networkRequest.requestHeaders = _headersToObject(input.headers);
25594
- }
25595
- else {
25596
- networkRequest.requestHeaders = _headersInitToObject(init === null || init === void 0 ? void 0 : init.headers);
25597
- }
25598
- }
25599
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25600
- // Prefer reading from the safely constructed Request; else fallback to init.body
25601
- const urlStr = inputIsRequest
25602
- ? input.url
25603
- : (typeof input === 'string' || input instanceof URL ? String(input) : '');
25604
- const candidateBody = requestForMetadata
25605
- ? requestForMetadata.body
25606
- : (inputIsRequest ? init === null || init === void 0 ? void 0 : init.body : init === null || init === void 0 ? void 0 : init.body);
25607
- if (!(0,_utils_type_utils__WEBPACK_IMPORTED_MODULE_0__.isNullish)(candidateBody)) {
25608
- const requestBody = _tryReadFetchBody({
25609
- body: candidateBody,
25610
- url: urlStr,
25611
- });
25612
- if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length) &&
25613
- new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25614
- networkRequest.requestBody = requestBody;
25567
+ // Idempotency guard: avoid double-patching
25568
+ // @ts-ignore
25569
+ if (window.fetch.__mp_session_recorder_patched__) {
25570
+ // Already patched; do nothing
25571
+ }
25572
+ else {
25573
+ // @ts-ignore
25574
+ window.fetch.__mp_session_recorder_patched__ = true;
25575
+ // Store original fetch
25576
+ const originalFetch = window.fetch;
25577
+ // Override fetch
25578
+ window.fetch = async function (input,
25579
+ // eslint-disable-next-line
25580
+ init) {
25581
+ const networkRequest = {};
25582
+ // Capture request data
25583
+ const inputIsRequest = typeof Request !== 'undefined' && input instanceof Request;
25584
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
25585
+ if (inputIsRequest) {
25586
+ networkRequest.requestHeaders = _headersToObject(input.headers);
25587
+ }
25588
+ else {
25589
+ networkRequest.requestHeaders = _headersInitToObject(init === null || init === void 0 ? void 0 : init.headers);
25615
25590
  }
25616
- }
25617
- }
25618
- try {
25619
- // Make the actual fetch request
25620
- const response = await originalFetch(input, init);
25621
- // Capture response data
25622
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
25623
- networkRequest.responseHeaders = _headersToObject(response.headers);
25624
25591
  }
25625
25592
  if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25626
- const responseBody = await _tryReadResponseBody(response);
25627
- if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length) &&
25628
- new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25629
- networkRequest.responseBody = responseBody;
25593
+ const urlStr = inputIsRequest
25594
+ ? input.url
25595
+ : (typeof input === 'string' || input instanceof URL ? String(input) : '');
25596
+ // Only attempt to read the body from init (safe); avoid constructing/cloning Requests
25597
+ // If the caller passed a Request as input, we do not attempt to read its body here
25598
+ const candidateBody = init === null || init === void 0 ? void 0 : init.body;
25599
+ if (!(0,_utils_type_utils__WEBPACK_IMPORTED_MODULE_0__.isNullish)(candidateBody)) {
25600
+ const requestBody = _tryReadFetchBody({
25601
+ body: candidateBody,
25602
+ url: urlStr,
25603
+ });
25604
+ if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length) &&
25605
+ new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25606
+ networkRequest.requestBody = requestBody;
25607
+ }
25630
25608
  }
25631
25609
  }
25632
- // Attach network request data to the response for later access
25633
- // @ts-ignore
25634
- response.networkRequest = networkRequest;
25635
- return response;
25636
- }
25637
- catch (error) {
25638
- // Even if the fetch fails, we can still capture the request data
25639
- // Attach captured request data to the thrown error for downstream handling
25640
- // @ts-ignore
25641
- if (error && typeof error === 'object') {
25610
+ try {
25611
+ // Make the actual fetch request
25612
+ const response = await originalFetch(input, init);
25613
+ // Capture response data
25614
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
25615
+ networkRequest.responseHeaders = _headersToObject(response.headers);
25616
+ }
25617
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25618
+ const responseBody = await _tryReadResponseBody(response);
25619
+ if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length) &&
25620
+ new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25621
+ networkRequest.responseBody = responseBody;
25622
+ }
25623
+ }
25624
+ // Attach network request data to the response for later access
25642
25625
  // @ts-ignore
25643
- error.networkRequest = networkRequest;
25626
+ response.networkRequest = networkRequest;
25627
+ return response;
25644
25628
  }
25645
- throw error;
25646
- }
25647
- };
25648
- // Preserve the original fetch function's properties
25649
- Object.setPrototypeOf(window.fetch, originalFetch);
25650
- Object.defineProperty(window.fetch, 'name', { value: 'fetch' });
25651
- Object.defineProperty(window.fetch, 'length', { value: originalFetch.length });
25629
+ catch (error) {
25630
+ // Even if the fetch fails, we can still capture the request data
25631
+ // Attach captured request data to the thrown error for downstream handling
25632
+ // @ts-ignore
25633
+ if (error && typeof error === 'object') {
25634
+ // @ts-ignore
25635
+ error.networkRequest = networkRequest;
25636
+ }
25637
+ throw error;
25638
+ }
25639
+ };
25640
+ // Preserve the original fetch function's properties
25641
+ Object.setPrototypeOf(window.fetch, originalFetch);
25642
+ Object.defineProperty(window.fetch, 'name', { value: 'fetch' });
25643
+ Object.defineProperty(window.fetch, 'length', { value: originalFetch.length });
25644
+ }
25652
25645
  }
25653
25646
 
25654
25647