clarity-js 0.8.19 → 0.8.21

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/build/clarity.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  var dom = /*#__PURE__*/Object.freeze({
4
4
  __proto__: null,
5
- get add () { return add; },
5
+ get add () { return add$1; },
6
6
  get get () { return get; },
7
- get getId () { return getId; },
7
+ get getId () { return getId$1; },
8
8
  get getNode () { return getNode; },
9
9
  get getValue () { return getValue; },
10
10
  get has () { return has$1; },
@@ -166,24 +166,30 @@ function api(method) {
166
166
  }
167
167
 
168
168
  var startTime = 0;
169
+ function computeStartTime() {
170
+ return performance.now() + performance.timeOrigin;
171
+ }
169
172
  function start$I() {
170
- startTime = performance.now() + performance.timeOrigin;
173
+ startTime = computeStartTime();
171
174
  }
172
- // event.timestamp is number of milliseconds elapsed since the document was loaded
175
+ // event.timestamp is number of milliseconds elapsed since the document was loaded
173
176
  // since iframes can be loaded later the event timestamp is not the same as performance.now()
174
177
  // converting everything to absolute time by adding timeorigin of the event view
175
178
  // to synchronize times before calculating the difference with start time
176
179
  function time(event) {
177
180
  if (event === void 0) { event = null; }
181
+ // If startTime is 0, Clarity hasn't been started or has been stopped
182
+ // Use a local baseline to maintain relative timing semantics without affecting global state
183
+ var baseline = startTime === 0 ? computeStartTime() : startTime;
178
184
  var ts = event && event.timeStamp > 0 ? event.timeStamp : performance.now();
179
185
  var origin = event && event.view ? event.view.performance.timeOrigin : performance.timeOrigin;
180
- return Math.max(Math.round(ts + origin - startTime), 0);
186
+ return Math.max(Math.round(ts + origin - baseline), 0);
181
187
  }
182
188
  function stop$F() {
183
189
  startTime = 0;
184
190
  }
185
191
 
186
- var version$1 = "0.8.19";
192
+ var version$1 = "0.8.21";
187
193
 
188
194
  // tslint:disable: no-bitwise
189
195
  function hash (input, precision) {
@@ -655,7 +661,7 @@ function reset$r() {
655
661
  function setTimeout$1(handler, timeout, event) {
656
662
  return window.setTimeout(measure(handler), timeout, event);
657
663
  }
658
- function clearTimeout(handle) {
664
+ function clearTimeout$1(handle) {
659
665
  return window.clearTimeout(handle);
660
666
  }
661
667
 
@@ -669,7 +675,7 @@ function start$F() {
669
675
  }
670
676
  function reset$q() {
671
677
  if (timeout$7) {
672
- clearTimeout(timeout$7);
678
+ clearTimeout$1(timeout$7);
673
679
  }
674
680
  timeout$7 = setTimeout$1(ping, interval);
675
681
  last = time();
@@ -686,7 +692,7 @@ function ping() {
686
692
  }
687
693
  }
688
694
  function stop$C() {
689
- clearTimeout(timeout$7);
695
+ clearTimeout$1(timeout$7);
690
696
  last = 0;
691
697
  interval = 0;
692
698
  }
@@ -1253,7 +1259,7 @@ function recompute$8(evt) {
1253
1259
  var value = element.value;
1254
1260
  var checksum = value && value.length >= 5 /* Setting.WordLength */ && config$2.fraud && "password,secret,pass,social,ssn,code,hidden" /* Mask.Exclude */.indexOf(element.type) === -1 ? hash(value, 28 /* Setting.ChecksumPrecision */) : "" /* Constant.Empty */;
1255
1261
  state$a.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1256
- schedule(encode$3.bind(this, 42 /* Event.Change */));
1262
+ schedule(encode$4.bind(this, 42 /* Event.Change */));
1257
1263
  }
1258
1264
  }
1259
1265
  function reset$m() {
@@ -1286,11 +1292,12 @@ function start$y() {
1286
1292
  }
1287
1293
  function observe$b(root) {
1288
1294
  bind(root, "click", handler$3.bind(this, 9 /* Event.Click */, root), true);
1295
+ bind(root, "contextmenu", handler$3.bind(this, 48 /* Event.ContextMenu */, root), true);
1289
1296
  }
1290
1297
  function handler$3(event, root, evt) {
1291
1298
  handler$3.dn = 6 /* FunctionNames.ClickHandler */;
1292
1299
  var frame = iframe(root);
1293
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1300
+ var d = frame && frame.contentDocument ? frame.contentDocument.documentElement : document.documentElement;
1294
1301
  var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
1295
1302
  var y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
1296
1303
  // In case of iframe, we adjust (x,y) to be relative to top parent's origin
@@ -1336,7 +1343,7 @@ function handler$3(event, root, evt) {
1336
1343
  isFullText: textInfo.isFullText,
1337
1344
  }
1338
1345
  });
1339
- schedule(encode$3.bind(this, event));
1346
+ schedule(encode$4.bind(this, event));
1340
1347
  }
1341
1348
  }
1342
1349
  function link(node) {
@@ -1427,7 +1434,7 @@ function observe$a(root) {
1427
1434
  function recompute$7(action, evt) {
1428
1435
  recompute$7.dn = 7 /* FunctionNames.ClipboardRecompute */;
1429
1436
  state$8.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1430
- schedule(encode$3.bind(this, 38 /* Event.Clipboard */));
1437
+ schedule(encode$4.bind(this, 38 /* Event.Clipboard */));
1431
1438
  }
1432
1439
  function reset$k() {
1433
1440
  state$8 = [];
@@ -1463,18 +1470,18 @@ function recompute$6(evt) {
1463
1470
  state$7.pop();
1464
1471
  }
1465
1472
  state$7.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1466
- clearTimeout(timeout$6);
1473
+ clearTimeout$1(timeout$6);
1467
1474
  timeout$6 = setTimeout$1(process$7, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
1468
1475
  }
1469
1476
  }
1470
1477
  function process$7(event) {
1471
- schedule(encode$3.bind(this, event));
1478
+ schedule(encode$4.bind(this, event));
1472
1479
  }
1473
1480
  function reset$j() {
1474
1481
  state$7 = [];
1475
1482
  }
1476
1483
  function stop$u() {
1477
- clearTimeout(timeout$6);
1484
+ clearTimeout$1(timeout$6);
1478
1485
  reset$j();
1479
1486
  }
1480
1487
 
@@ -1500,7 +1507,7 @@ function observe$8(root) {
1500
1507
  function mouse(event, root, evt) {
1501
1508
  mouse.dn = 10 /* FunctionNames.PointerMouse */;
1502
1509
  var frame = iframe(root);
1503
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1510
+ var d = frame && frame.contentDocument ? frame.contentDocument.documentElement : document.documentElement;
1504
1511
  var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
1505
1512
  var y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
1506
1513
  // In case of iframe, we adjust (x,y) to be relative to top parent's origin
@@ -1517,7 +1524,7 @@ function mouse(event, root, evt) {
1517
1524
  function touch(event, root, evt) {
1518
1525
  touch.dn = 11 /* FunctionNames.PointerTouch */;
1519
1526
  var frame = iframe(root);
1520
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1527
+ var d = frame && frame.contentDocument ? frame.contentDocument.documentElement : document.documentElement;
1521
1528
  var touches = evt.changedTouches;
1522
1529
  var t = time(evt);
1523
1530
  if (touches) {
@@ -1569,7 +1576,7 @@ function handler$2(current) {
1569
1576
  state$6.pop();
1570
1577
  }
1571
1578
  state$6.push(current);
1572
- clearTimeout(timeout$5);
1579
+ clearTimeout$1(timeout$5);
1573
1580
  timeout$5 = setTimeout$1(process$6, 500 /* Setting.LookAhead */, current.event);
1574
1581
  break;
1575
1582
  default:
@@ -1579,7 +1586,7 @@ function handler$2(current) {
1579
1586
  }
1580
1587
  }
1581
1588
  function process$6(event) {
1582
- schedule(encode$3.bind(this, event));
1589
+ schedule(encode$4.bind(this, event));
1583
1590
  }
1584
1591
  function reset$i() {
1585
1592
  state$6 = [];
@@ -1594,7 +1601,7 @@ function similar$1(last, current) {
1594
1601
  return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.PointerInterval */ && sameId;
1595
1602
  }
1596
1603
  function stop$t() {
1597
- clearTimeout(timeout$5);
1604
+ clearTimeout$1(timeout$5);
1598
1605
  // Send out any pending pointer events in the pipeline
1599
1606
  if (state$6.length > 0) {
1600
1607
  process$6(state$6[state$6.length - 1].event);
@@ -1619,20 +1626,20 @@ function recompute$5() {
1619
1626
  height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
1620
1627
  };
1621
1628
  if (initialStateLogged) {
1622
- clearTimeout(timeout$4);
1629
+ clearTimeout$1(timeout$4);
1623
1630
  timeout$4 = setTimeout$1(process$5, 500 /* Setting.LookAhead */, 11 /* Event.Resize */);
1624
1631
  }
1625
1632
  else {
1626
- encode$3(11 /* Event.Resize */);
1633
+ encode$4(11 /* Event.Resize */);
1627
1634
  initialStateLogged = true;
1628
1635
  }
1629
1636
  }
1630
1637
  function process$5(event) {
1631
- schedule(encode$3.bind(this, event));
1638
+ schedule(encode$4.bind(this, event));
1632
1639
  }
1633
1640
  function reset$h() {
1634
1641
  data$c = null;
1635
- clearTimeout(timeout$4);
1642
+ clearTimeout$1(timeout$4);
1636
1643
  }
1637
1644
  function stop$s() {
1638
1645
  reset$h();
@@ -1643,13 +1650,13 @@ function stop$s() {
1643
1650
  * every specified duration in milliseconds, ensuring the last event is not lost.
1644
1651
  * @param func - The function to throttle.
1645
1652
  * @param duration - The duration in milliseconds to wait before allowing the next execution.
1646
- * @returns A throttled version of the provided function.
1653
+ * @returns A throttled version of the provided function with a cleanup method.
1647
1654
  */
1648
1655
  function throttle(func, duration) {
1649
1656
  var lastExecutionTime = 0;
1650
1657
  var timeoutId = null;
1651
1658
  var lastArgs = null;
1652
- return function () {
1659
+ function throttledFunction() {
1653
1660
  var _this = this;
1654
1661
  var args = [];
1655
1662
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1674,7 +1681,16 @@ function throttle(func, duration) {
1674
1681
  lastExecutionTime = now;
1675
1682
  func.apply(this, args);
1676
1683
  }
1684
+ }
1685
+ // Add cleanup method to clear pending timeouts
1686
+ throttledFunction.cleanup = function () {
1687
+ if (timeoutId) {
1688
+ clearTimeout(timeoutId);
1689
+ timeoutId = null;
1690
+ lastArgs = null;
1691
+ }
1677
1692
  };
1693
+ return throttledFunction;
1678
1694
  }
1679
1695
 
1680
1696
  var state$5 = [];
@@ -1733,7 +1749,7 @@ function recompute$4(event) {
1733
1749
  state$5.pop();
1734
1750
  }
1735
1751
  state$5.push(current);
1736
- clearTimeout(timeout$3);
1752
+ clearTimeout$1(timeout$3);
1737
1753
  timeout$3 = setTimeout$1(process$4, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
1738
1754
  }
1739
1755
  var throttledRecompute = throttle(recompute$4, 25 /* Setting.Throttle */);
@@ -1760,7 +1776,7 @@ function reset$g() {
1760
1776
  initialBottom = null;
1761
1777
  }
1762
1778
  function process$4(event) {
1763
- schedule(encode$3.bind(this, event));
1779
+ schedule(encode$4.bind(this, event));
1764
1780
  }
1765
1781
  function similar(last, current) {
1766
1782
  var dx = last.data.x - current.data.x;
@@ -1780,7 +1796,8 @@ function compute$8() {
1780
1796
  }
1781
1797
  }
1782
1798
  function stop$r() {
1783
- clearTimeout(timeout$3);
1799
+ clearTimeout$1(timeout$3);
1800
+ throttledRecompute.cleanup();
1784
1801
  state$5 = [];
1785
1802
  initialTop = null;
1786
1803
  initialBottom = null;
@@ -1814,7 +1831,7 @@ function recompute$3(root) {
1814
1831
  }
1815
1832
  var startNode = data$b.start ? data$b.start : null;
1816
1833
  if (previous !== null && data$b.start !== null && startNode !== current.anchorNode) {
1817
- clearTimeout(timeout$2);
1834
+ clearTimeout$1(timeout$2);
1818
1835
  process$3(21 /* Event.Selection */);
1819
1836
  }
1820
1837
  data$b = {
@@ -1824,11 +1841,11 @@ function recompute$3(root) {
1824
1841
  endOffset: current.focusOffset
1825
1842
  };
1826
1843
  previous = current;
1827
- clearTimeout(timeout$2);
1844
+ clearTimeout$1(timeout$2);
1828
1845
  timeout$2 = setTimeout$1(process$3, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
1829
1846
  }
1830
1847
  function process$3(event) {
1831
- schedule(encode$3.bind(this, event));
1848
+ schedule(encode$4.bind(this, event));
1832
1849
  }
1833
1850
  function reset$f() {
1834
1851
  previous = null;
@@ -1836,7 +1853,7 @@ function reset$f() {
1836
1853
  }
1837
1854
  function stop$q() {
1838
1855
  reset$f();
1839
- clearTimeout(timeout$2);
1856
+ clearTimeout$1(timeout$2);
1840
1857
  }
1841
1858
 
1842
1859
  var state$4 = [];
@@ -1849,7 +1866,7 @@ function observe$5(root) {
1849
1866
  function recompute$2(evt) {
1850
1867
  recompute$2.dn = 16 /* FunctionNames.SubmitRecompute */;
1851
1868
  state$4.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
1852
- schedule(encode$3.bind(this, 39 /* Event.Submit */));
1869
+ schedule(encode$4.bind(this, 39 /* Event.Submit */));
1853
1870
  }
1854
1871
  function reset$e() {
1855
1872
  state$4 = [];
@@ -1865,7 +1882,7 @@ function start$q() {
1865
1882
  function recompute$1(evt) {
1866
1883
  recompute$1.dn = 17 /* FunctionNames.UnloadRecompute */;
1867
1884
  data$a = { name: evt.type, persisted: evt.persisted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */ };
1868
- encode$3(26 /* Event.Unload */, time(evt));
1885
+ encode$4(26 /* Event.Unload */, time(evt));
1869
1886
  stop();
1870
1887
  }
1871
1888
  function reset$d() {
@@ -1884,7 +1901,7 @@ function recompute(evt) {
1884
1901
  if (evt === void 0) { evt = null; }
1885
1902
  recompute.dn = 18 /* FunctionNames.VisibilityRecompute */;
1886
1903
  data$9 = { visible: "visibilityState" in document ? document.visibilityState : "default" };
1887
- encode$3(28 /* Event.Visibility */, time(evt));
1904
+ encode$4(28 /* Event.Visibility */, time(evt));
1888
1905
  }
1889
1906
  function reset$c() {
1890
1907
  data$9 = null;
@@ -2063,13 +2080,13 @@ function checkDocumentStyles(documentNode, timestamp) {
2063
2080
  }
2064
2081
  currentStyleSheets.push(styleSheet[styleSheetId]);
2065
2082
  }
2066
- var documentId = getId(documentNode, true);
2083
+ var documentId = getId$1(documentNode, true);
2067
2084
  if (!styleSheetMap[documentId]) {
2068
2085
  styleSheetMap[documentId] = [];
2069
2086
  }
2070
2087
  if (!arraysEqual(currentStyleSheets, styleSheetMap[documentId])) {
2071
2088
  // Using -1 to signify the root document node as we don't track that as part of our nodeMap
2072
- trackStyleAdoption(timestamp, documentNode == document ? -1 : getId(documentNode), 3 /* StyleSheetOperation.SetAdoptedStyles */, currentStyleSheets);
2089
+ trackStyleAdoption(timestamp, documentNode == document ? -1 : getId$1(documentNode), 3 /* StyleSheetOperation.SetAdoptedStyles */, currentStyleSheets);
2073
2090
  styleSheetMap[documentId] = currentStyleSheets;
2074
2091
  styleTimeMap[documentId] = timestamp;
2075
2092
  }
@@ -2077,7 +2094,7 @@ function checkDocumentStyles(documentNode, timestamp) {
2077
2094
  function compute$7() {
2078
2095
  for (var _i = 0, documentNodes_1 = documentNodes; _i < documentNodes_1.length; _i++) {
2079
2096
  var documentNode = documentNodes_1[_i];
2080
- var docId = documentNode == document ? -1 : getId(documentNode);
2097
+ var docId = documentNode == document ? -1 : getId$1(documentNode);
2081
2098
  var ts = docId in styleTimeMap ? styleTimeMap[docId] : null;
2082
2099
  checkDocumentStyles(documentNode, ts);
2083
2100
  }
@@ -2103,7 +2120,7 @@ function trackStyleChange(time, id, operation, cssRules) {
2103
2120
  cssRules: cssRules
2104
2121
  }
2105
2122
  });
2106
- encode$4(46 /* Event.StyleSheetUpdate */);
2123
+ encode$5(46 /* Event.StyleSheetUpdate */);
2107
2124
  }
2108
2125
  function trackStyleAdoption(time, id, operation, newIds) {
2109
2126
  sheetAdoptionState.push({
@@ -2115,7 +2132,7 @@ function trackStyleAdoption(time, id, operation, newIds) {
2115
2132
  newIds: newIds
2116
2133
  }
2117
2134
  });
2118
- encode$4(45 /* Event.StyleSheetAdoption */);
2135
+ encode$5(45 /* Event.StyleSheetAdoption */);
2119
2136
  }
2120
2137
  function arraysEqual(a, b) {
2121
2138
  if (a.length !== b.length) {
@@ -2187,7 +2204,7 @@ function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
2187
2204
  timeline: timeline
2188
2205
  }
2189
2206
  });
2190
- encode$4(44 /* Event.Animation */);
2207
+ encode$5(44 /* Event.Animation */);
2191
2208
  }
2192
2209
  function stop$k() {
2193
2210
  reset$a();
@@ -2204,7 +2221,7 @@ function overrideAnimationHelper(functionToOverride, name) {
2204
2221
  function trackAnimationOperation(animation, name) {
2205
2222
  if (active()) {
2206
2223
  var effect = animation.effect;
2207
- var target = (effect === null || effect === void 0 ? void 0 : effect.target) ? getId(effect.target) : null;
2224
+ var target = (effect === null || effect === void 0 ? void 0 : effect.target) ? getId$1(effect.target) : null;
2208
2225
  if (target !== null && effect.getKeyframes && effect.getTiming) {
2209
2226
  if (!animation[animationId]) {
2210
2227
  animation[animationId] = shortid();
@@ -2240,7 +2257,7 @@ function trackAnimationOperation(animation, name) {
2240
2257
  }
2241
2258
  }
2242
2259
 
2243
- function encode$4 (type, timer, ts) {
2260
+ function encode$5 (type, timer, ts) {
2244
2261
  if (timer === void 0) { timer = null; }
2245
2262
  if (ts === void 0) { ts = null; }
2246
2263
  return __awaiter(this, void 0, void 0, function () {
@@ -2365,7 +2382,7 @@ function encode$4 (type, timer, ts) {
2365
2382
  case "attributes":
2366
2383
  for (attr in data[key]) {
2367
2384
  if (data[key][attr] !== undefined) {
2368
- tokens.push(attribute(attr, data[key][attr], privacy));
2385
+ tokens.push(attribute$1(attr, data[key][attr], privacy));
2369
2386
  }
2370
2387
  }
2371
2388
  break;
@@ -2408,7 +2425,7 @@ function size(value) {
2408
2425
  function str(input) {
2409
2426
  return input.toString(36);
2410
2427
  }
2411
- function attribute(key, value, privacy) {
2428
+ function attribute$1(key, value, privacy) {
2412
2429
  return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
2413
2430
  }
2414
2431
 
@@ -2441,14 +2458,14 @@ function compute$6() {
2441
2458
  // Check that width or height has changed from before, and also that width & height are not null values
2442
2459
  if ((data$8 === null || width !== data$8.width || height !== data$8.height) && width !== null && height !== null) {
2443
2460
  data$8 = { width: width, height: height };
2444
- encode$4(8 /* Event.Document */);
2461
+ encode$5(8 /* Event.Document */);
2445
2462
  }
2446
2463
  }
2447
2464
  function stop$j() {
2448
2465
  reset$9();
2449
2466
  }
2450
2467
 
2451
- function traverse (root, timer, source, timestamp) {
2468
+ function traverse$1 (root, timer, source, timestamp) {
2452
2469
  return __awaiter(this, void 0, void 0, function () {
2453
2470
  var queue, entry, next, state$1, subnode;
2454
2471
  return __generator(this, function (_a) {
@@ -2641,7 +2658,7 @@ function process$2() {
2641
2658
  case 4:
2642
2659
  _i++;
2643
2660
  return [3 /*break*/, 2];
2644
- case 5: return [4 /*yield*/, encode$4(6 /* Event.Mutation */, timer, record.time)];
2661
+ case 5: return [4 /*yield*/, encode$5(6 /* Event.Mutation */, timer, record.time)];
2645
2662
  case 6:
2646
2663
  _d.sent();
2647
2664
  return [3 /*break*/, 1];
@@ -2667,7 +2684,7 @@ function process$2() {
2667
2684
  processThrottledMutations();
2668
2685
  }
2669
2686
  if (!(Object.keys(throttledMutations).length === 0 && processedMutations)) return [3 /*break*/, 13];
2670
- return [4 /*yield*/, encode$4(6 /* Event.Mutation */, timer, time())];
2687
+ return [4 /*yield*/, encode$5(6 /* Event.Mutation */, timer, time())];
2671
2688
  case 12:
2672
2689
  _d.sent();
2673
2690
  _d.label = 13;
@@ -2754,7 +2771,7 @@ function processNodeList(list, source, timer, timestamp) {
2754
2771
  if (!(i < length)) return [3 /*break*/, 6];
2755
2772
  node = list[i];
2756
2773
  if (!(source === 1 /* Source.ChildListAdd */)) return [3 /*break*/, 2];
2757
- traverse(node, timer, source, timestamp);
2774
+ traverse$1(node, timer, source, timestamp);
2758
2775
  return [3 /*break*/, 5];
2759
2776
  case 2:
2760
2777
  state$1 = state(timer);
@@ -2779,7 +2796,7 @@ function processNodeList(list, source, timer, timestamp) {
2779
2796
  }
2780
2797
  function processThrottledMutations() {
2781
2798
  if (throttleDelay) {
2782
- clearTimeout(throttleDelay);
2799
+ clearTimeout$1(throttleDelay);
2783
2800
  }
2784
2801
  throttleDelay = setTimeout$1(function () {
2785
2802
  schedule(process$2, 1 /* Priority.High */);
@@ -2794,7 +2811,7 @@ function schedule$1(node) {
2794
2811
  // It's common for a webpage to call multiple synchronous "insertRule" / "deleteRule" calls.
2795
2812
  // And in those cases we do not wish to monitor changes multiple times for the same node.
2796
2813
  if (timeout$1) {
2797
- clearTimeout(timeout$1);
2814
+ clearTimeout$1(timeout$1);
2798
2815
  }
2799
2816
  timeout$1 = setTimeout$1(function () {
2800
2817
  trigger$1();
@@ -3040,7 +3057,7 @@ function processNode (node, source, timestamp) {
3040
3057
  case Node.ELEMENT_NODE:
3041
3058
  var element = node;
3042
3059
  var tag = element.tagName;
3043
- var attributes = getAttributes(element);
3060
+ var attributes = getAttributes$1(element);
3044
3061
  // In some cases, external libraries like vue-fragment, can modify parentNode property to not be in sync with the DOM
3045
3062
  // For correctness, we first look at parentElement and if it not present then fall back to using parentNode
3046
3063
  parent = node.parentElement ? node.parentElement : (node.parentNode ? node.parentNode : null);
@@ -3220,7 +3237,7 @@ function getCssRules(sheet) {
3220
3237
  }
3221
3238
  return value;
3222
3239
  }
3223
- function getAttributes(element) {
3240
+ function getAttributes$1(element) {
3224
3241
  var output = {};
3225
3242
  var attributes = element.attributes;
3226
3243
  if (attributes && attributes.length > 0) {
@@ -3332,9 +3349,9 @@ var selector = /*#__PURE__*/Object.freeze({
3332
3349
  reset: reset$8
3333
3350
  });
3334
3351
 
3335
- var index = 1;
3352
+ var index$1 = 1;
3336
3353
  var nodesMap = null; // Maps id => node to retrieve further node details using id.
3337
- var values = [];
3354
+ var values$1 = [];
3338
3355
  var updateMap = [];
3339
3356
  var hashMap = {};
3340
3357
  var override = [];
@@ -3344,7 +3361,7 @@ var maskExclude = [];
3344
3361
  var maskDisable = [];
3345
3362
  var maskTags = [];
3346
3363
  // The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced
3347
- var idMap = null; // Maps node => id.
3364
+ var idMap$1 = null; // Maps node => id.
3348
3365
  var iframeMap = null; // Maps iframe's contentDocument => parent iframe element
3349
3366
  var iframeContentMap = null; // Maps parent iframe element => iframe's contentDocument & contentWindow
3350
3367
  var privacyMap = null; // Maps node => Privacy (enum)
@@ -3357,8 +3374,8 @@ function stop$h() {
3357
3374
  reset$7();
3358
3375
  }
3359
3376
  function reset$7() {
3360
- index = 1;
3361
- values = [];
3377
+ index$1 = 1;
3378
+ values$1 = [];
3362
3379
  updateMap = [];
3363
3380
  hashMap = {};
3364
3381
  override = [];
@@ -3368,7 +3385,7 @@ function reset$7() {
3368
3385
  maskDisable = "radio,checkbox,range,button,reset,submit" /* Mask.Disable */.split("," /* Constant.Comma */);
3369
3386
  maskTags = "INPUT,SELECT,TEXTAREA" /* Mask.Tags */.split("," /* Constant.Comma */);
3370
3387
  nodesMap = new Map();
3371
- idMap = new WeakMap();
3388
+ idMap$1 = new WeakMap();
3372
3389
  iframeMap = new WeakMap();
3373
3390
  iframeContentMap = new WeakMap();
3374
3391
  privacyMap = new WeakMap();
@@ -3399,32 +3416,32 @@ function parse(root, init) {
3399
3416
  log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
3400
3417
  }
3401
3418
  }
3402
- function getId(node, autogen) {
3419
+ function getId$1(node, autogen) {
3403
3420
  if (autogen === void 0) { autogen = false; }
3404
3421
  if (node === null) {
3405
3422
  return null;
3406
3423
  }
3407
- var id = idMap.get(node);
3424
+ var id = idMap$1.get(node);
3408
3425
  if (!id && autogen) {
3409
- id = index++;
3410
- idMap.set(node, id);
3426
+ id = index$1++;
3427
+ idMap$1.set(node, id);
3411
3428
  }
3412
3429
  return id ? id : null;
3413
3430
  }
3414
- function add(node, parent, data, source) {
3415
- var parentId = parent ? getId(parent) : null;
3431
+ function add$1(node, parent, data, source) {
3432
+ var parentId = parent ? getId$1(parent) : null;
3416
3433
  // Do not add detached nodes
3417
3434
  if ((!parent || !parentId) && node.host == null && node.nodeType !== Node.DOCUMENT_TYPE_NODE) {
3418
3435
  return;
3419
3436
  }
3420
- var id = getId(node, true);
3437
+ var id = getId$1(node, true);
3421
3438
  var previousId = getPreviousId(node);
3422
3439
  var parentValue = null;
3423
3440
  var regionId = exists(node) ? id : null;
3424
3441
  var fraudId = fraudMap.has(node) ? fraudMap.get(node) : null;
3425
3442
  var privacyId = config$2.content ? 1 /* Privacy.Sensitive */ : 3 /* Privacy.TextImage */;
3426
- if (parentId >= 0 && values[parentId]) {
3427
- parentValue = values[parentId];
3443
+ if (parentId >= 0 && values$1[parentId]) {
3444
+ parentValue = values$1[parentId];
3428
3445
  parentValue.children.push(id);
3429
3446
  regionId = regionId === null ? parentValue.region : regionId;
3430
3447
  fraudId = fraudId === null ? parentValue.metadata.fraud : fraudId;
@@ -3436,7 +3453,7 @@ function add(node, parent, data, source) {
3436
3453
  regionId = id;
3437
3454
  }
3438
3455
  nodesMap.set(id, node);
3439
- values[id] = {
3456
+ values$1[id] = {
3440
3457
  id: id,
3441
3458
  parent: parentId,
3442
3459
  previous: previousId,
@@ -3447,19 +3464,19 @@ function add(node, parent, data, source) {
3447
3464
  region: regionId,
3448
3465
  metadata: { active: true, suspend: false, privacy: privacyId, position: null, fraud: fraudId, size: null },
3449
3466
  };
3450
- privacy(node, values[id], parentValue);
3451
- updateSelector(values[id]);
3452
- updateImageSize(values[id]);
3467
+ privacy(node, values$1[id], parentValue);
3468
+ updateSelector(values$1[id]);
3469
+ updateImageSize(values$1[id]);
3453
3470
  track$4(id, source);
3454
3471
  }
3455
3472
  function update(node, parent, data, source) {
3456
- var id = getId(node);
3457
- var parentId = parent ? getId(parent) : null;
3473
+ var id = getId$1(node);
3474
+ var parentId = parent ? getId$1(parent) : null;
3458
3475
  var previousId = getPreviousId(node);
3459
3476
  var changed = false;
3460
3477
  var parentChanged = false;
3461
- if (id in values) {
3462
- var value = values[id];
3478
+ if (id in values$1) {
3479
+ var value = values$1[id];
3463
3480
  value.metadata.active = true;
3464
3481
  // Handle case where internal ordering may have changed
3465
3482
  if (value.previous !== previousId) {
@@ -3473,10 +3490,10 @@ function update(node, parent, data, source) {
3473
3490
  value.parent = parentId;
3474
3491
  // Move this node to the right location under new parent
3475
3492
  if (parentId !== null && parentId >= 0) {
3476
- var childIndex = previousId === null ? 0 : values[parentId].children.indexOf(previousId) + 1;
3477
- values[parentId].children.splice(childIndex, 0, id);
3493
+ var childIndex = previousId === null ? 0 : values$1[parentId].children.indexOf(previousId) + 1;
3494
+ values$1[parentId].children.splice(childIndex, 0, id);
3478
3495
  // Update region after the move
3479
- value.region = exists(node) ? id : values[parentId].region;
3496
+ value.region = exists(node) ? id : values$1[parentId].region;
3480
3497
  }
3481
3498
  else {
3482
3499
  // Mark this element as deleted if the parent has been updated to null
@@ -3484,9 +3501,9 @@ function update(node, parent, data, source) {
3484
3501
  }
3485
3502
  // Remove reference to this node from the old parent
3486
3503
  if (oldParentId !== null && oldParentId >= 0) {
3487
- var nodeIndex = values[oldParentId].children.indexOf(id);
3504
+ var nodeIndex = values$1[oldParentId].children.indexOf(id);
3488
3505
  if (nodeIndex >= 0) {
3489
- values[oldParentId].children.splice(nodeIndex, 1);
3506
+ values$1[oldParentId].children.splice(nodeIndex, 1);
3490
3507
  }
3491
3508
  }
3492
3509
  parentChanged = true;
@@ -3616,7 +3633,7 @@ function position(parent, child) {
3616
3633
  child.metadata.position = 1;
3617
3634
  var idx = parent ? parent.children.indexOf(child.id) : -1;
3618
3635
  while (idx-- > 0) {
3619
- var sibling = values[parent.children[idx]];
3636
+ var sibling = values$1[parent.children[idx]];
3620
3637
  if (child.data.tag === sibling.data.tag) {
3621
3638
  child.metadata.position = sibling.metadata.position + 1;
3622
3639
  break;
@@ -3625,7 +3642,7 @@ function position(parent, child) {
3625
3642
  return child.metadata.position;
3626
3643
  }
3627
3644
  function updateSelector(value) {
3628
- var parent = value.parent && value.parent in values ? values[value.parent] : null;
3645
+ var parent = value.parent && value.parent in values$1 ? values$1[value.parent] : null;
3629
3646
  var prefix = parent ? parent.selector : null;
3630
3647
  var d = value.data;
3631
3648
  var p = position(parent, value);
@@ -3643,35 +3660,35 @@ function getNode(id) {
3643
3660
  return nodesMap.has(id) ? nodesMap.get(id) : null;
3644
3661
  }
3645
3662
  function getValue(id) {
3646
- if (id in values) {
3647
- return values[id];
3663
+ if (id in values$1) {
3664
+ return values$1[id];
3648
3665
  }
3649
3666
  return null;
3650
3667
  }
3651
3668
  function get(node) {
3652
- var id = getId(node);
3653
- return id in values ? values[id] : null;
3669
+ var id = getId$1(node);
3670
+ return id in values$1 ? values$1[id] : null;
3654
3671
  }
3655
3672
  function lookup(hash) {
3656
3673
  return hash in hashMap ? hashMap[hash] : null;
3657
3674
  }
3658
3675
  function has$1(node) {
3659
- return nodesMap.has(getId(node));
3676
+ return nodesMap.has(getId$1(node));
3660
3677
  }
3661
3678
  function updates$2() {
3662
3679
  var output = [];
3663
3680
  for (var _i = 0, updateMap_1 = updateMap; _i < updateMap_1.length; _i++) {
3664
3681
  var id = updateMap_1[_i];
3665
- if (id in values) {
3666
- output.push(values[id]);
3682
+ if (id in values$1) {
3683
+ output.push(values$1[id]);
3667
3684
  }
3668
3685
  }
3669
3686
  updateMap = [];
3670
3687
  return output;
3671
3688
  }
3672
3689
  function remove(id, source) {
3673
- if (id in values) {
3674
- var value = values[id];
3690
+ if (id in values$1) {
3691
+ var value = values$1[id];
3675
3692
  value.metadata.active = false;
3676
3693
  value.parent = null;
3677
3694
  track$4(id, source);
@@ -3691,7 +3708,7 @@ function removeNodeFromNodesMap(id) {
3691
3708
  removeObserver(iframe_1);
3692
3709
  }
3693
3710
  nodesMap.delete(id);
3694
- var value = id in values ? values[id] : null;
3711
+ var value = id in values$1 ? values$1[id] : null;
3695
3712
  if (value && value.children) {
3696
3713
  for (var _i = 0, _a = value.children; _i < _a.length; _i++) {
3697
3714
  var childId = _a[_i];
@@ -3718,7 +3735,7 @@ function getPreviousId(node) {
3718
3735
  // Some nodes may not have an ID by design since Clarity skips over tags like SCRIPT, NOSCRIPT, META, COMMENTS, etc..
3719
3736
  // In that case, we keep going back and check for their sibling until we find a sibling with ID or no more sibling nodes are left.
3720
3737
  while (id === null && node.previousSibling) {
3721
- id = getId(node.previousSibling);
3738
+ id = getId$1(node.previousSibling);
3722
3739
  node = node.previousSibling;
3723
3740
  }
3724
3741
  return id;
@@ -3801,7 +3818,7 @@ function compute$5() {
3801
3818
  var q = [];
3802
3819
  for (var _i = 0, queue_1 = queue$1; _i < queue_1.length; _i++) {
3803
3820
  var r = queue_1[_i];
3804
- var id = getId(r.node);
3821
+ var id = getId$1(r.node);
3805
3822
  if (id) {
3806
3823
  r.state.data.id = id;
3807
3824
  regions[id] = r.state.data;
@@ -3814,7 +3831,7 @@ function compute$5() {
3814
3831
  queue$1 = q;
3815
3832
  // Schedule encode only when we have at least one valid data entry
3816
3833
  if (state$2.length > 0) {
3817
- encode$4(7 /* Event.Region */);
3834
+ encode$5(7 /* Event.Region */);
3818
3835
  }
3819
3836
  }
3820
3837
  function handler$1(entries) {
@@ -3829,7 +3846,7 @@ function handler$1(entries) {
3829
3846
  // like search box - one for desktop, and another for mobile. In those cases, CSS media queries determine which one should be visible.
3830
3847
  // Also, if these regions ever become non-zero width or height (through AJAX, user action or orientation change) - we will automatically start monitoring them from that point onwards
3831
3848
  if (regionMap.has(target) && rect.width + rect.height > 0 && viewport && viewport.width > 0 && viewport.height > 0) {
3832
- var id = target ? getId(target) : null;
3849
+ var id = target ? getId$1(target) : null;
3833
3850
  var data = id in regions ? regions[id] : { id: id, name: regionMap.get(target), interaction: 16 /* InteractionState.None */, visibility: 0 /* RegionVisibility.Rendered */ };
3834
3851
  // For regions that have relatively smaller area, we look at intersection ratio and see the overlap relative to element's area
3835
3852
  // However, for larger regions, area of regions could be bigger than viewport and therefore comparison is relative to visible area
@@ -3850,7 +3867,7 @@ function handler$1(entries) {
3850
3867
  }
3851
3868
  }
3852
3869
  if (state$2.length > 0) {
3853
- encode$4(7 /* Event.Region */);
3870
+ encode$5(7 /* Event.Region */);
3854
3871
  }
3855
3872
  }
3856
3873
  function process$1(n, d, s, v) {
@@ -3917,7 +3934,7 @@ function metadata$2(node, event, text) {
3917
3934
  return output;
3918
3935
  }
3919
3936
 
3920
- function encode$3 (type, ts) {
3937
+ function encode$4 (type, ts) {
3921
3938
  if (ts === void 0) { ts = null; }
3922
3939
  return __awaiter(this, void 0, void 0, function () {
3923
3940
  var t, tokens, _i, _a, entry, pTarget, _b, _c, entry, cTarget, cHash, _d, _e, entry, target, r, u, _f, _g, entry, iTarget, s, startTarget, endTarget, _h, _j, entry, sTarget, top_1, bottom, sTopHash, sBottomHash, _k, _l, entry, target, _m, _o, entry, target, _p, _q, entry, v;
@@ -3957,6 +3974,7 @@ function encode$3 (type, ts) {
3957
3974
  reset$i();
3958
3975
  break;
3959
3976
  case 9 /* Event.Click */:
3977
+ case 48 /* Event.ContextMenu */:
3960
3978
  for (_b = 0, _c = state$9; _b < _c.length; _b++) {
3961
3979
  entry = _c[_b];
3962
3980
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
@@ -4155,13 +4173,146 @@ function compute$4() {
4155
4173
  }
4156
4174
  }
4157
4175
  state$1 = temp; // Drop events less than the min time
4158
- encode$3(22 /* Event.Timeline */);
4176
+ encode$4(22 /* Event.Timeline */);
4159
4177
  }
4160
4178
  function stop$f() {
4161
4179
  state$1 = [];
4162
4180
  reset$5();
4163
4181
  }
4164
4182
 
4183
+ function encode$3 (type) {
4184
+ return __awaiter(this, void 0, void 0, function () {
4185
+ var eventTime, tokens, d, values$1, _i, values_1, value, privacy, data, _a, _b, key, attr;
4186
+ return __generator(this, function (_c) {
4187
+ eventTime = time();
4188
+ tokens = [eventTime, type];
4189
+ switch (type) {
4190
+ case 8 /* Event.Document */:
4191
+ d = data$8;
4192
+ tokens.push(d.width);
4193
+ tokens.push(d.height);
4194
+ track$8(type, d.width, d.height);
4195
+ queue(tokens);
4196
+ break;
4197
+ case 43 /* Event.Snapshot */:
4198
+ values$1 = values;
4199
+ // Only encode and queue DOM updates if we have valid updates to report back
4200
+ if (values$1.length > 0) {
4201
+ for (_i = 0, values_1 = values$1; _i < values_1.length; _i++) {
4202
+ value = values_1[_i];
4203
+ privacy = value.metadata.privacy;
4204
+ data = value.data;
4205
+ for (_a = 0, _b = ["tag", "attributes", "value"]; _a < _b.length; _a++) {
4206
+ key = _b[_a];
4207
+ if (data[key]) {
4208
+ switch (key) {
4209
+ case "tag":
4210
+ tokens.push(value.id);
4211
+ if (value.parent) {
4212
+ tokens.push(value.parent);
4213
+ }
4214
+ if (value.previous) {
4215
+ tokens.push(value.previous);
4216
+ }
4217
+ tokens.push(data[key]);
4218
+ break;
4219
+ case "attributes":
4220
+ for (attr in data[key]) {
4221
+ if (data[key][attr] !== undefined) {
4222
+ tokens.push(attribute(attr, data[key][attr], privacy));
4223
+ }
4224
+ }
4225
+ break;
4226
+ case "value":
4227
+ tokens.push(text$1(data[key], data.tag, privacy));
4228
+ break;
4229
+ }
4230
+ }
4231
+ }
4232
+ }
4233
+ queue(tokenize(tokens), true);
4234
+ }
4235
+ break;
4236
+ }
4237
+ return [2 /*return*/];
4238
+ });
4239
+ });
4240
+ }
4241
+ function attribute(key, value, privacy) {
4242
+ return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
4243
+ }
4244
+
4245
+ var values = [];
4246
+ var index = 1;
4247
+ var idMap = null; // Maps node => id.
4248
+ function snapshot() {
4249
+ values = [];
4250
+ traverse(document);
4251
+ encode$3(43 /* Event.Snapshot */);
4252
+ }
4253
+ function traverse(root) {
4254
+ var queue = [root];
4255
+ while (queue.length > 0) {
4256
+ var attributes = null, tag = null, value = null;
4257
+ var node = queue.shift();
4258
+ var next = node.firstChild;
4259
+ var parent_1 = node.parentElement ? node.parentElement : (node.parentNode ? node.parentNode : null);
4260
+ while (next) {
4261
+ queue.push(next);
4262
+ next = next.nextSibling;
4263
+ }
4264
+ // Process the node
4265
+ var type = node.nodeType;
4266
+ switch (type) {
4267
+ case Node.DOCUMENT_TYPE_NODE:
4268
+ var doctype = node;
4269
+ tag = "*D" /* Constant.DocumentTag */;
4270
+ attributes = { name: doctype.name, publicId: doctype.publicId, systemId: doctype.systemId };
4271
+ break;
4272
+ case Node.TEXT_NODE:
4273
+ value = node.nodeValue;
4274
+ tag = idMap.get(parent_1) ? "*T" /* Constant.TextTag */ : tag;
4275
+ break;
4276
+ case Node.ELEMENT_NODE:
4277
+ var element = node;
4278
+ attributes = getAttributes(element);
4279
+ tag = ["NOSCRIPT", "SCRIPT", "STYLE"].indexOf(element.tagName) < 0 ? element.tagName : tag;
4280
+ break;
4281
+ }
4282
+ add(node, parent_1, { tag: tag, attributes: attributes, value: value });
4283
+ }
4284
+ }
4285
+ /* Helper Functions - Snapshot Traversal */
4286
+ function getAttributes(element) {
4287
+ var output = {};
4288
+ var attributes = element.attributes;
4289
+ if (attributes && attributes.length > 0) {
4290
+ for (var i = 0; i < attributes.length; i++) {
4291
+ output[attributes[i].name] = attributes[i].value;
4292
+ }
4293
+ }
4294
+ return output;
4295
+ }
4296
+ function getId(node) {
4297
+ if (node === null) {
4298
+ return null;
4299
+ }
4300
+ if (idMap.has(node)) {
4301
+ return idMap.get(node);
4302
+ }
4303
+ idMap.set(node, index);
4304
+ return index++;
4305
+ }
4306
+ function add(node, parent, data) {
4307
+ if (node && data && data.tag) {
4308
+ var id = getId(node);
4309
+ var parentId = parent ? idMap.get(parent) : null;
4310
+ var previous = node.previousSibling ? idMap.get(node.previousSibling) : null;
4311
+ var metadata_1 = { active: true, suspend: false, privacy: 5 /* Privacy.Snapshot */, position: null, fraud: null, size: null };
4312
+ values.push({ id: id, parent: parentId, previous: previous, children: [], data: data, selector: null, hash: null, region: null, metadata: metadata_1 });
4313
+ }
4314
+ }
4315
+
4165
4316
  var discoverBytes = 0;
4166
4317
  var playbackBytes = 0;
4167
4318
  var playback;
@@ -4226,7 +4377,7 @@ function queue(tokens, transmit) {
4226
4377
  // reset the timer. This allows Clarity to attempt an upload again.
4227
4378
  var gap = delay();
4228
4379
  if (now - queuedTime > (gap * 2)) {
4229
- clearTimeout(timeout);
4380
+ clearTimeout$1(timeout);
4230
4381
  timeout = null;
4231
4382
  }
4232
4383
  // Transmit Check: When transmit is set to true (default), it indicates that we should schedule an upload
@@ -4242,7 +4393,7 @@ function queue(tokens, transmit) {
4242
4393
  }
4243
4394
  }
4244
4395
  function stop$e() {
4245
- clearTimeout(timeout);
4396
+ clearTimeout$1(timeout);
4246
4397
  upload(true);
4247
4398
  discoverBytes = 0;
4248
4399
  playbackBytes = 0;
@@ -4312,6 +4463,7 @@ function stringify(encoded) {
4312
4463
  return encoded.p.length > 0 ? "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, ",\"p\":").concat(encoded.p, "}") : "{\"e\":".concat(encoded.e, ",\"a\":").concat(encoded.a, "}");
4313
4464
  }
4314
4465
  function send(payload, zipped, sequence, beacon) {
4466
+ var _a;
4315
4467
  if (beacon === void 0) { beacon = false; }
4316
4468
  // Upload data if a valid URL is defined in the config
4317
4469
  if (typeof config$2.upload === "string" /* Constant.String */) {
@@ -4328,8 +4480,15 @@ function send(payload, zipped, sequence, beacon) {
4328
4480
  if (dispatched) {
4329
4481
  done(sequence);
4330
4482
  }
4483
+ else {
4484
+ // If sendBeacon fails, we report the error and continue with XHR upload
4485
+ report(new Error("".concat("BeaconError" /* Constant.BeaconError */, ": ").concat(payload.length)));
4486
+ }
4487
+ }
4488
+ catch (error) {
4489
+ // If sendBeacon fails, we report the error and continue with XHR upload
4490
+ report(new Error("".concat("BeaconError" /* Constant.BeaconError */, ": ").concat((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.substring(0, 50), " : ").concat(payload.length)));
4331
4491
  }
4332
- catch ( /* do nothing - and we will automatically fallback to XHR below */_a) { /* do nothing - and we will automatically fallback to XHR below */ }
4333
4492
  }
4334
4493
  // Before initiating XHR upload, we check if the data has already been uploaded using sendBeacon
4335
4494
  // There are two cases when dispatched could still be false:
@@ -4389,6 +4548,9 @@ function check$3(xhr, sequence) {
4389
4548
  if (xhr.status === 0) {
4390
4549
  config$2.upload = config$2.fallback ? config$2.fallback : config$2.upload;
4391
4550
  }
4551
+ // Capture the status code and number of attempts so we can report it back to the server
4552
+ track$1 = { sequence: sequence, attempts: transitData.attempts, status: xhr.status };
4553
+ encode$1(2 /* Event.Upload */);
4392
4554
  // In all other cases, re-attempt sending the same data
4393
4555
  // For retry we always fallback to string payload, even though we may have attempted
4394
4556
  // sending zipped payload earlier
@@ -4464,6 +4626,10 @@ function response(payload) {
4464
4626
  signalsEvent(parts[1]);
4465
4627
  }
4466
4628
  break;
4629
+ case "SNAPSHOT" /* Constant.Snapshot */:
4630
+ config$2.lean = false; // Disable lean mode to ensure we can send playback information to server.
4631
+ snapshot();
4632
+ break;
4467
4633
  }
4468
4634
  }
4469
4635
  }
@@ -4780,11 +4946,11 @@ function discover() {
4780
4946
  ts = time();
4781
4947
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4782
4948
  start$d(timer);
4783
- return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
4949
+ return [4 /*yield*/, traverse$1(document, timer, 0 /* Source.Discover */, ts)];
4784
4950
  case 1:
4785
4951
  _a.sent();
4786
4952
  checkDocumentStyles(document, ts);
4787
- return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4953
+ return [4 /*yield*/, encode$5(5 /* Event.Discover */, timer, ts)];
4788
4954
  case 2:
4789
4955
  _a.sent();
4790
4956
  stop$c(timer);
@@ -4834,7 +5000,7 @@ function encode$1 (event) {
4834
5000
  switch (event) {
4835
5001
  case 4 /* Event.Baseline */: {
4836
5002
  var b = state$b;
4837
- if (b) {
5003
+ if (b && b.data) {
4838
5004
  tokens = [b.time, b.event];
4839
5005
  tokens.push(b.data.visible);
4840
5006
  tokens.push(b.data.docWidth);
@@ -4948,7 +5114,7 @@ function encode$1 (event) {
4948
5114
  }
4949
5115
  case 40 /* Event.Extract */: {
4950
5116
  var extractKeys = keys;
4951
- extractKeys.forEach((function (e) {
5117
+ extractKeys.forEach(function (e) {
4952
5118
  tokens.push(e);
4953
5119
  var token = [];
4954
5120
  for (var d in data$e[e]) {
@@ -4957,7 +5123,7 @@ function encode$1 (event) {
4957
5123
  token.push(data$e[e][d]);
4958
5124
  }
4959
5125
  tokens.push(token);
4960
- }));
5126
+ });
4961
5127
  reset$n();
4962
5128
  queue(tokens, false);
4963
5129
  break;
@@ -5062,7 +5228,7 @@ function start$8() {
5062
5228
  var _a, _b, _c;
5063
5229
  rootDomain = null;
5064
5230
  var ua = navigator && "userAgent" in navigator ? navigator.userAgent : "" /* Constant.Empty */;
5065
- var timezone = (_c = (_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat()) === null || _a === void 0 ? void 0 : _a.resolvedOptions()) === null || _b === void 0 ? void 0 : _b.timeZone) !== null && _c !== void 0 ? _c : '';
5231
+ var timezone = (_c = (typeof Intl !== 'undefined' && ((_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat()) === null || _a === void 0 ? void 0 : _a.resolvedOptions()) === null || _b === void 0 ? void 0 : _b.timeZone))) !== null && _c !== void 0 ? _c : '';
5066
5232
  var timezoneOffset = new Date().getTimezoneOffset().toString();
5067
5233
  var ancestorOrigins = window.location.ancestorOrigins ? Array.from(window.location.ancestorOrigins).toString() : '';
5068
5234
  var title = document && document.title ? document.title : "" /* Constant.Empty */;
@@ -5904,7 +6070,7 @@ var observer;
5904
6070
  var types = ["navigation" /* Constant.Navigation */, "resource" /* Constant.Resource */, "longtask" /* Constant.LongTask */, "first-input" /* Constant.FID */, "layout-shift" /* Constant.CLS */, "largest-contentful-paint" /* Constant.LCP */, "event" /* Constant.PerformanceEventTiming */];
5905
6071
  function start$2() {
5906
6072
  // Capture connection properties, if available
5907
- if (navigator && "connection" in navigator) {
6073
+ if (navigator && navigator["connection"]) {
5908
6074
  log(27 /* Dimension.ConnectionType */, navigator["connection"]["effectiveType"]);
5909
6075
  }
5910
6076
  // Check the browser support performance observer as a pre-requisite for any performance measurement