@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.
@@ -9978,7 +9978,7 @@ const DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE = 100000;
9978
9978
  const SESSION_RESPONSE = 'multiplayer-debug-session-response';
9979
9979
  const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
9980
9980
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
9981
- const PACKAGE_VERSION_EXPORT = "1.2.34" || 0;
9981
+ const PACKAGE_VERSION_EXPORT = "1.2.35" || 0;
9982
9982
  // Regex patterns for OpenTelemetry ignore URLs
9983
9983
  const OTEL_IGNORE_URLS = [
9984
9984
  // Traces endpoint
package/dist/index.js CHANGED
@@ -24143,7 +24143,7 @@ const DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE = 100000;
24143
24143
  const SESSION_RESPONSE = 'multiplayer-debug-session-response';
24144
24144
  const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
24145
24145
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
24146
- const PACKAGE_VERSION_EXPORT = "1.2.34" || 0;
24146
+ const PACKAGE_VERSION_EXPORT = "1.2.35" || 0;
24147
24147
  // Regex patterns for OpenTelemetry ignore URLs
24148
24148
  const OTEL_IGNORE_URLS = [
24149
24149
  // Traces endpoint
@@ -25376,91 +25376,84 @@ function _headersInitToObject(headersInit) {
25376
25376
  return result;
25377
25377
  }
25378
25378
  if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
25379
- // Store original fetch
25380
- const originalFetch = window.fetch;
25381
- // Override fetch
25382
- window.fetch = async function (input,
25383
- // eslint-disable-next-line
25384
- init) {
25385
- const networkRequest = {};
25386
- // Capture request data
25387
- const inputIsRequest = typeof Request !== 'undefined' && input instanceof Request;
25388
- const safeToConstructRequest = !inputIsRequest || !input.bodyUsed;
25389
- // Only construct a new Request when it's safe (i.e., body not already used)
25390
- let requestForMetadata = null;
25391
- if (safeToConstructRequest) {
25392
- try {
25393
- requestForMetadata = new Request(input, init);
25394
- }
25395
- catch (_a) {
25396
- // If construction fails for any reason, fall back to using available data
25397
- requestForMetadata = null;
25398
- }
25399
- }
25400
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
25401
- if (requestForMetadata) {
25402
- networkRequest.requestHeaders = _headersToObject(requestForMetadata.headers);
25403
- }
25404
- else if (inputIsRequest) {
25405
- networkRequest.requestHeaders = _headersToObject(input.headers);
25406
- }
25407
- else {
25408
- networkRequest.requestHeaders = _headersInitToObject(init === null || init === void 0 ? void 0 : init.headers);
25409
- }
25410
- }
25411
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25412
- // Prefer reading from the safely constructed Request; else fallback to init.body
25413
- const urlStr = inputIsRequest
25414
- ? input.url
25415
- : (typeof input === 'string' || input instanceof URL ? String(input) : '');
25416
- const candidateBody = requestForMetadata
25417
- ? requestForMetadata.body
25418
- : (inputIsRequest ? init === null || init === void 0 ? void 0 : init.body : init === null || init === void 0 ? void 0 : init.body);
25419
- if (!(0,_utils_type_utils__WEBPACK_IMPORTED_MODULE_0__.isNullish)(candidateBody)) {
25420
- const requestBody = _tryReadFetchBody({
25421
- body: candidateBody,
25422
- url: urlStr,
25423
- });
25424
- if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length) &&
25425
- new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25426
- networkRequest.requestBody = requestBody;
25379
+ // Idempotency guard: avoid double-patching
25380
+ // @ts-ignore
25381
+ if (window.fetch.__mp_session_recorder_patched__) {
25382
+ // Already patched; do nothing
25383
+ }
25384
+ else {
25385
+ // @ts-ignore
25386
+ window.fetch.__mp_session_recorder_patched__ = true;
25387
+ // Store original fetch
25388
+ const originalFetch = window.fetch;
25389
+ // Override fetch
25390
+ window.fetch = async function (input,
25391
+ // eslint-disable-next-line
25392
+ init) {
25393
+ const networkRequest = {};
25394
+ // Capture request data
25395
+ const inputIsRequest = typeof Request !== 'undefined' && input instanceof Request;
25396
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
25397
+ if (inputIsRequest) {
25398
+ networkRequest.requestHeaders = _headersToObject(input.headers);
25399
+ }
25400
+ else {
25401
+ networkRequest.requestHeaders = _headersInitToObject(init === null || init === void 0 ? void 0 : init.headers);
25427
25402
  }
25428
- }
25429
- }
25430
- try {
25431
- // Make the actual fetch request
25432
- const response = await originalFetch(input, init);
25433
- // Capture response data
25434
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
25435
- networkRequest.responseHeaders = _headersToObject(response.headers);
25436
25403
  }
25437
25404
  if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25438
- const responseBody = await _tryReadResponseBody(response);
25439
- if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length) &&
25440
- new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25441
- networkRequest.responseBody = responseBody;
25405
+ const urlStr = inputIsRequest
25406
+ ? input.url
25407
+ : (typeof input === 'string' || input instanceof URL ? String(input) : '');
25408
+ // Only attempt to read the body from init (safe); avoid constructing/cloning Requests
25409
+ // If the caller passed a Request as input, we do not attempt to read its body here
25410
+ const candidateBody = init === null || init === void 0 ? void 0 : init.body;
25411
+ if (!(0,_utils_type_utils__WEBPACK_IMPORTED_MODULE_0__.isNullish)(candidateBody)) {
25412
+ const requestBody = _tryReadFetchBody({
25413
+ body: candidateBody,
25414
+ url: urlStr,
25415
+ });
25416
+ if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length) &&
25417
+ new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25418
+ networkRequest.requestBody = requestBody;
25419
+ }
25442
25420
  }
25443
25421
  }
25444
- // Attach network request data to the response for later access
25445
- // @ts-ignore
25446
- response.networkRequest = networkRequest;
25447
- return response;
25448
- }
25449
- catch (error) {
25450
- // Even if the fetch fails, we can still capture the request data
25451
- // Attach captured request data to the thrown error for downstream handling
25452
- // @ts-ignore
25453
- if (error && typeof error === 'object') {
25422
+ try {
25423
+ // Make the actual fetch request
25424
+ const response = await originalFetch(input, init);
25425
+ // Capture response data
25426
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
25427
+ networkRequest.responseHeaders = _headersToObject(response.headers);
25428
+ }
25429
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25430
+ const responseBody = await _tryReadResponseBody(response);
25431
+ if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length) &&
25432
+ new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25433
+ networkRequest.responseBody = responseBody;
25434
+ }
25435
+ }
25436
+ // Attach network request data to the response for later access
25454
25437
  // @ts-ignore
25455
- error.networkRequest = networkRequest;
25438
+ response.networkRequest = networkRequest;
25439
+ return response;
25456
25440
  }
25457
- throw error;
25458
- }
25459
- };
25460
- // Preserve the original fetch function's properties
25461
- Object.setPrototypeOf(window.fetch, originalFetch);
25462
- Object.defineProperty(window.fetch, 'name', { value: 'fetch' });
25463
- Object.defineProperty(window.fetch, 'length', { value: originalFetch.length });
25441
+ catch (error) {
25442
+ // Even if the fetch fails, we can still capture the request data
25443
+ // Attach captured request data to the thrown error for downstream handling
25444
+ // @ts-ignore
25445
+ if (error && typeof error === 'object') {
25446
+ // @ts-ignore
25447
+ error.networkRequest = networkRequest;
25448
+ }
25449
+ throw error;
25450
+ }
25451
+ };
25452
+ // Preserve the original fetch function's properties
25453
+ Object.setPrototypeOf(window.fetch, originalFetch);
25454
+ Object.defineProperty(window.fetch, 'name', { value: 'fetch' });
25455
+ Object.defineProperty(window.fetch, 'length', { value: originalFetch.length });
25456
+ }
25464
25457
  }
25465
25458
 
25466
25459