@coralogix/browser 2.1.0 → 2.2.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.2.0 (2025-03-18)
2
+
3
+ ### 🚀 Features
4
+
5
+ - Update Coralogix configuration and improve performance observer handling
6
+
1
7
  ## 2.1.0 (2025-02-18)
2
8
 
3
9
  ### 🚀 Features
package/index.esm.js CHANGED
@@ -1325,7 +1325,8 @@ var IMG_EXTENSIONS = [
1325
1325
  * because it's not maintained anymore, and we want to have control over the codebase.
1326
1326
  * Also, we don't want to have a dependency on a package that is not maintained.
1327
1327
  */
1328
- var h = 'undefined' != typeof globalThis ? globalThis : {},
1328
+
1329
+ var h = 'undefined' != typeof CxGlobal ? CxGlobal : {},
1329
1330
  k =
1330
1331
  'function' == typeof Object.defineProperties
1331
1332
  ? Object.defineProperty
@@ -1477,8 +1478,8 @@ function C(a) {
1477
1478
  a = a ? a : {};
1478
1479
  this.w = !!a.useMutationObserver;
1479
1480
  this.u = a.minValue || null;
1480
- a = globalThis.__tti && globalThis.__tti.e;
1481
- var b = globalThis.__tti && globalThis.__tti.o;
1481
+ a = CxGlobal.__tti && CxGlobal.__tti.e;
1482
+ var b = CxGlobal.__tti && CxGlobal.__tti.o;
1482
1483
  this.a = a
1483
1484
  ? a.map(function (a) {
1484
1485
  return { start: a.startTime, end: a.startTime + a.duration };
@@ -1502,7 +1503,7 @@ C.prototype.getFirstConsistentlyInteractive = function () {
1502
1503
  a.s = b;
1503
1504
  'complete' == document.readyState
1504
1505
  ? F(a)
1505
- : globalThis.addEventListener('load', function () {
1506
+ : CxGlobal.addEventListener('load', function () {
1506
1507
  F(a);
1507
1508
  });
1508
1509
  });
@@ -1521,7 +1522,7 @@ function G(a, b) {
1521
1522
  var b = performance.timing.navigationStart,
1522
1523
  d = B(a.g, a.b),
1523
1524
  b =
1524
- (globalThis.a && globalThis.a.A ? 1e3 * globalThis.a.A().C - b : 0) ||
1525
+ (CxGlobal.a && CxGlobal.a.A ? 1e3 * CxGlobal.a.A().C - b : 0) ||
1525
1526
  performance.timing.domContentLoadedEventEnd - b;
1526
1527
  if (a.u) var f = a.u;
1527
1528
  else
@@ -1583,14 +1584,34 @@ h.Object.defineProperties(C.prototype, {
1583
1584
  },
1584
1585
  });
1585
1586
  var H = {
1586
- getFirstConsistentlyInteractive: function (a) {
1587
+ getFirstConsistentlyInteractive: function (a = undefined) {
1587
1588
  a = a ? a : {};
1588
- return 'PerformanceLongTaskTiming' in globalThis
1589
+ return 'PerformanceLongTaskTiming' in CxGlobal
1589
1590
  ? new C(a).getFirstConsistentlyInteractive()
1590
1591
  : Promise.resolve(null);
1591
1592
  },
1592
1593
  };
1593
1594
 
1595
+ function observeIfSupported(observer, entryType) {
1596
+ if (!isPerformanceObserverSupported()) {
1597
+ return;
1598
+ }
1599
+ try {
1600
+ observer.observe({ type: entryType, buffered: true });
1601
+ }
1602
+ catch (error) {
1603
+ observer.observe({ entryTypes: [entryType] });
1604
+ }
1605
+ }
1606
+ function isPerformanceObserverSupported() {
1607
+ var _a;
1608
+ if (!((_a = CxGlobal === null || CxGlobal === undefined ? undefined : CxGlobal.PerformanceObserver) === null || _a === undefined ? undefined : _a.supportedEntryTypes)) {
1609
+ console.warn('Coralogix Browser SDK - browser does not support the required APIs ');
1610
+ return false;
1611
+ }
1612
+ return true;
1613
+ }
1614
+
1594
1615
  var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1595
1616
  __extends(CoralogixWebVitalsInstrumentation, _super);
1596
1617
  function CoralogixWebVitalsInstrumentation(config) {
@@ -1623,6 +1644,9 @@ var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1623
1644
  _this.metrics = isEmpty(config.metrics)
1624
1645
  ? ALL_WEB_VITALS_METRICS
1625
1646
  : config.metrics;
1647
+ if (!isPerformanceObserverSupported()) {
1648
+ return _this;
1649
+ }
1626
1650
  _this.registerToCoreWebVitalMetrics();
1627
1651
  _this.registerToCalculatedWebVitalMetrics();
1628
1652
  if (_this.isSoftNavsEnabled) {
@@ -1678,10 +1702,7 @@ var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1678
1702
  });
1679
1703
  });
1680
1704
  this.observers.push(softNavObserver);
1681
- softNavObserver.observe({
1682
- type: PerformanceTypes.SoftNavigation,
1683
- buffered: true,
1684
- });
1705
+ observeIfSupported(softNavObserver, PerformanceTypes.SoftNavigation);
1685
1706
  }
1686
1707
  else {
1687
1708
  console.warn('Coralogix Browser SDK - browser doesnt support soft navigation events');
@@ -1736,10 +1757,7 @@ var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1736
1757
  });
1737
1758
  });
1738
1759
  this.observers.push(loadingPageObserver);
1739
- loadingPageObserver.observe({
1740
- type: PerformanceTypes.Navigation,
1741
- buffered: true,
1742
- });
1760
+ observeIfSupported(loadingPageObserver, PerformanceTypes.Navigation);
1743
1761
  };
1744
1762
  CoralogixWebVitalsInstrumentation.prototype.calculateAllTotalBlockingTime = function () {
1745
1763
  var _this = this;
@@ -1755,10 +1773,7 @@ var CoralogixWebVitalsInstrumentation = /** @class */ (function (_super) {
1755
1773
  };
1756
1774
  });
1757
1775
  this.observers.push(totalBLockingTimeObserver);
1758
- totalBLockingTimeObserver.observe({
1759
- type: PerformanceTypes.LongTask,
1760
- buffered: true,
1761
- });
1776
+ observeIfSupported(totalBLockingTimeObserver, PerformanceTypes.LongTask);
1762
1777
  H.getFirstConsistentlyInteractive().then(function (tti) {
1763
1778
  var _a, _b;
1764
1779
  if (tti) {
@@ -1802,10 +1817,7 @@ var CoralogixLongTaskInstrumentation = /** @class */ (function (_super) {
1802
1817
  return _this.createSpanFromLongTask(entry);
1803
1818
  });
1804
1819
  });
1805
- this.longTaskObserver.observe({
1806
- type: PerformanceTypes.LongTask,
1807
- buffered: true,
1808
- });
1820
+ observeIfSupported(this.longTaskObserver, PerformanceTypes.LongTask);
1809
1821
  };
1810
1822
  CoralogixLongTaskInstrumentation.prototype.createSpanFromLongTask = function (entry) {
1811
1823
  var longTaskSpan = this.tracer.startSpan(CoralogixEventType.LONG_TASK);
@@ -1891,10 +1903,7 @@ var CoralogixResourcesInstrumentation = /** @class */ (function (_super) {
1891
1903
  }
1892
1904
  });
1893
1905
  });
1894
- this.resourcesObserver.observe({
1895
- type: PerformanceTypes.Resource,
1896
- buffered: true,
1897
- });
1906
+ observeIfSupported(this.resourcesObserver, PerformanceTypes.Resource);
1898
1907
  };
1899
1908
  CoralogixResourcesInstrumentation.prototype.isProcessableResourceEntry = function (entry) {
1900
1909
  var isAcceptedResourceType = ![
@@ -5782,7 +5791,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
5782
5791
  return resolvedUrlBlueprinters;
5783
5792
  }
5784
5793
 
5785
- var SDK_VERSION = '2.1.0';
5794
+ var SDK_VERSION = '2.2.0';
5786
5795
 
5787
5796
  function shouldDropEvent(cxRumEvent, options) {
5788
5797
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -6276,10 +6285,7 @@ if (supportedPerformanceTypes.has(PerformanceTypes.LongTask)) {
6276
6285
  ttiHandler_1.o = new PerformanceObserver(function (list) {
6277
6286
  ttiHandler_1.e = ttiHandler_1.e.concat(list.getEntries());
6278
6287
  });
6279
- ttiHandler_1.o.observe({
6280
- type: PerformanceTypes.LongTask,
6281
- buffered: true,
6282
- });
6288
+ observeIfSupported(ttiHandler_1.o, PerformanceTypes.LongTask);
6283
6289
  }
6284
6290
  var isInited = false;
6285
6291
  var _deregisterInstrumentations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -0,0 +1,3 @@
1
+ import { PerformanceTypes } from '../../types';
2
+ export declare function observeIfSupported(observer: PerformanceObserver, entryType: PerformanceTypes): void;
3
+ export declare function isPerformanceObserverSupported(): boolean;
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.1.0";
1
+ export declare const SDK_VERSION = "2.2.0";