@cloudcare/browser-rum 2.2.15 → 3.0.1

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 +388 -0
  22. package/cjs/domain/replay/record/observers.js +470 -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 +4400 -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 +127 -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 +336 -0
  77. package/esm/domain/replay/record/observers.js +454 -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 +4393 -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 +114 -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 +403 -0
  132. package/src/domain/replay/record/observers.js +565 -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 +4584 -0
  143. package/src/domain/replay/segmentCollection/index.js +6 -0
  144. package/src/domain/replay/segmentCollection/segment.js +86 -0
  145. package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
  146. package/src/domain/replay/segmentCollection/startDeflateWorker.js +102 -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,336 @@
1
+ import { noop, getChildNodes, isNodeShadowHost, getParentNode, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
2
+ import { getMutationObserverConstructor } from '../../domMutationCollection';
3
+ import { NodePrivacyLevel } from '../../../constants';
4
+ import { getNodePrivacyLevel, getTextContent } from './privacy';
5
+ import { getElementInputValue, getSerializedNodeId, hasSerializedNode, nodeAndAncestorsHaveSerializedNode } from './serializationUtils';
6
+ import { serializeNodeWithId, serializeAttribute, SerializationContextStatus } from './serialize';
7
+ import { createMutationBatch } from './mutationBatch';
8
+ /**
9
+ * Buffers and aggregate mutations generated by a MutationObserver into MutationPayload
10
+ */
11
+
12
+ export function startMutationObserver(mutationCallback, configuration, shadowRootsController, target) {
13
+ var MutationObserver = getMutationObserverConstructor();
14
+
15
+ if (!MutationObserver) {
16
+ return {
17
+ stop: noop,
18
+ flush: noop
19
+ };
20
+ }
21
+
22
+ var mutationBatch = createMutationBatch(function (mutations) {
23
+ processMutations(mutations.concat(observer.takeRecords()), mutationCallback, configuration, shadowRootsController, target);
24
+ });
25
+ var observer = new MutationObserver(mutationBatch.addMutations);
26
+ observer.observe(target, {
27
+ attributeOldValue: true,
28
+ attributes: true,
29
+ characterData: true,
30
+ characterDataOldValue: true,
31
+ childList: true,
32
+ subtree: true
33
+ });
34
+ return {
35
+ stop: function stop() {
36
+ observer.disconnect();
37
+ mutationBatch.stop();
38
+ },
39
+ flush: function flush() {
40
+ mutationBatch.flush();
41
+ }
42
+ };
43
+ }
44
+
45
+ function processMutations(mutations, mutationCallback, configuration, shadowRootsController, target) {
46
+ mutations.filter(function (mutation) {
47
+ return mutation.type === 'childList';
48
+ }).forEach(function (mutation) {
49
+ mutation.removedNodes.forEach(function (removedNode) {
50
+ traverseRemovedShadowDom(removedNode, shadowRootsController.removeShadowRoot);
51
+ });
52
+ }); // Discard any mutation with a 'target' node that:
53
+ // * isn't injected in the current document or isn't known/serialized yet: those nodes are likely
54
+ // part of a mutation occurring in a parent Node
55
+ // * should be hidden or ignored
56
+
57
+ var filteredMutations = mutations.filter(function (mutation) {
58
+ return target.contains(mutation.target) && nodeAndAncestorsHaveSerializedNode(mutation.target) && getNodePrivacyLevel(mutation.target, configuration.defaultPrivacyLevel) !== NodePrivacyLevel.HIDDEN;
59
+ });
60
+
61
+ var _processChildListMutations = processChildListMutations(filteredMutations.filter(function (mutation) {
62
+ return mutation.type === 'childList';
63
+ }), configuration, shadowRootsController);
64
+
65
+ var adds = _processChildListMutations.adds;
66
+ var removes = _processChildListMutations.removes; // var hasBeenSerialized = _processChildListMutations.hasBeenSerialized
67
+
68
+ var serializedNodeIds = _processChildListMutations.serializedNodeIds;
69
+
70
+ function hasBeenSerialized(node) {
71
+ return hasSerializedNode(node) && serializedNodeIds.has(getSerializedNodeId(node));
72
+ }
73
+
74
+ var texts = processCharacterDataMutations(filteredMutations.filter(function (mutation) {
75
+ return mutation.type === 'characterData' && !hasBeenSerialized(mutation.target);
76
+ }), configuration);
77
+ var attributes = processAttributesMutations(filteredMutations.filter(function (mutation) {
78
+ return mutation.type === 'attributes' && !hasBeenSerialized(mutation.target);
79
+ }), configuration);
80
+
81
+ if (!texts.length && !attributes.length && !removes.length && !adds.length) {
82
+ return;
83
+ }
84
+
85
+ mutationCallback({
86
+ adds: adds,
87
+ removes: removes,
88
+ texts: texts,
89
+ attributes: attributes
90
+ });
91
+ }
92
+
93
+ function processChildListMutations(mutations, configuration, shadowRootsController) {
94
+ // First, we iterate over mutations to collect:
95
+ //
96
+ // * nodes that have been added in the document and not removed by a subsequent mutation
97
+ // * nodes that have been removed from the document but were not added in a previous mutation
98
+ //
99
+ // For this second category, we also collect their previous parent (mutation.target) because we'll
100
+ // need it to emit a 'remove' mutation.
101
+ //
102
+ // Those two categories may overlap: if a node moved from a position to another, it is reported as
103
+ // two mutation records, one with a "removedNodes" and the other with "addedNodes". In this case,
104
+ // the node will be in both sets.
105
+ var addedAndMovedNodes = new Set();
106
+ var removedNodes = new Map();
107
+
108
+ for (var mutation of mutations) {
109
+ mutation.addedNodes.forEach(function (node) {
110
+ addedAndMovedNodes.add(node);
111
+ });
112
+ mutation.removedNodes.forEach(function (node) {
113
+ if (!addedAndMovedNodes.has(node)) {
114
+ removedNodes.set(node, mutation.target);
115
+ }
116
+
117
+ addedAndMovedNodes.delete(node);
118
+ });
119
+ } // Then, we sort nodes that are still in the document by topological order, for two reasons:
120
+ //
121
+ // * We will serialize each added nodes with their descendants. We don't want to serialize a node
122
+ // twice, so we need to iterate over the parent nodes first and skip any node that is contained in
123
+ // a precedent node.
124
+ //
125
+ // * To emit "add" mutations, we need references to the parent and potential next sibling of each
126
+ // added node. So we need to iterate over the parent nodes first, and when multiple nodes are
127
+ // siblings, we want to iterate from last to first. This will ensure that any "next" node is
128
+ // already serialized and have an id.
129
+
130
+
131
+ var sortedAddedAndMovedNodes = Array.from(addedAndMovedNodes);
132
+ sortAddedAndMovedNodes(sortedAddedAndMovedNodes); // Then, we iterate over our sorted node sets to emit mutations. We collect the newly serialized
133
+ // node ids in a set to be able to skip subsequent related mutations.
134
+
135
+ var serializedNodeIds = new Set();
136
+ var addedNodeMutations = [];
137
+
138
+ for (var node of sortedAddedAndMovedNodes) {
139
+ if (hasBeenSerialized(node)) {
140
+ continue;
141
+ }
142
+
143
+ var parentNodePrivacyLevel = getNodePrivacyLevel(node.parentNode, configuration.defaultPrivacyLevel);
144
+
145
+ if (parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === NodePrivacyLevel.IGNORE) {
146
+ continue;
147
+ }
148
+
149
+ var serializedNode = serializeNodeWithId(node, {
150
+ serializedNodeIds: serializedNodeIds,
151
+ parentNodePrivacyLevel: parentNodePrivacyLevel,
152
+ serializationContext: {
153
+ status: SerializationContextStatus.MUTATION,
154
+ shadowRootsController: shadowRootsController
155
+ },
156
+ configuration
157
+ });
158
+
159
+ if (!serializedNode) {
160
+ continue;
161
+ }
162
+
163
+ var parentNode = getParentNode(node);
164
+ addedNodeMutations.push({
165
+ nextId: getNextSibling(node),
166
+ parentId: getSerializedNodeId(parentNode),
167
+ node: serializedNode
168
+ });
169
+ } // Finally, we emit remove mutations.
170
+
171
+
172
+ var removedNodeMutations = [];
173
+ removedNodes.forEach(function (parent, node) {
174
+ if (hasSerializedNode(node)) {
175
+ removedNodeMutations.push({
176
+ parentId: getSerializedNodeId(parent),
177
+ id: getSerializedNodeId(node)
178
+ });
179
+ }
180
+ });
181
+ return {
182
+ adds: addedNodeMutations,
183
+ removes: removedNodeMutations,
184
+ serializedNodeIds: serializedNodeIds,
185
+ hasBeenSerialized: hasBeenSerialized
186
+ };
187
+
188
+ function hasBeenSerialized(node) {
189
+ return hasSerializedNode(node) && serializedNodeIds.has(getSerializedNodeId(node));
190
+ }
191
+
192
+ function getNextSibling(node) {
193
+ var nextSibling = node.nextSibling;
194
+
195
+ while (nextSibling) {
196
+ if (hasSerializedNode(nextSibling)) {
197
+ return getSerializedNodeId(nextSibling);
198
+ }
199
+
200
+ nextSibling = nextSibling.nextSibling;
201
+ }
202
+
203
+ return null;
204
+ }
205
+ }
206
+
207
+ function processCharacterDataMutations(mutations, configuration) {
208
+ var textMutations = []; // Deduplicate mutations based on their target node
209
+
210
+ var handledNodes = new Set();
211
+ var filteredMutations = mutations.filter(function (mutation) {
212
+ if (handledNodes.has(mutation.target)) {
213
+ return false;
214
+ }
215
+
216
+ handledNodes.add(mutation.target);
217
+ return true;
218
+ }); // Emit mutations
219
+
220
+ for (var mutation of filteredMutations) {
221
+ var value = mutation.target.textContent;
222
+
223
+ if (value === mutation.oldValue) {
224
+ continue;
225
+ }
226
+
227
+ var parentNodePrivacyLevel = getNodePrivacyLevel(getParentNode(mutation.target), configuration.defaultPrivacyLevel);
228
+
229
+ if (parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === NodePrivacyLevel.IGNORE) {
230
+ continue;
231
+ }
232
+
233
+ textMutations.push({
234
+ id: getSerializedNodeId(mutation.target),
235
+ // TODO: pass a valid "ignoreWhiteSpace" argument
236
+ value: isNullUndefinedDefaultValue(getTextContent(mutation.target, false, parentNodePrivacyLevel, null))
237
+ });
238
+ }
239
+
240
+ return textMutations;
241
+ }
242
+
243
+ function processAttributesMutations(mutations, configuration) {
244
+ var attributeMutations = []; // Deduplicate mutations based on their target node and changed attribute
245
+
246
+ var handledElements = new Map();
247
+ var filteredMutations = mutations.filter(function (mutation) {
248
+ var handledAttributes = handledElements.get(mutation.target);
249
+
250
+ if (handledAttributes && handledAttributes.has(mutation.attributeName)) {
251
+ return false;
252
+ }
253
+
254
+ if (!handledAttributes) {
255
+ handledElements.set(mutation.target, new Set([mutation.attributeName]));
256
+ } else {
257
+ handledAttributes.add(mutation.attributeName);
258
+ }
259
+
260
+ return true;
261
+ }); // Emit mutations
262
+
263
+ var emittedMutations = new Map();
264
+
265
+ for (var mutation of filteredMutations) {
266
+ var uncensoredValue = mutation.target.getAttribute(mutation.attributeName);
267
+
268
+ if (uncensoredValue === mutation.oldValue) {
269
+ continue;
270
+ }
271
+
272
+ var privacyLevel = getNodePrivacyLevel(mutation.target, configuration.defaultPrivacyLevel);
273
+ var attributeValue = serializeAttribute(mutation.target, privacyLevel, mutation.attributeName, configuration);
274
+ var transformedValue;
275
+
276
+ if (mutation.attributeName === 'value') {
277
+ var inputValue = getElementInputValue(mutation.target, privacyLevel);
278
+
279
+ if (inputValue === undefined) {
280
+ continue;
281
+ }
282
+
283
+ transformedValue = inputValue;
284
+ } else if (typeof attributeValue === 'string') {
285
+ transformedValue = attributeValue;
286
+ } else {
287
+ transformedValue = null;
288
+ }
289
+
290
+ var emittedMutation = emittedMutations.get(mutation.target);
291
+
292
+ if (!emittedMutation) {
293
+ emittedMutation = {
294
+ id: getSerializedNodeId(mutation.target),
295
+ attributes: {}
296
+ };
297
+ attributeMutations.push(emittedMutation);
298
+ emittedMutations.set(mutation.target, emittedMutation);
299
+ }
300
+
301
+ emittedMutation.attributes[mutation.attributeName] = transformedValue;
302
+ }
303
+
304
+ return attributeMutations;
305
+ }
306
+
307
+ export function sortAddedAndMovedNodes(nodes) {
308
+ nodes.sort(function (a, b) {
309
+ var position = a.compareDocumentPosition(b);
310
+ /* eslint-disable no-bitwise */
311
+
312
+ if (position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
313
+ return -1;
314
+ } else if (position & Node.DOCUMENT_POSITION_CONTAINS) {
315
+ return 1;
316
+ } else if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
317
+ return 1;
318
+ } else if (position & Node.DOCUMENT_POSITION_PRECEDING) {
319
+ return -1;
320
+ }
321
+ /* eslint-enable no-bitwise */
322
+
323
+
324
+ return 0;
325
+ });
326
+ }
327
+
328
+ function traverseRemovedShadowDom(removedNode, shadowDomRemovedCallback) {
329
+ if (isNodeShadowHost(removedNode)) {
330
+ shadowDomRemovedCallback(removedNode.shadowRoot);
331
+ }
332
+
333
+ getChildNodes(removedNode).forEach(function (child) {
334
+ traverseRemovedShadowDom(child, shadowDomRemovedCallback);
335
+ });
336
+ }