@multiplayer-app/session-recorder-browser 1.2.28 → 1.2.29

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.
@@ -25094,7 +25094,7 @@ const DEFAULT_MAX_HTTP_CAPTURING_PAYLOAD_SIZE = 100000;
25094
25094
  const SESSION_RESPONSE = 'multiplayer-debug-session-response';
25095
25095
  const CONTINUOUS_DEBUGGING_TIMEOUT = 60000; // 1 minutes
25096
25096
  const DEBUG_SESSION_MAX_DURATION_SECONDS = 10 * 60 + 30; // TODO: move to shared config otel core
25097
- const PACKAGE_VERSION_EXPORT = "1.2.28" || 0;
25097
+ const PACKAGE_VERSION_EXPORT = "1.2.29" || 0;
25098
25098
  // Regex patterns for OpenTelemetry ignore URLs
25099
25099
  const OTEL_IGNORE_URLS = [
25100
25100
  // Traces endpoint
@@ -26518,64 +26518,86 @@ function _tryReadXHRBody({ body, url, }) {
26518
26518
  }
26519
26519
  return `[XHR] Cannot read body of type ${toString.call(body)}`;
26520
26520
  }
26521
- (function (xhr) {
26522
- const originalOpen = XMLHttpRequest.prototype.open;
26523
- xhr.open = function (method, url, async = true, username, password) {
26524
- const xhr = this;
26525
- const networkRequest = {};
26521
+ function _isWithinPayloadLimit(payload) {
26522
+ try {
26523
+ if (typeof Blob !== 'undefined') {
26524
+ return new Blob([payload]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize;
26525
+ }
26526
+ }
26527
+ catch (_a) {
26528
+ // ignore and fallback to string length
26529
+ }
26530
+ return payload.length <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize;
26531
+ }
26532
+ // Only patch XHR in environments where it exists (avoid SSR/Node)
26533
+ if (typeof XMLHttpRequest !== 'undefined') {
26534
+ (function (xhr) {
26535
+ // Idempotency guard: avoid double-patching
26526
26536
  // @ts-ignore
26527
- const requestHeaders = {};
26528
- const originalSetRequestHeader = xhr.setRequestHeader.bind(xhr);
26529
- xhr.setRequestHeader = (header, value) => {
26530
- requestHeaders[header] = value;
26531
- return originalSetRequestHeader(header, value);
26532
- };
26533
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
26534
- networkRequest.requestHeaders = requestHeaders;
26535
- }
26536
- const originalSend = xhr.send.bind(xhr);
26537
- xhr.send = (body) => {
26538
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
26539
- const requestBody = _tryReadXHRBody({ body, url });
26540
- if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length)
26541
- && new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
26542
- networkRequest.requestBody = requestBody;
26543
- }
26544
- }
26545
- return originalSend(body);
26546
- };
26547
- xhr.addEventListener('readystatechange', () => {
26548
- if (xhr.readyState !== xhr.DONE) {
26549
- return;
26550
- }
26537
+ if (xhr.__mp_session_recorder_patched__) {
26538
+ return;
26539
+ }
26540
+ // @ts-ignore
26541
+ ;
26542
+ xhr.__mp_session_recorder_patched__ = true;
26543
+ const originalOpen = xhr.open;
26544
+ xhr.open = function (method, url, async = true, username, password) {
26545
+ const xhr = this;
26546
+ const networkRequest = {};
26551
26547
  // @ts-ignore
26552
- const responseHeaders = {};
26553
- const rawHeaders = xhr.getAllResponseHeaders();
26554
- const headers = rawHeaders.trim().split(/[\r\n]+/);
26555
- headers.forEach((line) => {
26556
- const parts = line.split(': ');
26557
- const header = parts.shift();
26558
- const value = parts.join(': ');
26559
- if (header) {
26560
- responseHeaders[header] = value;
26548
+ const requestHeaders = {};
26549
+ const originalSetRequestHeader = xhr.setRequestHeader.bind(xhr);
26550
+ xhr.setRequestHeader = (header, value) => {
26551
+ requestHeaders[header] = value;
26552
+ return originalSetRequestHeader(header, value);
26553
+ };
26554
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
26555
+ networkRequest.requestHeaders = requestHeaders;
26556
+ }
26557
+ const originalSend = xhr.send.bind(xhr);
26558
+ xhr.send = (body) => {
26559
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
26560
+ const requestBody = _tryReadXHRBody({ body, url });
26561
+ if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length)
26562
+ && _isWithinPayloadLimit(requestBody)) {
26563
+ networkRequest.requestBody = requestBody;
26564
+ }
26561
26565
  }
26562
- });
26563
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
26564
- networkRequest.responseHeaders = responseHeaders;
26565
- }
26566
- if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
26567
- const responseBody = _tryReadXHRBody({ body: xhr.response, url });
26568
- if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length)
26569
- && new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
26570
- networkRequest.responseBody = responseBody;
26566
+ return originalSend(body);
26567
+ };
26568
+ xhr.addEventListener('readystatechange', () => {
26569
+ if (xhr.readyState !== xhr.DONE) {
26570
+ return;
26571
26571
  }
26572
- }
26573
- });
26574
- // @ts-ignore
26575
- xhr.networkRequest = networkRequest;
26576
- originalOpen.call(xhr, method, url, async, username, password);
26577
- };
26578
- })(XMLHttpRequest.prototype);
26572
+ // @ts-ignore
26573
+ const responseHeaders = {};
26574
+ const rawHeaders = xhr.getAllResponseHeaders();
26575
+ const headers = rawHeaders.trim().split(/[\r\n]+/);
26576
+ headers.forEach((line) => {
26577
+ const parts = line.split(': ');
26578
+ const header = parts.shift();
26579
+ const value = parts.join(': ');
26580
+ if (header) {
26581
+ responseHeaders[header] = value;
26582
+ }
26583
+ });
26584
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
26585
+ networkRequest.responseHeaders = responseHeaders;
26586
+ }
26587
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
26588
+ const responseBody = _tryReadXHRBody({ body: xhr.response, url });
26589
+ if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length)
26590
+ && _isWithinPayloadLimit(responseBody)) {
26591
+ networkRequest.responseBody = responseBody;
26592
+ }
26593
+ }
26594
+ });
26595
+ // @ts-ignore
26596
+ xhr.networkRequest = networkRequest;
26597
+ originalOpen.call(xhr, method, url, async, username, password);
26598
+ };
26599
+ })(XMLHttpRequest.prototype);
26600
+ }
26579
26601
 
26580
26602
 
26581
26603
  /***/ }),