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

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.36" || 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.36" || 0;
24147
24147
  // Regex patterns for OpenTelemetry ignore URLs
24148
24148
  const OTEL_IGNORE_URLS = [
24149
24149
  // Traces endpoint
@@ -24762,6 +24762,7 @@ class NavigationRecorder {
24762
24762
 
24763
24763
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
24764
24764
  /* harmony export */ extractResponseBody: () => (/* binding */ extractResponseBody),
24765
+ /* harmony export */ getElementTextContent: () => (/* binding */ getElementTextContent),
24765
24766
  /* harmony export */ getExporterEndpoint: () => (/* binding */ getExporterEndpoint),
24766
24767
  /* harmony export */ headersToObject: () => (/* binding */ headersToObject),
24767
24768
  /* harmony export */ processHttpPayload: () => (/* binding */ processHttpPayload)
@@ -24968,6 +24969,16 @@ const getExporterEndpoint = (exporterEndpoint) => {
24968
24969
  const trimmedExporterEndpoint = new URL(exporterEndpoint).origin;
24969
24970
  return `${trimmedExporterEndpoint}/v1/traces`;
24970
24971
  };
24972
+ const getElementTextContent = (element) => {
24973
+ const getInnerText = (element) => {
24974
+ const slicedText = element.innerText.slice(0, 50);
24975
+ if (slicedText.length < element.innerText.length) {
24976
+ return `${slicedText}...`;
24977
+ }
24978
+ return slicedText;
24979
+ };
24980
+ return String(element.textContent || element.ariaLabel || getInnerText(element) || '').trim();
24981
+ };
24971
24982
 
24972
24983
 
24973
24984
  /***/ }),
@@ -25008,7 +25019,6 @@ const getExporterEndpoint = (exporterEndpoint) => {
25008
25019
 
25009
25020
  class TracerBrowserSDK {
25010
25021
  constructor() {
25011
- this.allowedElements = new Set(['A', 'BUTTON']);
25012
25022
  this.sessionId = '';
25013
25023
  this.globalErrorListenersRegistered = false;
25014
25024
  }
@@ -25138,11 +25148,10 @@ class TracerBrowserSDK {
25138
25148
  if (span['parentSpanContext']) {
25139
25149
  return true;
25140
25150
  }
25141
- let textContent = '';
25142
- if (this.allowedElements.has(element.tagName)) {
25143
- textContent = String(element.textContent || element.ariaLabel || '').trim();
25144
- }
25145
- span.setAttribute('target.innerText', textContent);
25151
+ span.setAttribute('target.innerText', (0,_helpers__WEBPACK_IMPORTED_MODULE_3__.getElementTextContent)(element));
25152
+ Array.from(element.attributes).forEach(attribute => {
25153
+ span.setAttribute(`target.attribute.${attribute.name}`, attribute.value);
25154
+ });
25146
25155
  return false;
25147
25156
  },
25148
25157
  },
@@ -25376,91 +25385,84 @@ function _headersInitToObject(headersInit) {
25376
25385
  return result;
25377
25386
  }
25378
25387
  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;
25388
+ // Idempotency guard: avoid double-patching
25389
+ // @ts-ignore
25390
+ if (window.fetch.__mp_session_recorder_patched__) {
25391
+ // Already patched; do nothing
25392
+ }
25393
+ else {
25394
+ // @ts-ignore
25395
+ window.fetch.__mp_session_recorder_patched__ = true;
25396
+ // Store original fetch
25397
+ const originalFetch = window.fetch;
25398
+ // Override fetch
25399
+ window.fetch = async function (input,
25400
+ // eslint-disable-next-line
25401
+ init) {
25402
+ const networkRequest = {};
25403
+ // Capture request data
25404
+ const inputIsRequest = typeof Request !== 'undefined' && input instanceof Request;
25405
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordRequestHeaders) {
25406
+ if (inputIsRequest) {
25407
+ networkRequest.requestHeaders = _headersToObject(input.headers);
25408
+ }
25409
+ else {
25410
+ networkRequest.requestHeaders = _headersInitToObject(init === null || init === void 0 ? void 0 : init.headers);
25427
25411
  }
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
25412
  }
25437
25413
  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;
25414
+ const urlStr = inputIsRequest
25415
+ ? input.url
25416
+ : (typeof input === 'string' || input instanceof URL ? String(input) : '');
25417
+ // Only attempt to read the body from init (safe); avoid constructing/cloning Requests
25418
+ // If the caller passed a Request as input, we do not attempt to read its body here
25419
+ const candidateBody = init === null || init === void 0 ? void 0 : init.body;
25420
+ if (!(0,_utils_type_utils__WEBPACK_IMPORTED_MODULE_0__.isNullish)(candidateBody)) {
25421
+ const requestBody = _tryReadFetchBody({
25422
+ body: candidateBody,
25423
+ url: urlStr,
25424
+ });
25425
+ if ((requestBody === null || requestBody === void 0 ? void 0 : requestBody.length) &&
25426
+ new Blob([requestBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25427
+ networkRequest.requestBody = requestBody;
25428
+ }
25442
25429
  }
25443
25430
  }
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') {
25431
+ try {
25432
+ // Make the actual fetch request
25433
+ const response = await originalFetch(input, init);
25434
+ // Capture response data
25435
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.recordResponseHeaders) {
25436
+ networkRequest.responseHeaders = _headersToObject(response.headers);
25437
+ }
25438
+ if (_configs__WEBPACK_IMPORTED_MODULE_2__.configs.shouldRecordBody) {
25439
+ const responseBody = await _tryReadResponseBody(response);
25440
+ if ((responseBody === null || responseBody === void 0 ? void 0 : responseBody.length) &&
25441
+ new Blob([responseBody]).size <= _configs__WEBPACK_IMPORTED_MODULE_2__.configs.maxCapturingHttpPayloadSize) {
25442
+ networkRequest.responseBody = responseBody;
25443
+ }
25444
+ }
25445
+ // Attach network request data to the response for later access
25454
25446
  // @ts-ignore
25455
- error.networkRequest = networkRequest;
25447
+ response.networkRequest = networkRequest;
25448
+ return response;
25456
25449
  }
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 });
25450
+ catch (error) {
25451
+ // Even if the fetch fails, we can still capture the request data
25452
+ // Attach captured request data to the thrown error for downstream handling
25453
+ // @ts-ignore
25454
+ if (error && typeof error === 'object') {
25455
+ // @ts-ignore
25456
+ error.networkRequest = networkRequest;
25457
+ }
25458
+ throw error;
25459
+ }
25460
+ };
25461
+ // Preserve the original fetch function's properties
25462
+ Object.setPrototypeOf(window.fetch, originalFetch);
25463
+ Object.defineProperty(window.fetch, 'name', { value: 'fetch' });
25464
+ Object.defineProperty(window.fetch, 'length', { value: originalFetch.length });
25465
+ }
25464
25466
  }
25465
25467
 
25466
25468