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