@cloudcare/browser-rum 2.2.13 → 3.0.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.
Files changed (166) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +161 -0
  4. package/cjs/boot/rum.entry.js +6 -1
  5. package/cjs/boot/rum.js +15 -5
  6. package/cjs/boot/rumPublicApi.js +8 -4
  7. package/cjs/boot/startRecording.js +55 -0
  8. package/cjs/constants.js +52 -0
  9. package/cjs/domain/assembly.js +1 -7
  10. package/cjs/domain/configuration.js +3 -2
  11. package/cjs/domain/contexts/foregroundContexts.js +138 -0
  12. package/cjs/domain/contexts/internalContext.js +1 -1
  13. package/cjs/domain/contexts/urlContexts.js +9 -2
  14. package/cjs/domain/domMutationCollection.js +4 -5
  15. package/cjs/domain/initViewportObservable.js +52 -0
  16. package/cjs/domain/locationChangeObservable.js +12 -26
  17. package/cjs/domain/performanceCollection.js +2 -13
  18. package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
  19. package/cjs/domain/replay/record/index.js +41 -0
  20. package/cjs/domain/replay/record/mutationBatch.js +58 -0
  21. package/cjs/domain/replay/record/mutationObserver.js +383 -0
  22. package/cjs/domain/replay/record/observers.js +473 -0
  23. package/cjs/domain/replay/record/privacy.js +256 -0
  24. package/cjs/domain/replay/record/record.js +174 -0
  25. package/cjs/domain/replay/record/serializationUtils.js +137 -0
  26. package/cjs/domain/replay/record/serialize.js +488 -0
  27. package/cjs/domain/replay/record/shadowRootsController.js +61 -0
  28. package/cjs/domain/replay/record/utils.js +53 -0
  29. package/cjs/domain/replay/record/viewports.js +104 -0
  30. package/cjs/domain/replay/replayStats.js +83 -0
  31. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
  32. package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
  33. package/cjs/domain/replay/segmentCollection/index.js +33 -0
  34. package/cjs/domain/replay/segmentCollection/segment.js +101 -0
  35. package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
  36. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
  37. package/cjs/domain/requestCollection.js +35 -17
  38. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  39. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  40. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  41. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
  42. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
  43. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  44. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
  45. package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
  46. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
  47. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  48. package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
  49. package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
  50. package/cjs/domain/rumSessionManager.js +6 -3
  51. package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
  52. package/cjs/domain/trackEventCounts.js +10 -2
  53. package/cjs/domain/waitPageActivityEnd.js +5 -1
  54. package/cjs/transport/startRumBatch.js +5 -7
  55. package/cjs/types/index.js +18 -0
  56. package/cjs/types/sessionReplayConstants.js +56 -0
  57. package/esm/boot/buildEnv.js +1 -1
  58. package/esm/boot/recorderApi.js +149 -0
  59. package/esm/boot/rum.entry.js +4 -1
  60. package/esm/boot/rum.js +15 -6
  61. package/esm/boot/rumPublicApi.js +8 -4
  62. package/esm/boot/startRecording.js +44 -0
  63. package/esm/constants.js +31 -0
  64. package/esm/domain/assembly.js +1 -7
  65. package/esm/domain/configuration.js +4 -3
  66. package/esm/domain/contexts/foregroundContexts.js +122 -0
  67. package/esm/domain/contexts/internalContext.js +1 -1
  68. package/esm/domain/contexts/urlContexts.js +10 -3
  69. package/esm/domain/domMutationCollection.js +5 -6
  70. package/esm/domain/initViewportObservable.js +39 -0
  71. package/esm/domain/locationChangeObservable.js +13 -27
  72. package/esm/domain/performanceCollection.js +1 -12
  73. package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
  74. package/esm/domain/replay/record/index.js +3 -0
  75. package/esm/domain/replay/record/mutationBatch.js +35 -0
  76. package/esm/domain/replay/record/mutationObserver.js +331 -0
  77. package/esm/domain/replay/record/observers.js +457 -0
  78. package/esm/domain/replay/record/privacy.js +233 -0
  79. package/esm/domain/replay/record/record.js +158 -0
  80. package/esm/domain/replay/record/serializationUtils.js +107 -0
  81. package/esm/domain/replay/record/serialize.js +461 -0
  82. package/esm/domain/replay/record/shadowRootsController.js +49 -0
  83. package/esm/domain/replay/record/utils.js +38 -0
  84. package/esm/domain/replay/record/viewports.js +87 -0
  85. package/esm/domain/replay/replayStats.js +64 -0
  86. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
  87. package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
  88. package/esm/domain/replay/segmentCollection/index.js +3 -0
  89. package/esm/domain/replay/segmentCollection/segment.js +84 -0
  90. package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
  91. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
  92. package/esm/domain/requestCollection.js +36 -18
  93. package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  94. package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
  95. package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  96. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
  97. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
  98. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  99. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
  100. package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
  101. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
  102. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
  103. package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
  104. package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
  105. package/esm/domain/rumSessionManager.js +6 -3
  106. package/esm/domain/tracing/getDocumentTraceId.js +1 -9
  107. package/esm/domain/trackEventCounts.js +10 -2
  108. package/esm/domain/waitPageActivityEnd.js +5 -1
  109. package/esm/transport/startRumBatch.js +5 -7
  110. package/esm/types/index.js +1 -0
  111. package/esm/types/sessionReplayConstants.js +45 -0
  112. package/package.json +3 -3
  113. package/src/boot/recorderApi.js +166 -0
  114. package/src/boot/rum.entry.js +4 -1
  115. package/src/boot/rum.js +38 -10
  116. package/src/boot/rumPublicApi.js +13 -3
  117. package/src/boot/startRecording.js +77 -0
  118. package/src/constants.js +37 -0
  119. package/src/domain/assembly.js +1 -6
  120. package/src/domain/configuration.js +10 -2
  121. package/src/domain/contexts/foregroundContexts.js +140 -0
  122. package/src/domain/contexts/internalContext.js +10 -4
  123. package/src/domain/contexts/urlContexts.js +29 -15
  124. package/src/domain/domMutationCollection.js +14 -6
  125. package/src/domain/initViewportObservable.js +46 -0
  126. package/src/domain/locationChangeObservable.js +17 -25
  127. package/src/domain/performanceCollection.js +42 -42
  128. package/src/domain/replay/record/elementsScrollPositions.js +22 -0
  129. package/src/domain/replay/record/index.js +7 -0
  130. package/src/domain/replay/record/mutationBatch.js +38 -0
  131. package/src/domain/replay/record/mutationObserver.js +393 -0
  132. package/src/domain/replay/record/observers.js +562 -0
  133. package/src/domain/replay/record/privacy.js +304 -0
  134. package/src/domain/replay/record/record.js +158 -0
  135. package/src/domain/replay/record/serializationUtils.js +134 -0
  136. package/src/domain/replay/record/serialize.js +497 -0
  137. package/src/domain/replay/record/shadowRootsController.js +58 -0
  138. package/src/domain/replay/record/utils.js +44 -0
  139. package/src/domain/replay/record/viewports.js +89 -0
  140. package/src/domain/replay/replayStats.js +67 -0
  141. package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
  142. package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
  143. package/src/domain/replay/segmentCollection/index.js +6 -0
  144. package/src/domain/replay/segmentCollection/segment.js +87 -0
  145. package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
  146. package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
  147. package/src/domain/requestCollection.js +64 -28
  148. package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
  149. package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
  150. package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
  151. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
  152. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
  153. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
  154. package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
  155. package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
  156. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
  157. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  158. package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
  159. package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
  160. package/src/domain/rumSessionManager.js +33 -19
  161. package/src/domain/tracing/getDocumentTraceId.js +6 -9
  162. package/src/domain/trackEventCounts.js +10 -4
  163. package/src/domain/waitPageActivityEnd.js +4 -1
  164. package/src/transport/startRumBatch.js +29 -24
  165. package/src/types/index.js +1 -0
  166. package/src/types/sessionReplayConstants.js +49 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createViewportObservable = createViewportObservable;
7
+ exports.getViewportDimension = getViewportDimension;
8
+ exports.initViewportObservable = initViewportObservable;
9
+
10
+ var _browserCore = require("@cloudcare/browser-core");
11
+
12
+ var viewportObservable;
13
+
14
+ function initViewportObservable() {
15
+ if (!viewportObservable) {
16
+ viewportObservable = createViewportObservable();
17
+ }
18
+
19
+ return viewportObservable;
20
+ }
21
+
22
+ function createViewportObservable() {
23
+ var observable = new _browserCore.Observable(function () {
24
+ var _throttledUpdateDimension = (0, _browserCore.throttle)(function () {
25
+ observable.notify(getViewportDimension());
26
+ }, 200);
27
+
28
+ var updateDimension = _throttledUpdateDimension.throttled;
29
+ return (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.RESIZE, updateDimension, {
30
+ capture: true,
31
+ passive: true
32
+ }).stop;
33
+ });
34
+ return observable;
35
+ } // excludes the width and height of any rendered classic scrollbar that is fixed to the visual viewport
36
+
37
+
38
+ function getViewportDimension() {
39
+ var visual = window.visualViewport;
40
+
41
+ if (visual) {
42
+ return {
43
+ width: Number(visual.width * visual.scale),
44
+ height: Number(visual.height * visual.scale)
45
+ };
46
+ }
47
+
48
+ return {
49
+ width: Number(window.innerWidth || 0),
50
+ height: Number(window.innerHeight || 0)
51
+ };
52
+ }
@@ -39,33 +39,19 @@ function createLocationChangeObservable(location) {
39
39
 
40
40
  function trackHistory(onHistoryChange) {
41
41
  // eslint-disable-next-line @typescript-eslint/unbound-method
42
- var originalPushState = history.pushState;
43
-
44
- history.pushState = function () {
45
- originalPushState.apply(this, arguments);
46
- onHistoryChange();
47
- }; // eslint-disable-next-line @typescript-eslint/unbound-method
48
-
49
-
50
- var originalReplaceState = history.replaceState;
51
-
52
- history.replaceState = function () {
53
- originalReplaceState.apply(this, arguments);
54
- onHistoryChange();
55
- };
56
-
57
- var _addEventListener = (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.POP_STATE, onHistoryChange);
58
-
59
- var removeListener = _addEventListener.stop;
60
-
61
- var stop = function stop() {
62
- removeListener();
63
- history.pushState = originalPushState;
64
- history.replaceState = originalReplaceState;
65
- };
66
-
42
+ var pushState = (0, _browserCore.instrumentMethodAndCallOriginal)(history, 'pushState', {
43
+ after: onHistoryChange
44
+ });
45
+ var replaceState = (0, _browserCore.instrumentMethodAndCallOriginal)(history, 'replaceState', {
46
+ after: onHistoryChange
47
+ });
48
+ var popState = (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.POP_STATE, onHistoryChange);
67
49
  return {
68
- stop: stop
50
+ stop: function stop() {
51
+ pushState.stop();
52
+ replaceState.stop();
53
+ popState.stop();
54
+ }
69
55
  };
70
56
  }
71
57
 
@@ -88,7 +88,7 @@ function startPerformanceCollection(lifeCycle, configuration) {
88
88
  }
89
89
 
90
90
  function retrieveInitialDocumentResourceTiming(callback) {
91
- runOnReadyState('interactive', function () {
91
+ (0, _browserCore.runOnReadyState)('interactive', function () {
92
92
  var timing;
93
93
  var forcedAttributes = {
94
94
  entryType: 'resource',
@@ -120,7 +120,7 @@ function retrieveNavigationTiming(callback) {
120
120
  }));
121
121
  }
122
122
 
123
- runOnReadyState('complete', function () {
123
+ (0, _browserCore.runOnReadyState)('complete', function () {
124
124
  // Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
125
125
  setTimeout(sendFakeTiming);
126
126
  });
@@ -194,17 +194,6 @@ function retrieveFirstInputTiming(callback) {
194
194
  }
195
195
  }
196
196
 
197
- function runOnReadyState(expectedReadyState, callback) {
198
- if (document.readyState === expectedReadyState || document.readyState === 'complete') {
199
- callback();
200
- } else {
201
- var eventName = expectedReadyState === 'complete' ? _browserCore.DOM_EVENT.LOAD : _browserCore.DOM_EVENT.DOM_CONTENT_LOADED;
202
- (0, _browserCore.addEventListener)(window, eventName, callback, {
203
- once: true
204
- });
205
- }
206
- }
207
-
208
197
  function computeRelativePerformanceTiming() {
209
198
  var result = {};
210
199
  var timing = performance.timing;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElementsScrollPositions = createElementsScrollPositions;
7
+
8
+ function createElementsScrollPositions() {
9
+ var scrollPositionsByElement = new WeakMap();
10
+ return {
11
+ set: function set(element, scrollPositions) {
12
+ if (element === document && !document.scrollingElement) {
13
+ // cf https://drafts.csswg.org/cssom-view/#dom-document-scrollingelement,
14
+ // in some cases scrolling elements can not be defined, we don't support those for now
15
+ return;
16
+ }
17
+
18
+ scrollPositionsByElement.set(element === document ? document.scrollingElement : element, scrollPositions);
19
+ },
20
+ get: function get(element) {
21
+ return scrollPositionsByElement.get(element);
22
+ },
23
+ has: function has(element) {
24
+ return scrollPositionsByElement.has(element);
25
+ }
26
+ };
27
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SerializationContextStatus", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _serialize.SerializationContextStatus;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "createElementsScrollPositions", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _elementsScrollPositions.createElementsScrollPositions;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "record", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _record.record;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "serializeDocument", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _serialize.serializeDocument;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "serializeNodeWithId", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _serialize.serializeNodeWithId;
34
+ }
35
+ });
36
+
37
+ var _record = require("./record");
38
+
39
+ var _serialize = require("./serialize");
40
+
41
+ var _elementsScrollPositions = require("./elementsScrollPositions");
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createMutationBatch = createMutationBatch;
7
+
8
+ var _browserCore = require("@cloudcare/browser-core");
9
+
10
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
+
12
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+
16
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
17
+
18
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
21
+
22
+ /**
23
+ * Maximum duration to wait before processing mutations. If the browser is idle, mutations will be
24
+ * processed more quickly. If the browser is busy executing small tasks (ex: rendering frames), the
25
+ * mutations will wait MUTATION_PROCESS_MAX_DELAY milliseconds before being processed. If the
26
+ * browser is busy executing a longer task, mutations will be processed after this task.
27
+ */
28
+ var MUTATION_PROCESS_MAX_DELAY = 100;
29
+
30
+ function createMutationBatch(processMutationBatch) {
31
+ var cancelScheduledFlush = _browserCore.noop;
32
+ var pendingMutations = [];
33
+
34
+ function flush() {
35
+ cancelScheduledFlush();
36
+ processMutationBatch(pendingMutations);
37
+ pendingMutations = [];
38
+ }
39
+
40
+ return {
41
+ addMutations: function addMutations(mutations) {
42
+ var _pendingMutations;
43
+
44
+ if (pendingMutations.length === 0) {
45
+ cancelScheduledFlush = (0, _browserCore.requestIdleCallback)(flush, {
46
+ timeout: MUTATION_PROCESS_MAX_DELAY
47
+ });
48
+ }
49
+
50
+ (_pendingMutations = pendingMutations).push.apply(_pendingMutations, _toConsumableArray(mutations)); // Array.prototype.push.apply(pendingMutations, mutations)
51
+
52
+ },
53
+ flush: flush,
54
+ stop: function stop() {
55
+ cancelScheduledFlush();
56
+ }
57
+ };
58
+ }
@@ -0,0 +1,383 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortAddedAndMovedNodes = sortAddedAndMovedNodes;
7
+ exports.startMutationObserver = startMutationObserver;
8
+
9
+ var _browserCore = require("@cloudcare/browser-core");
10
+
11
+ var _domMutationCollection = require("../../domMutationCollection");
12
+
13
+ var _constants = require("../../../constants");
14
+
15
+ var _privacy = require("./privacy");
16
+
17
+ var _serializationUtils = require("./serializationUtils");
18
+
19
+ var _serialize = require("./serialize");
20
+
21
+ var _mutationBatch = require("./mutationBatch");
22
+
23
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
24
+
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+
27
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
28
+
29
+ /**
30
+ * Buffers and aggregate mutations generated by a MutationObserver into MutationPayload
31
+ */
32
+ function startMutationObserver(mutationCallback, configuration, shadowRootsController, target) {
33
+ var MutationObserver = (0, _domMutationCollection.getMutationObserverConstructor)();
34
+
35
+ if (!MutationObserver) {
36
+ return {
37
+ stop: _browserCore.noop,
38
+ flush: _browserCore.noop
39
+ };
40
+ }
41
+
42
+ var mutationBatch = (0, _mutationBatch.createMutationBatch)(function (mutations) {
43
+ processMutations(mutations.concat(observer.takeRecords()), mutationCallback, configuration, shadowRootsController, target);
44
+ });
45
+ var observer = new MutationObserver(mutationBatch.addMutations);
46
+ observer.observe(target, {
47
+ attributeOldValue: true,
48
+ attributes: true,
49
+ characterData: true,
50
+ characterDataOldValue: true,
51
+ childList: true,
52
+ subtree: true
53
+ });
54
+ return {
55
+ stop: function stop() {
56
+ observer.disconnect();
57
+ mutationBatch.stop();
58
+ },
59
+ flush: function flush() {
60
+ mutationBatch.flush();
61
+ }
62
+ };
63
+ }
64
+
65
+ function processMutations(mutations, mutationCallback, configuration, shadowRootsController, target) {
66
+ mutations.filter(function (mutation) {
67
+ return mutation.type === 'childList';
68
+ }).forEach(function (mutation) {
69
+ mutation.removedNodes.forEach(function (removedNode) {
70
+ traverseRemovedShadowDom(removedNode, shadowRootsController.removeShadowRoot);
71
+ });
72
+ }); // Discard any mutation with a 'target' node that:
73
+ // * isn't injected in the current document or isn't known/serialized yet: those nodes are likely
74
+ // part of a mutation occurring in a parent Node
75
+ // * should be hidden or ignored
76
+
77
+ var filteredMutations = mutations.filter(function (mutation) {
78
+ return target.contains(mutation.target) && (0, _serializationUtils.nodeAndAncestorsHaveSerializedNode)(mutation.target) && (0, _privacy.getNodePrivacyLevel)(mutation.target, configuration.defaultPrivacyLevel) !== _constants.NodePrivacyLevel.HIDDEN;
79
+ });
80
+
81
+ var _processChildListMutations = processChildListMutations(filteredMutations.filter(function (mutation) {
82
+ return mutation.type === 'childList';
83
+ }), configuration, shadowRootsController);
84
+
85
+ var adds = _processChildListMutations.adds;
86
+ var removes = _processChildListMutations.removes;
87
+ var hasBeenSerialized = _processChildListMutations.hasBeenSerialized;
88
+ var texts = processCharacterDataMutations(filteredMutations.filter(function (mutation) {
89
+ return mutation.type === 'characterData' && !hasBeenSerialized(mutation.target);
90
+ }), configuration);
91
+ var attributes = processAttributesMutations(filteredMutations.filter(function (mutation) {
92
+ mutation.type === 'attributes' && !hasBeenSerialized(mutation.target);
93
+ }), configuration);
94
+
95
+ if (!texts.length && !attributes.length && !removes.length && !adds.length) {
96
+ return;
97
+ }
98
+
99
+ mutationCallback({
100
+ adds: adds,
101
+ removes: removes,
102
+ texts: texts,
103
+ attributes: attributes
104
+ });
105
+ }
106
+
107
+ function processChildListMutations(mutations, configuration, shadowRootsController) {
108
+ // First, we iterate over mutations to collect:
109
+ //
110
+ // * nodes that have been added in the document and not removed by a subsequent mutation
111
+ // * nodes that have been removed from the document but were not added in a previous mutation
112
+ //
113
+ // For this second category, we also collect their previous parent (mutation.target) because we'll
114
+ // need it to emit a 'remove' mutation.
115
+ //
116
+ // Those two categories may overlap: if a node moved from a position to another, it is reported as
117
+ // two mutation records, one with a "removedNodes" and the other with "addedNodes". In this case,
118
+ // the node will be in both sets.
119
+ var addedAndMovedNodes = new Set();
120
+ var removedNodes = new Map();
121
+
122
+ var _iterator = _createForOfIteratorHelper(mutations),
123
+ _step;
124
+
125
+ try {
126
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
127
+ var mutation = _step.value;
128
+ mutation.addedNodes.forEach(function (node) {
129
+ addedAndMovedNodes.add(node);
130
+ });
131
+ mutation.removedNodes.forEach(function (node) {
132
+ if (!addedAndMovedNodes.has(node)) {
133
+ removedNodes.set(node, mutation.target);
134
+ }
135
+
136
+ addedAndMovedNodes["delete"](node);
137
+ });
138
+ } // Then, we sort nodes that are still in the document by topological order, for two reasons:
139
+ //
140
+ // * We will serialize each added nodes with their descendants. We don't want to serialize a node
141
+ // twice, so we need to iterate over the parent nodes first and skip any node that is contained in
142
+ // a precedent node.
143
+ //
144
+ // * To emit "add" mutations, we need references to the parent and potential next sibling of each
145
+ // added node. So we need to iterate over the parent nodes first, and when multiple nodes are
146
+ // siblings, we want to iterate from last to first. This will ensure that any "next" node is
147
+ // already serialized and have an id.
148
+
149
+ } catch (err) {
150
+ _iterator.e(err);
151
+ } finally {
152
+ _iterator.f();
153
+ }
154
+
155
+ var sortedAddedAndMovedNodes = Array.from(addedAndMovedNodes);
156
+ sortAddedAndMovedNodes(sortedAddedAndMovedNodes); // Then, we iterate over our sorted node sets to emit mutations. We collect the newly serialized
157
+ // node ids in a set to be able to skip subsequent related mutations.
158
+
159
+ var serializedNodeIds = new Set();
160
+ var addedNodeMutations = [];
161
+
162
+ for (var _i = 0, _sortedAddedAndMovedN = sortedAddedAndMovedNodes; _i < _sortedAddedAndMovedN.length; _i++) {
163
+ var node = _sortedAddedAndMovedN[_i];
164
+
165
+ if (hasBeenSerialized(node)) {
166
+ continue;
167
+ }
168
+
169
+ var parentNodePrivacyLevel = (0, _privacy.getNodePrivacyLevel)(node.parentNode, configuration.defaultPrivacyLevel);
170
+
171
+ if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
172
+ continue;
173
+ }
174
+
175
+ var serializedNode = (0, _serialize.serializeNodeWithId)(node, {
176
+ serializedNodeIds: serializedNodeIds,
177
+ parentNodePrivacyLevel: parentNodePrivacyLevel,
178
+ serializationContext: {
179
+ status: _serialize.SerializationContextStatus.MUTATION,
180
+ shadowRootsController: shadowRootsController
181
+ },
182
+ configuration: configuration
183
+ });
184
+
185
+ if (!serializedNode) {
186
+ continue;
187
+ }
188
+
189
+ var parentNode = (0, _browserCore.getParentNode)(node);
190
+ addedNodeMutations.push({
191
+ nextId: getNextSibling(node),
192
+ parentId: (0, _serializationUtils.getSerializedNodeId)(parentNode),
193
+ node: serializedNode
194
+ });
195
+ } // Finally, we emit remove mutations.
196
+
197
+
198
+ var removedNodeMutations = [];
199
+ removedNodes.forEach(function (parent, node) {
200
+ if ((0, _serializationUtils.hasSerializedNode)(node)) {
201
+ removedNodeMutations.push({
202
+ parentId: (0, _serializationUtils.getSerializedNodeId)(parent),
203
+ id: (0, _serializationUtils.getSerializedNodeId)(node)
204
+ });
205
+ }
206
+ });
207
+ return {
208
+ adds: addedNodeMutations,
209
+ removes: removedNodeMutations,
210
+ hasBeenSerialized: hasBeenSerialized
211
+ };
212
+
213
+ function hasBeenSerialized(node) {
214
+ return (0, _serializationUtils.hasSerializedNode)(node) && serializedNodeIds.has((0, _serializationUtils.getSerializedNodeId)(node));
215
+ }
216
+
217
+ function getNextSibling(node) {
218
+ var nextSibling = node.nextSibling;
219
+
220
+ while (nextSibling) {
221
+ if ((0, _serializationUtils.hasSerializedNode)(nextSibling)) {
222
+ return (0, _serializationUtils.getSerializedNodeId)(nextSibling);
223
+ }
224
+
225
+ nextSibling = nextSibling.nextSibling;
226
+ }
227
+
228
+ return null;
229
+ }
230
+ }
231
+
232
+ function processCharacterDataMutations(mutations, configuration) {
233
+ var textMutations = []; // Deduplicate mutations based on their target node
234
+
235
+ var handledNodes = new Set();
236
+ var filteredMutations = mutations.filter(function (mutation) {
237
+ if (handledNodes.has(mutation.target)) {
238
+ return false;
239
+ }
240
+
241
+ handledNodes.add(mutation.target);
242
+ return true;
243
+ }); // Emit mutations
244
+
245
+ var _iterator2 = _createForOfIteratorHelper(filteredMutations),
246
+ _step2;
247
+
248
+ try {
249
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
250
+ var _getTextContent;
251
+
252
+ var mutation = _step2.value;
253
+ var value = mutation.target.textContent;
254
+
255
+ if (value === mutation.oldValue) {
256
+ continue;
257
+ }
258
+
259
+ var parentNodePrivacyLevel = (0, _privacy.getNodePrivacyLevel)((0, _browserCore.getParentNode)(mutation.target), configuration.defaultPrivacyLevel);
260
+
261
+ if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
262
+ continue;
263
+ }
264
+
265
+ textMutations.push({
266
+ id: (0, _serializationUtils.getSerializedNodeId)(mutation.target),
267
+ // TODO: pass a valid "ignoreWhiteSpace" argument
268
+ value: (_getTextContent = (0, _privacy.getTextContent)(mutation.target, false, parentNodePrivacyLevel)) !== null && _getTextContent !== void 0 ? _getTextContent : null
269
+ });
270
+ }
271
+ } catch (err) {
272
+ _iterator2.e(err);
273
+ } finally {
274
+ _iterator2.f();
275
+ }
276
+
277
+ return textMutations;
278
+ }
279
+
280
+ function processAttributesMutations(mutations, configuration) {
281
+ var attributeMutations = []; // Deduplicate mutations based on their target node and changed attribute
282
+
283
+ var handledElements = new Map();
284
+ var filteredMutations = mutations.filter(function (mutation) {
285
+ var handledAttributes = handledElements.get(mutation.target);
286
+
287
+ if (handledAttributes !== null && handledAttributes !== void 0 && handledAttributes.has(mutation.attributeName)) {
288
+ return false;
289
+ }
290
+
291
+ if (!handledAttributes) {
292
+ handledElements.set(mutation.target, new Set([mutation.attributeName]));
293
+ } else {
294
+ handledAttributes.add(mutation.attributeName);
295
+ }
296
+
297
+ return true;
298
+ }); // Emit mutations
299
+
300
+ var emittedMutations = new Map();
301
+
302
+ var _iterator3 = _createForOfIteratorHelper(filteredMutations),
303
+ _step3;
304
+
305
+ try {
306
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
307
+ var mutation = _step3.value;
308
+ var uncensoredValue = mutation.target.getAttribute(mutation.attributeName);
309
+
310
+ if (uncensoredValue === mutation.oldValue) {
311
+ continue;
312
+ }
313
+
314
+ var privacyLevel = (0, _privacy.getNodePrivacyLevel)(mutation.target, configuration.defaultPrivacyLevel);
315
+ var attributeValue = (0, _serialize.serializeAttribute)(mutation.target, privacyLevel, mutation.attributeName, configuration);
316
+ var transformedValue;
317
+
318
+ if (mutation.attributeName === 'value') {
319
+ var inputValue = (0, _serializationUtils.getElementInputValue)(mutation.target, privacyLevel);
320
+
321
+ if (inputValue === undefined) {
322
+ continue;
323
+ }
324
+
325
+ transformedValue = inputValue;
326
+ } else if (typeof attributeValue === 'string') {
327
+ transformedValue = attributeValue;
328
+ } else {
329
+ transformedValue = null;
330
+ }
331
+
332
+ var emittedMutation = emittedMutations.get(mutation.target);
333
+
334
+ if (!emittedMutation) {
335
+ emittedMutation = {
336
+ id: (0, _serializationUtils.getSerializedNodeId)(mutation.target),
337
+ attributes: {}
338
+ };
339
+ attributeMutations.push(emittedMutation);
340
+ emittedMutations.set(mutation.target, emittedMutation);
341
+ }
342
+
343
+ emittedMutation.attributes[mutation.attributeName] = transformedValue;
344
+ }
345
+ } catch (err) {
346
+ _iterator3.e(err);
347
+ } finally {
348
+ _iterator3.f();
349
+ }
350
+
351
+ return attributeMutations;
352
+ }
353
+
354
+ function sortAddedAndMovedNodes(nodes) {
355
+ nodes.sort(function (a, b) {
356
+ var position = a.compareDocumentPosition(b);
357
+ /* eslint-disable no-bitwise */
358
+
359
+ if (position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
360
+ return -1;
361
+ } else if (position & Node.DOCUMENT_POSITION_CONTAINS) {
362
+ return 1;
363
+ } else if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
364
+ return 1;
365
+ } else if (position & Node.DOCUMENT_POSITION_PRECEDING) {
366
+ return -1;
367
+ }
368
+ /* eslint-enable no-bitwise */
369
+
370
+
371
+ return 0;
372
+ });
373
+ }
374
+
375
+ function traverseRemovedShadowDom(removedNode, shadowDomRemovedCallback) {
376
+ if ((0, _browserCore.isNodeShadowHost)(removedNode)) {
377
+ shadowDomRemovedCallback(removedNode.shadowRoot);
378
+ }
379
+
380
+ (0, _browserCore.getChildNodes)(removedNode).forEach(function (child) {
381
+ traverseRemovedShadowDom(child, shadowDomRemovedCallback);
382
+ });
383
+ }