@coralogix/browser 2.0.0 → 2.1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.1.0 (2025-02-18)
2
+
3
+ ### 🚀 Features
4
+
5
+ - Improved initialization for SSR applications.
6
+
1
7
  # 2.0.0 (2025-01-29)
2
8
 
3
9
  ### 🚀 Features
package/index.esm.js CHANGED
@@ -258,17 +258,44 @@ var INITIAL_SNAPSHOT_CONTEXT = {
258
258
  hasScreenshot: false,
259
259
  };
260
260
 
261
+ function getCxGlobal() {
262
+ if (typeof globalThis === 'object') {
263
+ return globalThis;
264
+ }
265
+ Object.defineProperty(Object.prototype, '__cx_global__', {
266
+ get: function () {
267
+ return this;
268
+ },
269
+ configurable: true,
270
+ });
271
+ var globalObject = __cx_global__;
272
+ delete Object.prototype.__cx_global__;
273
+ if (typeof globalObject !== 'object') {
274
+ if (typeof self === 'object') {
275
+ globalObject = self;
276
+ }
277
+ else if (typeof window === 'object') {
278
+ globalObject = window;
279
+ }
280
+ else {
281
+ globalObject = {};
282
+ }
283
+ }
284
+ return globalObject;
285
+ }
286
+ var CxGlobal = getCxGlobal();
287
+
261
288
  function getSnapshotManager() {
262
- return window[SNAPSHOT_MANAGER_KEY];
289
+ return CxGlobal[SNAPSHOT_MANAGER_KEY];
263
290
  }
264
291
  function getSessionManager() {
265
- return window[SESSION_MANAGER_KEY];
292
+ return CxGlobal[SESSION_MANAGER_KEY];
266
293
  }
267
294
  function getSessionRecorder() {
268
- return window[SESSION_RECORDER_KEY];
295
+ return CxGlobal[SESSION_RECORDER_KEY];
269
296
  }
270
297
  function getSdkConfig() {
271
- return window[SDK_CONFIG_KEY];
298
+ return CxGlobal[SDK_CONFIG_KEY];
272
299
  }
273
300
 
274
301
  var GLOBAL_SPAN_KEY = '__globalSpan__';
@@ -276,25 +303,25 @@ var CUSTOM_TRACER_KEY = '__customTracer__';
276
303
  var CUSTOM_TRACER_IGNORED_INSTRUMENTS = '__customTracerIgnoredInstruments__';
277
304
 
278
305
  function setGlobalSpan(globalSpan) {
279
- window[GLOBAL_SPAN_KEY] = globalSpan;
306
+ CxGlobal[GLOBAL_SPAN_KEY] = globalSpan;
280
307
  }
281
308
  function getGlobalSpan() {
282
- return window[GLOBAL_SPAN_KEY];
309
+ return CxGlobal[GLOBAL_SPAN_KEY];
283
310
  }
284
311
  function clearGlobalSpan() {
285
- delete window[GLOBAL_SPAN_KEY];
312
+ delete CxGlobal[GLOBAL_SPAN_KEY];
286
313
  }
287
314
  function setCustomTracer(customTracer) {
288
- window[CUSTOM_TRACER_KEY] = customTracer;
315
+ CxGlobal[CUSTOM_TRACER_KEY] = customTracer;
289
316
  }
290
317
  function getCustomTracer() {
291
- return window[CUSTOM_TRACER_KEY];
318
+ return CxGlobal[CUSTOM_TRACER_KEY];
292
319
  }
293
320
  function setCustomTracerIgnoredInstruments(ignoredInstruments) {
294
- window[CUSTOM_TRACER_IGNORED_INSTRUMENTS] = ignoredInstruments;
321
+ CxGlobal[CUSTOM_TRACER_IGNORED_INSTRUMENTS] = ignoredInstruments;
295
322
  }
296
323
  function getCustomTracerIgnoredInstruments() {
297
- return window[CUSTOM_TRACER_IGNORED_INSTRUMENTS];
324
+ return CxGlobal[CUSTOM_TRACER_IGNORED_INSTRUMENTS];
298
325
  }
299
326
  function shouldAttachSpanToGlobalSpan(instrumentationType) {
300
327
  var _a;
@@ -338,10 +365,10 @@ function shouldAddOtelAttr(span) {
338
365
  return !!span[IS_OTEL_READY];
339
366
  }
340
367
  function setAttrProcessor(processor) {
341
- window[ATTR_PROCESSOR_KEY] = processor;
368
+ CxGlobal[ATTR_PROCESSOR_KEY] = processor;
342
369
  }
343
370
  function getAttrProcessor() {
344
- return window[ATTR_PROCESSOR_KEY];
371
+ return CxGlobal[ATTR_PROCESSOR_KEY];
345
372
  }
346
373
 
347
374
  function setCustomLabelsForSpan(span, labels) {
@@ -450,7 +477,7 @@ function extractMetadataFromMfeStacktrace() {
450
477
  return __generator(this, function (_c) {
451
478
  switch (_c.label) {
452
479
  case 0:
453
- cachedMetadata = window[CACHED_METADATA_KEY];
480
+ cachedMetadata = CxGlobal[CACHED_METADATA_KEY];
454
481
  MFE_METADATA_KEY = 'cx-metadata.json';
455
482
  _a = __read$1(fileName.match(/https?:\/\/.*\//), 1), mfePath = _a[0];
456
483
  if (!mfePath) return [3 /*break*/, 7];
@@ -477,7 +504,7 @@ function extractMetadataFromMfeStacktrace() {
477
504
  }
478
505
  return [3 /*break*/, 5];
479
506
  case 5:
480
- window[CACHED_METADATA_KEY] = cachedMetadata.set(mfePath, metadata);
507
+ CxGlobal[CACHED_METADATA_KEY] = cachedMetadata.set(mfePath, metadata);
481
508
  return [3 /*break*/, 7];
482
509
  case 6:
483
510
  metadata = cachedMetadata === null || cachedMetadata === undefined ? undefined : cachedMetadata.get(mfePath);
@@ -527,23 +554,23 @@ var CoralogixErrorInstrumentation = /** @class */ (function (_super) {
527
554
  return (_a = obj === null || obj === undefined ? undefined : obj.message) !== null && _a !== undefined ? _a : JSON.stringify(obj, getCircularReplacer());
528
555
  };
529
556
  if (getSdkConfig().supportMfe) {
530
- window[CACHED_METADATA_KEY] = new Map();
557
+ CxGlobal[CACHED_METADATA_KEY] = new Map();
531
558
  }
532
559
  return _this;
533
560
  }
534
561
  CoralogixErrorInstrumentation.prototype.init = function () { };
535
562
  CoralogixErrorInstrumentation.prototype.enable = function () {
536
563
  shimmer_1.wrap(console, 'error', _consoleErrorHandler(this));
537
- window.addEventListener('error', _errorListener(this));
538
- window.addEventListener('unhandledrejection', _unhandledRejectionListener(this));
564
+ CxGlobal.addEventListener('error', _errorListener(this));
565
+ CxGlobal.addEventListener('unhandledrejection', _unhandledRejectionListener(this));
539
566
  document.documentElement.addEventListener('error', _documentErrorListener(this), {
540
567
  capture: true,
541
568
  });
542
569
  };
543
570
  CoralogixErrorInstrumentation.prototype.disable = function () {
544
571
  shimmer_1.unwrap(console, 'error');
545
- window.removeEventListener('error', _errorListener(this));
546
- window.removeEventListener('unhandledrejection', _unhandledRejectionListener(this));
572
+ CxGlobal.removeEventListener('error', _errorListener(this));
573
+ CxGlobal.removeEventListener('unhandledrejection', _unhandledRejectionListener(this));
547
574
  document.documentElement.removeEventListener('error', _documentErrorListener(this), { capture: true });
548
575
  };
549
576
  CoralogixErrorInstrumentation.prototype.report = function (source, arg) {
@@ -1298,7 +1325,7 @@ var IMG_EXTENSIONS = [
1298
1325
  * because it's not maintained anymore, and we want to have control over the codebase.
1299
1326
  * Also, we don't want to have a dependency on a package that is not maintained.
1300
1327
  */
1301
- var h = 'undefined' != typeof window ? window : {},
1328
+ var h = 'undefined' != typeof globalThis ? globalThis : {},
1302
1329
  k =
1303
1330
  'function' == typeof Object.defineProperties
1304
1331
  ? Object.defineProperty
@@ -1450,8 +1477,8 @@ function C(a) {
1450
1477
  a = a ? a : {};
1451
1478
  this.w = !!a.useMutationObserver;
1452
1479
  this.u = a.minValue || null;
1453
- a = window.__tti && window.__tti.e;
1454
- var b = window.__tti && window.__tti.o;
1480
+ a = globalThis.__tti && globalThis.__tti.e;
1481
+ var b = globalThis.__tti && globalThis.__tti.o;
1455
1482
  this.a = a
1456
1483
  ? a.map(function (a) {
1457
1484
  return { start: a.startTime, end: a.startTime + a.duration };
@@ -1475,7 +1502,7 @@ C.prototype.getFirstConsistentlyInteractive = function () {
1475
1502
  a.s = b;
1476
1503
  'complete' == document.readyState
1477
1504
  ? F(a)
1478
- : window.addEventListener('load', function () {
1505
+ : globalThis.addEventListener('load', function () {
1479
1506
  F(a);
1480
1507
  });
1481
1508
  });
@@ -1494,7 +1521,7 @@ function G(a, b) {
1494
1521
  var b = performance.timing.navigationStart,
1495
1522
  d = B(a.g, a.b),
1496
1523
  b =
1497
- (window.a && window.a.A ? 1e3 * window.a.A().C - b : 0) ||
1524
+ (globalThis.a && globalThis.a.A ? 1e3 * globalThis.a.A().C - b : 0) ||
1498
1525
  performance.timing.domContentLoadedEventEnd - b;
1499
1526
  if (a.u) var f = a.u;
1500
1527
  else
@@ -1558,7 +1585,7 @@ h.Object.defineProperties(C.prototype, {
1558
1585
  var H = {
1559
1586
  getFirstConsistentlyInteractive: function (a) {
1560
1587
  a = a ? a : {};
1561
- return 'PerformanceLongTaskTiming' in window
1588
+ return 'PerformanceLongTaskTiming' in globalThis
1562
1589
  ? new C(a).getFirstConsistentlyInteractive()
1563
1590
  : Promise.resolve(null);
1564
1591
  },
@@ -1742,7 +1769,7 @@ var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1742
1769
  id: generateWebVitalUniqueID(),
1743
1770
  });
1744
1771
  totalBLockingTimeObserver.disconnect();
1745
- (_b = (_a = window.__tti) === null || _a === undefined ? undefined : _a.o) === null || _b === undefined ? undefined : _b.disconnect();
1772
+ (_b = (_a = CxGlobal.__tti) === null || _a === undefined ? undefined : _a.o) === null || _b === undefined ? undefined : _b.disconnect();
1746
1773
  }
1747
1774
  });
1748
1775
  };
@@ -1941,47 +1968,11 @@ var CoralogixResourcesInstrumentation = /** @class */ (function (_super) {
1941
1968
  return CoralogixResourcesInstrumentation;
1942
1969
  }(InstrumentationBase));
1943
1970
 
1944
- /**
1945
- * access the global this consistently, making it suitable for various JavaScript contexts.
1946
- * inspired by https://mathiasbynens.be/notes/globalthis
1947
- */
1948
- function getGlobalObject() {
1949
- if (typeof globalThis === 'object') {
1950
- return globalThis;
1951
- }
1952
- Object.defineProperty(Object.prototype, '_dd_temp_', {
1953
- get: function () {
1954
- return this;
1955
- },
1956
- configurable: true,
1957
- });
1958
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1959
- // @ts-ignore _dd_temp is defined using defineProperty
1960
- var globalObject = _dd_temp_;
1961
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1962
- // @ts-ignore _dd_temp is defined using defineProperty
1963
- delete Object.prototype._dd_temp_;
1964
- if (typeof globalObject !== 'object') {
1965
- // on safari _dd_temp_ is available on window but not globally
1966
- // fallback on other browser globals check
1967
- if (typeof self === 'object') {
1968
- globalObject = self;
1969
- }
1970
- else if (typeof window === 'object') {
1971
- globalObject = window;
1972
- }
1973
- else {
1974
- globalObject = {};
1975
- }
1976
- }
1977
- return globalObject;
1978
- }
1979
-
1980
1971
  /**
1981
1972
  * Gets the original value for a DOM API that was potentially patched by Zone.js.
1982
1973
  */
1983
1974
  function getZoneJsOriginalDom(target, name) {
1984
- var browserWindow = getGlobalObject();
1975
+ var browserWindow = getCxGlobal();
1985
1976
  var original;
1986
1977
  if (browserWindow.Zone &&
1987
1978
  typeof browserWindow.Zone.__symbol__ === 'function') {
@@ -2170,7 +2161,7 @@ var MEMORY_USAGE_INSTRUMENTATION_VERSION = '1.0.0';
2170
2161
  var MEMORY_USAGE_DEFAULT_INTERVAL = 300000; // 5 minutes;
2171
2162
 
2172
2163
  function isMeasureUserAgentSpecificMemoryAllowed() {
2173
- if (!window.crossOriginIsolated) {
2164
+ if (!CxGlobal.crossOriginIsolated) {
2174
2165
  console.debug('Coralogix Browser SDK - measureUserAgentSpecificMemory() is only available in cross-origin-isolated pages.');
2175
2166
  return false;
2176
2167
  }
@@ -2630,20 +2621,20 @@ var PARAMS_SEPARATOR = '?';
2630
2621
  var PROTOCOL_SEPARATOR = '://';
2631
2622
 
2632
2623
  function saveInternalRumData(key, value) {
2633
- if (!window[RUM_INTERNAL_DATA_KEY]) {
2634
- window[RUM_INTERNAL_DATA_KEY] = {};
2624
+ if (!CxGlobal[RUM_INTERNAL_DATA_KEY]) {
2625
+ CxGlobal[RUM_INTERNAL_DATA_KEY] = {};
2635
2626
  }
2636
- window[RUM_INTERNAL_DATA_KEY][key] = value;
2627
+ CxGlobal[RUM_INTERNAL_DATA_KEY][key] = value;
2637
2628
  }
2638
2629
  function getInternalRumData(key) {
2639
2630
  var _a;
2640
- return (_a = window[RUM_INTERNAL_DATA_KEY]) === null || _a === undefined ? undefined : _a[key];
2631
+ return (_a = CxGlobal[RUM_INTERNAL_DATA_KEY]) === null || _a === undefined ? undefined : _a[key];
2641
2632
  }
2642
2633
 
2643
2634
  var _a$1;
2644
- var supportedPerformanceTypes = !((_a$1 = window === null || window === undefined ? undefined : window.PerformanceObserver) === null || _a$1 === undefined ? undefined : _a$1.supportedEntryTypes)
2635
+ var supportedPerformanceTypes = !((_a$1 = CxGlobal === null || CxGlobal === undefined ? undefined : CxGlobal.PerformanceObserver) === null || _a$1 === undefined ? undefined : _a$1.supportedEntryTypes)
2645
2636
  ? new Set()
2646
- : new Set(window.PerformanceObserver.supportedEntryTypes);
2637
+ : new Set(CxGlobal.PerformanceObserver.supportedEntryTypes);
2647
2638
  function valueEndWithOrInclude(value, extensions) {
2648
2639
  return extensions.some(function (ex) { return value.endsWith(ex) || value.includes(ex); });
2649
2640
  }
@@ -3677,7 +3668,7 @@ var CoralogixExporter = /** @class */ (function () {
3677
3668
  return cxSpans;
3678
3669
  }, []);
3679
3670
  this.invokeLogRequest(instrumentationLogs);
3680
- var cachedLogs = (window.cachedLogs = __spreadArray(__spreadArray([], __read$1((window.cachedLogs || [])), false), __read$1(currentSpans), false));
3671
+ var cachedLogs = (CxGlobal.cachedLogs = __spreadArray(__spreadArray([], __read$1((CxGlobal.cachedLogs || [])), false), __read$1(currentSpans), false));
3681
3672
  var logsCounter = cachedLogs.length;
3682
3673
  //check if we reached the limit of max rum events for session with error
3683
3674
  if (logsCounter > maxRumEventsForSessionWithError && !sessionHasError) {
@@ -3703,7 +3694,7 @@ var CoralogixExporter = /** @class */ (function () {
3703
3694
  }
3704
3695
  };
3705
3696
  CoralogixExporter.prototype.clearCachedDataForSessionWithError = function () {
3706
- window.cachedLogs = [];
3697
+ CxGlobal.cachedLogs = [];
3707
3698
  this.batchTimeDelay = BATCH_TIME_DELAY;
3708
3699
  };
3709
3700
  CoralogixExporter.prototype.shutdown = function () {
@@ -5035,7 +5026,7 @@ var WorkerManager = /** @class */ (function () {
5035
5026
  if (workerUrl.startsWith('http://') || workerUrl.startsWith('https://')) {
5036
5027
  return workerUrl;
5037
5028
  }
5038
- return "".concat(window.location.origin).concat(workerUrl);
5029
+ return "".concat(CxGlobal.location.origin).concat(workerUrl);
5039
5030
  };
5040
5031
  return WorkerManager;
5041
5032
  }());
@@ -5119,7 +5110,7 @@ var SessionRecorder = /** @class */ (function () {
5119
5110
  _this.batchTimeDelay = BATCH_TIME_DELAY;
5120
5111
  }
5121
5112
  };
5122
- window[SESSION_RECORDER_KEY] = this;
5113
+ CxGlobal[SESSION_RECORDER_KEY] = this;
5123
5114
  this.sessionManager = sessionManager;
5124
5115
  var onlySessionWithErrorMode = sessionManager.onlySessionWithErrorMode, maxRecordTimeForSessionWithError = sessionManager.maxRecordTimeForSessionWithError;
5125
5116
  var maxMutations = recordConfig.maxMutations, autoStartSessionRecording = recordConfig.autoStartSessionRecording, workerUrl = recordConfig.workerUrl;
@@ -5128,7 +5119,7 @@ var SessionRecorder = /** @class */ (function () {
5128
5119
  this.isAutoStartRecording = autoStartSessionRecording;
5129
5120
  this.maxMutations = maxMutations !== null && maxMutations !== undefined ? maxMutations : MAX_MUTATIONS_FOR_SESSION_RECORDING;
5130
5121
  this.recordConfig = this.prepareRecordConfig(recordConfig);
5131
- if (window.Worker) {
5122
+ if (CxGlobal.Worker) {
5132
5123
  this.workerManager = new WorkerManager();
5133
5124
  this.initializeSessionWorker(workerUrl);
5134
5125
  }
@@ -5435,8 +5426,10 @@ var SessionIdle = /** @class */ (function () {
5435
5426
  SessionIdle.prototype.trackActivity = function () {
5436
5427
  var _a, _b;
5437
5428
  (_b = (_a = this.stopCallbacks).removeActivityListeners) === null || _b === undefined ? undefined : _b.call(_a);
5438
- var stop = addEventListeners(window, ["touchstart" /* DOM_EVENT.TOUCH_START */, "keydown" /* DOM_EVENT.KEY_DOWN */, "mousemove" /* DOM_EVENT.MOUSE_MOVE */], this.idlenessEventsHandler, { capture: true, passive: true }).stop;
5439
- this.stopCallbacks.removeActivityListeners = stop;
5429
+ if (typeof CxGlobal.addEventListener === 'function') {
5430
+ var stop_1 = addEventListeners(CxGlobal, ["touchstart" /* DOM_EVENT.TOUCH_START */, "keydown" /* DOM_EVENT.KEY_DOWN */, "mousemove" /* DOM_EVENT.MOUSE_MOVE */], this.idlenessEventsHandler, { capture: true, passive: true }).stop;
5431
+ this.stopCallbacks.removeActivityListeners = stop_1;
5432
+ }
5440
5433
  };
5441
5434
  return SessionIdle;
5442
5435
  }());
@@ -5454,10 +5447,12 @@ var SessionManager = /** @class */ (function (_super) {
5454
5447
  _this._cachedLogsSent = false;
5455
5448
  _this._currentPageTimestamp = getNowTime();
5456
5449
  _this.getPrevSession = function () {
5457
- return JSON.parse(window.sessionStorage.getItem(PREV_SESSION_KEY));
5450
+ var _a;
5451
+ return JSON.parse((_a = CxGlobal.sessionStorage) === null || _a === undefined ? undefined : _a.getItem(PREV_SESSION_KEY));
5458
5452
  };
5459
5453
  _this.getSession = function () {
5460
- var storedSession = JSON.parse(window.sessionStorage.getItem(SESSION_KEY));
5454
+ var _a;
5455
+ var storedSession = JSON.parse((_a = CxGlobal.sessionStorage) === null || _a === undefined ? undefined : _a.getItem(SESSION_KEY));
5461
5456
  var now = getNowTime();
5462
5457
  var session;
5463
5458
  if (storedSession) {
@@ -5472,7 +5467,7 @@ var SessionManager = /** @class */ (function (_super) {
5472
5467
  return session;
5473
5468
  };
5474
5469
  _this.setSession = function (afterIdle) {
5475
- var _a, _b, _c;
5470
+ var _a, _b, _c, _d;
5476
5471
  if (afterIdle === undefined) { afterIdle = false; }
5477
5472
  var shouldkeepSessionAfterReload = (_a = _this._sessionConfig) === null || _a === undefined ? undefined : _a.keepSessionAfterReload;
5478
5473
  if (shouldkeepSessionAfterReload) {
@@ -5481,14 +5476,14 @@ var SessionManager = /** @class */ (function (_super) {
5481
5476
  else {
5482
5477
  _this.createNewSession();
5483
5478
  }
5484
- window.sessionStorage.setItem(SESSION_KEY, JSON.stringify(_this.activeSession));
5479
+ (_b = CxGlobal.sessionStorage) === null || _b === undefined ? undefined : _b.setItem(SESSION_KEY, JSON.stringify(_this.activeSession));
5485
5480
  var sessionRecorder = getSessionRecorder();
5486
5481
  var shouldStartRecordingAfterIdle = afterIdle &&
5487
5482
  !!(sessionRecorder === null || sessionRecorder === undefined ? undefined : sessionRecorder.recordingStopDueToTimeout) &&
5488
- !!((_b = _this.sessionRecorderConfig) === null || _b === undefined ? undefined : _b.enable);
5483
+ !!((_c = _this.sessionRecorderConfig) === null || _c === undefined ? undefined : _c.enable);
5489
5484
  if (shouldStartRecordingAfterIdle ||
5490
5485
  (sessionRecorder === null || sessionRecorder === undefined ? undefined : sessionRecorder.getIsAutoStartRecording())) {
5491
- (_c = _this.sessionRecorder) === null || _c === undefined ? undefined : _c.startRecording();
5486
+ (_d = _this.sessionRecorder) === null || _d === undefined ? undefined : _d.startRecording();
5492
5487
  }
5493
5488
  return _this.activeSession;
5494
5489
  };
@@ -5588,7 +5583,7 @@ var SessionManager = /** @class */ (function (_super) {
5588
5583
  this.stopIdleListener();
5589
5584
  };
5590
5585
  SessionManager.prototype.initializeSession = function (recordConfig) {
5591
- window[SESSION_MANAGER_KEY] = this;
5586
+ CxGlobal[SESSION_MANAGER_KEY] = this;
5592
5587
  this.sessionRecorderConfig = recordConfig;
5593
5588
  if (recordConfig === null || recordConfig === undefined ? undefined : recordConfig.enable) {
5594
5589
  var recordingSamplingEnabled = isSamplingOn(recordConfig.sessionRecordingSampleRate);
@@ -5610,28 +5605,29 @@ var SessionManager = /** @class */ (function (_super) {
5610
5605
  this.clearSession();
5611
5606
  };
5612
5607
  SessionManager.prototype.clearPrevSession = function () {
5613
- window.sessionStorage.removeItem(PREV_SESSION_KEY);
5608
+ var _a;
5609
+ (_a = CxGlobal.sessionStorage) === null || _a === undefined ? undefined : _a.removeItem(PREV_SESSION_KEY);
5614
5610
  };
5615
5611
  SessionManager.prototype.clearSession = function () {
5616
- var _a, _b, _c, _d;
5617
- window.sessionStorage.setItem(PREV_SESSION_KEY, JSON.stringify(__assign(__assign({}, this.activeSession), { hasRecording: (_a = this.sessionRecorder) === null || _a === undefined ? undefined : _a.getSessionHasRecording(), hasScreenshot: (_b = this.sessionRecorder) === null || _b === undefined ? undefined : _b.getSessionHasScreenshot() })));
5612
+ var _a, _b, _c, _d, _e, _f;
5613
+ (_a = CxGlobal.sessionStorage) === null || _a === undefined ? undefined : _a.setItem(PREV_SESSION_KEY, JSON.stringify(__assign(__assign({}, this.activeSession), { hasRecording: (_b = this.sessionRecorder) === null || _b === undefined ? undefined : _b.getSessionHasRecording(), hasScreenshot: (_c = this.sessionRecorder) === null || _c === undefined ? undefined : _c.getSessionHasScreenshot() })));
5618
5614
  clearGlobalSpan();
5619
5615
  this.clearSessionWithErrorMode();
5620
- (_c = getSnapshotManager()) === null || _c === undefined ? undefined : _c.resetSnapshot();
5616
+ (_d = getSnapshotManager()) === null || _d === undefined ? undefined : _d.resetSnapshot();
5621
5617
  this._currentPageFragment = undefined;
5622
- (_d = this.sessionRecorder) === null || _d === undefined ? undefined : _d.stopRecording();
5623
- window.sessionStorage.removeItem(SESSION_KEY);
5618
+ (_e = this.sessionRecorder) === null || _e === undefined ? undefined : _e.stopRecording();
5619
+ (_f = CxGlobal.sessionStorage) === null || _f === undefined ? undefined : _f.removeItem(SESSION_KEY);
5624
5620
  };
5625
5621
  SessionManager.prototype.clearSessionWithErrorMode = function () {
5626
5622
  this.sessionHasError = false;
5627
5623
  this.cachedLogsSent = false;
5628
5624
  };
5629
5625
  SessionManager.prototype.handleRefreshedSessions = function () {
5630
- var _a;
5626
+ var _a, _b;
5631
5627
  this.activeSession = this.getSession();
5632
- var recordingSegmentMapFromStorage = JSON.parse(window.sessionStorage.getItem(SESSION_RECORDER_SEGMENTS_MAP) || '{}');
5628
+ var recordingSegmentMapFromStorage = JSON.parse(((_a = CxGlobal.sessionStorage) === null || _a === undefined ? undefined : _a.getItem(SESSION_RECORDER_SEGMENTS_MAP)) || '{}');
5633
5629
  if (this.activeSession) {
5634
- (_a = getSessionRecorder()) === null || _a === undefined ? undefined : _a.updateSegmentIndexCounter(recordingSegmentMapFromStorage);
5630
+ (_b = getSessionRecorder()) === null || _b === undefined ? undefined : _b.updateSegmentIndexCounter(recordingSegmentMapFromStorage);
5635
5631
  }
5636
5632
  else {
5637
5633
  this.createNewSession();
@@ -5786,7 +5782,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
5786
5782
  return resolvedUrlBlueprinters;
5787
5783
  }
5788
5784
 
5789
- var SDK_VERSION = '2.0.0';
5785
+ var SDK_VERSION = '2.1.0';
5790
5786
 
5791
5787
  function shouldDropEvent(cxRumEvent, options) {
5792
5788
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -6211,7 +6207,7 @@ var SnapshotManager = /** @class */ (function () {
6211
6207
  _this._fragmentsState = new Set();
6212
6208
  _this._isSnapshotSentDueToRecording = false;
6213
6209
  };
6214
- window[SNAPSHOT_MANAGER_KEY] = this;
6210
+ CxGlobal[SNAPSHOT_MANAGER_KEY] = this;
6215
6211
  this.resetSnapshot();
6216
6212
  }
6217
6213
  Object.defineProperty(SnapshotManager.prototype, "fragmentsState", {
@@ -6274,7 +6270,7 @@ function getTiming(duration) {
6274
6270
  }
6275
6271
 
6276
6272
  if (supportedPerformanceTypes.has(PerformanceTypes.LongTask)) {
6277
- var ttiHandler_1 = (window.__tti = {
6273
+ var ttiHandler_1 = (CxGlobal.__tti = {
6278
6274
  e: [],
6279
6275
  });
6280
6276
  ttiHandler_1.o = new PerformanceObserver(function (list) {
@@ -6310,8 +6306,8 @@ var CoralogixRum = {
6310
6306
  console.warn('CoralogixRum already inited.');
6311
6307
  return;
6312
6308
  }
6313
- // Abort if running in a non-browser environment.
6314
- if (typeof window !== 'object') {
6309
+ // Abort if not in browser environment.
6310
+ if (!CxGlobal.sessionStorage) {
6315
6311
  console.warn('CoralogixRum: Non-browser environment detected, aborting');
6316
6312
  return;
6317
6313
  }
@@ -6324,7 +6320,7 @@ var CoralogixRum = {
6324
6320
  if (!resolvedOptions) {
6325
6321
  return;
6326
6322
  }
6327
- window[SDK_CONFIG_KEY] = resolvedOptions;
6323
+ CxGlobal[SDK_CONFIG_KEY] = resolvedOptions;
6328
6324
  var sampler = getResolvedSampler(resolvedOptions);
6329
6325
  // Check if not in debug mode & no auth token.
6330
6326
  if (!resolvedOptions.debug && !resolvedOptions.public_key) {
@@ -6639,7 +6635,7 @@ var CoralogixRum = {
6639
6635
  }
6640
6636
  },
6641
6637
  };
6642
- window.CoralogixRum = CoralogixRum;
6638
+ CxGlobal.CoralogixRum = CoralogixRum;
6643
6639
 
6644
6640
  var UrlBasedLabelProvider = /** @class */ (function () {
6645
6641
  function UrlBasedLabelProvider(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -1,7 +1,11 @@
1
- import { CoralogixOtelWebType, CoralogixWindow } from './types';
1
+ import { CoralogixOtelWebType, CoralogixWindow, CxSpan } from './types';
2
2
  import { MemoryUsageContext } from './instrumentations/memory-usage';
3
3
  declare global {
4
+ interface Object {
5
+ __cx_global__: unknown;
6
+ }
4
7
  interface Window extends CoralogixWindow {
8
+ cachedLogs: CxSpan[];
5
9
  }
6
10
  interface Performance {
7
11
  measureUserAgentSpecificMemory(): Promise<MemoryUsageContext>;
package/src/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { CoralogixRum } from './coralogix-rum';
2
2
  export { CoralogixLogSeverity } from './types-external';
3
3
  export { UrlBasedLabelProvider } from './label-providers/url-based-label-provider';
4
4
  export * from './types';
5
- export { SessionRecordingEventType, RecordEvent, RecordPluginEvent, } from './session/session.model';
5
+ export { SessionRecordingEventType, type RecordEvent, type RecordPluginEvent, } from './session/session.model';
@@ -6,11 +6,6 @@ import { ExportResult } from '@opentelemetry/core';
6
6
  interface CxReadableSpan extends ReadableSpan {
7
7
  [CX_MAPPED_SPAN]?: CxSpan;
8
8
  }
9
- declare global {
10
- interface Window {
11
- cachedLogs: CxSpan[];
12
- }
13
- }
14
9
  export declare class CoralogixExporter implements SpanExporter, ProcessorBaseModel {
15
10
  isActive: boolean;
16
11
  private sdkConfig;
@@ -1,5 +1,2 @@
1
- /**
2
- * access the global this consistently, making it suitable for various JavaScript contexts.
3
- * inspired by https://mathiasbynens.be/notes/globalthis
4
- */
5
- export declare function getGlobalObject<T = typeof globalThis>(): T;
1
+ export declare function getCxGlobal<T = typeof globalThis>(): T;
2
+ export declare const CxGlobal: typeof globalThis;
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.0";
1
+ export declare const SDK_VERSION = "2.1.0";