@cloudcare/browser-rum 3.2.49 → 3.3.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/README.md +89 -1
- package/README.zh.md +105 -0
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/perStartRum.js +16 -0
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +154 -1
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/rum.js +17 -2
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +52 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/boot/startRecording.js +69 -4
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/domain/configuration.js +99 -1
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/replay/record/canvasAutoSnapshot.js +15 -0
- package/cjs/domain/replay/record/canvasAutoSnapshot.js.map +1 -0
- package/cjs/domain/replay/record/canvasCommandCapture.js +480 -0
- package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -0
- package/cjs/domain/replay/record/canvasCommandObserver.js +274 -0
- package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -0
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +94 -0
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -0
- package/cjs/domain/replay/record/canvasContinuousScheduler.js +255 -0
- package/cjs/domain/replay/record/canvasContinuousScheduler.js.map +1 -0
- package/cjs/domain/replay/record/canvasEncodeBridge.js +247 -0
- package/cjs/domain/replay/record/canvasEncodeBridge.js.map +1 -0
- package/cjs/domain/replay/record/canvasEncodeWorker.js +154 -0
- package/cjs/domain/replay/record/canvasEncodeWorker.js.map +1 -0
- package/cjs/domain/replay/record/canvasFrameSignature.js +50 -0
- package/cjs/domain/replay/record/canvasFrameSignature.js.map +1 -0
- package/cjs/domain/replay/record/canvasMutationRecord.js +33 -0
- package/cjs/domain/replay/record/canvasMutationRecord.js.map +1 -0
- package/cjs/domain/replay/record/canvasObserver.js +190 -0
- package/cjs/domain/replay/record/canvasObserver.js.map +1 -0
- package/cjs/domain/replay/record/canvasReplayFixtures.js +105 -0
- package/cjs/domain/replay/record/canvasReplayFixtures.js.map +1 -0
- package/cjs/domain/replay/record/canvasSerializeArgs.js +110 -0
- package/cjs/domain/replay/record/canvasSerializeArgs.js.map +1 -0
- package/cjs/domain/replay/record/mutationBatch.js +7 -2
- package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +369 -55
- package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
- package/cjs/domain/replay/record/observers.js +8 -3
- package/cjs/domain/replay/record/observers.js.map +1 -1
- package/cjs/domain/replay/record/record.js +478 -1
- package/cjs/domain/replay/record/record.js.map +1 -1
- package/cjs/domain/replay/record/serializationUtils.js +60 -4
- package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
- package/cjs/domain/replay/record/serialize.js +169 -46
- package/cjs/domain/replay/record/serialize.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segment.js +58 -1
- package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +29 -3
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/cjs/domain/requestCollection.js +1 -1
- package/cjs/domain/requestCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +1 -1
- package/cjs/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -1
- package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/trackReportError.js +2 -2
- package/cjs/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +43 -39
- package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +48 -8
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js +237 -0
- package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -0
- package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +2 -0
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/cjs/domain/tracing/skywalkingTracer.js +1 -1
- package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
- package/cjs/types/sessionReplayConstants.js +2 -2
- package/cjs/types/sessionReplayConstants.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/perStartRum.js +16 -0
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +154 -1
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/rum.js +17 -2
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rumPublicApi.js +52 -3
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +70 -5
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/domain/configuration.js +100 -2
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/replay/record/canvasAutoSnapshot.js +9 -0
- package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -0
- package/esm/domain/replay/record/canvasCommandCapture.js +474 -0
- package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -0
- package/esm/domain/replay/record/canvasCommandObserver.js +268 -0
- package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -0
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js +87 -0
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -0
- package/esm/domain/replay/record/canvasContinuousScheduler.js +249 -0
- package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -0
- package/esm/domain/replay/record/canvasEncodeBridge.js +240 -0
- package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -0
- package/esm/domain/replay/record/canvasEncodeWorker.js +146 -0
- package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -0
- package/esm/domain/replay/record/canvasFrameSignature.js +42 -0
- package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -0
- package/esm/domain/replay/record/canvasMutationRecord.js +26 -0
- package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -0
- package/esm/domain/replay/record/canvasObserver.js +184 -0
- package/esm/domain/replay/record/canvasObserver.js.map +1 -0
- package/esm/domain/replay/record/canvasReplayFixtures.js +96 -0
- package/esm/domain/replay/record/canvasReplayFixtures.js.map +1 -0
- package/esm/domain/replay/record/canvasSerializeArgs.js +101 -0
- package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -0
- package/esm/domain/replay/record/mutationBatch.js +7 -2
- package/esm/domain/replay/record/mutationBatch.js.map +1 -1
- package/esm/domain/replay/record/mutationObserver.js +369 -56
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/observers.js +8 -3
- package/esm/domain/replay/record/observers.js.map +1 -1
- package/esm/domain/replay/record/record.js +479 -2
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +58 -4
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +168 -47
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +59 -2
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +30 -4
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/requestCollection.js +1 -1
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackReportError.js +2 -2
- package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +43 -38
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +50 -10
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +231 -0
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -0
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumSessionManager.js +2 -0
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/skywalkingTracer.js +1 -1
- package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
- package/esm/types/sessionReplayConstants.js +2 -2
- package/esm/types/sessionReplayConstants.js.map +1 -1
- package/package.json +5 -5
- package/src/boot/perStartRum.js +16 -0
- package/src/boot/recorderApi.js +162 -1
- package/src/boot/rum.js +21 -2
- package/src/boot/rumPublicApi.js +59 -3
- package/src/boot/startRecording.js +94 -5
- package/src/domain/configuration.js +229 -1
- package/src/domain/replay/record/canvasAutoSnapshot.js +8 -0
- package/src/domain/replay/record/canvasCommandCapture.js +621 -0
- package/src/domain/replay/record/canvasCommandObserver.js +355 -0
- package/src/domain/replay/record/canvasCommandSerializeArgs.js +124 -0
- package/src/domain/replay/record/canvasContinuousScheduler.js +295 -0
- package/src/domain/replay/record/canvasEncodeBridge.js +299 -0
- package/src/domain/replay/record/canvasEncodeWorker.js +211 -0
- package/src/domain/replay/record/canvasFrameSignature.js +83 -0
- package/src/domain/replay/record/canvasMutationRecord.js +29 -0
- package/src/domain/replay/record/canvasObserver.js +279 -0
- package/src/domain/replay/record/canvasReplayFixtures.js +113 -0
- package/src/domain/replay/record/canvasSerializeArgs.js +129 -0
- package/src/domain/replay/record/mutationBatch.js +8 -2
- package/src/domain/replay/record/mutationObserver.js +449 -66
- package/src/domain/replay/record/observers.js +15 -3
- package/src/domain/replay/record/record.js +658 -2
- package/src/domain/replay/record/serializationUtils.js +75 -4
- package/src/domain/replay/record/serialize.js +217 -49
- package/src/domain/replay/segmentCollection/segment.js +65 -2
- package/src/domain/replay/segmentCollection/segmentCollection.js +46 -4
- package/src/domain/requestCollection.js +5 -1
- package/src/domain/rumEventsCollection/actions/clickChain.js +1 -1
- package/src/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -1
- package/src/domain/rumEventsCollection/error/trackReportError.js +3 -2
- package/src/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +51 -46
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +69 -10
- package/src/domain/rumEventsCollection/resource/resourceTrackerManager.js +264 -0
- package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +0 -1
- package/src/domain/rumSessionManager.js +2 -0
- package/src/domain/tracing/skywalkingTracer.js +1 -1
- package/src/types/sessionReplayConstants.js +2 -2
- package/types/index.d.ts +133 -1
|
@@ -12,19 +12,31 @@ var _privacy = require("./privacy");
|
|
|
12
12
|
var _serializationUtils = require("./serializationUtils");
|
|
13
13
|
var _serialize = require("./serialize");
|
|
14
14
|
var _mutationBatch = require("./mutationBatch");
|
|
15
|
+
var MUTATION_SERIALIZATION_SLICE_MS = 4;
|
|
16
|
+
var MUTATION_SERIALIZATION_EMIT_DELAY_MS = 16;
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* Buffers and aggregate mutations generated by a MutationObserver into MutationPayload
|
|
17
20
|
*/
|
|
18
|
-
function startMutationObserver(mutationCallback, configuration, shadowRootsController, target) {
|
|
21
|
+
function startMutationObserver(mutationCallback, configuration, shadowRootsController, target, mutationPerfCb) {
|
|
19
22
|
var MutationObserver = (0, _domMutationObservable.getMutationObserverConstructor)();
|
|
20
23
|
if (!MutationObserver) {
|
|
21
24
|
return {
|
|
22
25
|
stop: _browserCore.noop,
|
|
23
|
-
flush: _browserCore.noop
|
|
26
|
+
flush: _browserCore.noop,
|
|
27
|
+
reset: _browserCore.noop
|
|
24
28
|
};
|
|
25
29
|
}
|
|
30
|
+
var mutationTasksController = createMutationTasksController(mutationCallback, configuration, shadowRootsController);
|
|
26
31
|
var mutationBatch = (0, _mutationBatch.createMutationBatch)(function (mutations) {
|
|
27
|
-
|
|
32
|
+
var processStart = getCurrentTime();
|
|
33
|
+
processMutations(mutations.concat(observer.takeRecords()), mutationCallback, configuration, shadowRootsController, mutationTasksController);
|
|
34
|
+
if (mutationPerfCb) {
|
|
35
|
+
mutationPerfCb({
|
|
36
|
+
processMutationsCount: 1,
|
|
37
|
+
processMutationsDuration: getCurrentTime() - processStart
|
|
38
|
+
});
|
|
39
|
+
}
|
|
28
40
|
});
|
|
29
41
|
var observer = new MutationObserver((0, _browserCore.monitor)(mutationBatch.addMutations));
|
|
30
42
|
try {
|
|
@@ -41,56 +53,96 @@ function startMutationObserver(mutationCallback, configuration, shadowRootsContr
|
|
|
41
53
|
stop: function stop() {
|
|
42
54
|
observer.disconnect();
|
|
43
55
|
mutationBatch.stop();
|
|
56
|
+
mutationTasksController.stop();
|
|
44
57
|
},
|
|
45
58
|
flush: function flush() {
|
|
46
59
|
mutationBatch.flush();
|
|
60
|
+
mutationTasksController.flush();
|
|
61
|
+
},
|
|
62
|
+
reset: function reset() {
|
|
63
|
+
if (mutationBatch.reset) {
|
|
64
|
+
mutationBatch.reset();
|
|
65
|
+
}
|
|
66
|
+
mutationTasksController.reset();
|
|
47
67
|
}
|
|
48
68
|
};
|
|
49
69
|
}
|
|
50
|
-
function processMutations(mutations, mutationCallback, configuration, shadowRootsController) {
|
|
70
|
+
function processMutations(mutations, mutationCallback, configuration, shadowRootsController, mutationTasksController) {
|
|
51
71
|
var nodePrivacyLevelCache = new Map();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
var pendingRootTasksToRefresh = new Set();
|
|
73
|
+
var childListMutations = [];
|
|
74
|
+
var characterDataMutations = [];
|
|
75
|
+
var attributeMutations = [];
|
|
76
|
+
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
77
|
+
var mutation = mutations_1[_i];
|
|
78
|
+
if (mutation.type === 'childList') {
|
|
79
|
+
mutation.removedNodes.forEach(function (removedNode) {
|
|
80
|
+
traverseRemovedShadowDom(removedNode, shadowRootsController.removeShadowRoot);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
var target = mutation.target;
|
|
84
|
+
var pendingRootTask = mutationTasksController.findPendingRootTask(target);
|
|
85
|
+
if (!target.isConnected || !(0, _serializationUtils.nodeAndAncestorsHaveSerializedNode)(target) && !pendingRootTask || (0, _privacy.getNodePrivacyLevel)(target, configuration.defaultPrivacyLevel, nodePrivacyLevelCache) === _constants.NodePrivacyLevel.HIDDEN) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
switch (mutation.type) {
|
|
89
|
+
case 'childList':
|
|
90
|
+
childListMutations.push(mutation);
|
|
91
|
+
break;
|
|
92
|
+
case 'characterData':
|
|
93
|
+
characterDataMutations.push(mutation);
|
|
94
|
+
break;
|
|
95
|
+
case 'attributes':
|
|
96
|
+
attributeMutations.push(mutation);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
var _processChildListMutations = processChildListMutations(childListMutations, configuration, shadowRootsController, nodePrivacyLevelCache, mutationTasksController, pendingRootTasksToRefresh);
|
|
71
101
|
var removes = _processChildListMutations.removes;
|
|
72
|
-
// var hasBeenSerialized = _processChildListMutations.hasBeenSerialized
|
|
73
102
|
var serializedNodeIds = _processChildListMutations.serializedNodeIds;
|
|
74
103
|
function hasBeenSerialized(node) {
|
|
75
104
|
return (0, _serializationUtils.hasSerializedNode)(node) && serializedNodeIds.has((0, _serializationUtils.getSerializedNodeId)(node));
|
|
76
105
|
}
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
106
|
+
var pendingCharacterDataMutations = [];
|
|
107
|
+
for (var _a = 0, characterDataMutations_1 = characterDataMutations; _a < characterDataMutations_1.length; _a++) {
|
|
108
|
+
var characterDataMutation = characterDataMutations_1[_a];
|
|
109
|
+
var pendingCharacterDataRootTask = mutationTasksController.findPendingRootTask(characterDataMutation.target);
|
|
110
|
+
if (pendingCharacterDataRootTask) {
|
|
111
|
+
pendingRootTasksToRefresh.add(pendingCharacterDataRootTask);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!hasBeenSerialized(characterDataMutation.target)) {
|
|
115
|
+
pendingCharacterDataMutations.push(characterDataMutation);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var texts = processCharacterDataMutations(pendingCharacterDataMutations, configuration, nodePrivacyLevelCache);
|
|
119
|
+
var pendingAttributeMutations = [];
|
|
120
|
+
for (var _b = 0, attributeMutations_1 = attributeMutations; _b < attributeMutations_1.length; _b++) {
|
|
121
|
+
var attributeMutation = attributeMutations_1[_b];
|
|
122
|
+
var pendingAttributeRootTask = mutationTasksController.findPendingRootTask(attributeMutation.target);
|
|
123
|
+
if (pendingAttributeRootTask) {
|
|
124
|
+
pendingRootTasksToRefresh.add(pendingAttributeRootTask);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!hasBeenSerialized(attributeMutation.target)) {
|
|
128
|
+
pendingAttributeMutations.push(attributeMutation);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var attributes = processAttributesMutations(pendingAttributeMutations, configuration, nodePrivacyLevelCache);
|
|
132
|
+
pendingRootTasksToRefresh.forEach(function (task) {
|
|
133
|
+
mutationTasksController.refreshPendingRootTask(task);
|
|
134
|
+
});
|
|
135
|
+
if (!texts.length && !attributes.length && !removes.length) {
|
|
84
136
|
return;
|
|
85
137
|
}
|
|
86
138
|
mutationCallback({
|
|
87
|
-
adds:
|
|
139
|
+
adds: [],
|
|
88
140
|
removes: removes,
|
|
89
141
|
texts: texts,
|
|
90
142
|
attributes: attributes
|
|
91
143
|
});
|
|
92
144
|
}
|
|
93
|
-
function processChildListMutations(mutations, configuration, shadowRootsController, nodePrivacyLevelCache) {
|
|
145
|
+
function processChildListMutations(mutations, configuration, shadowRootsController, nodePrivacyLevelCache, mutationTasksController, pendingRootTasksToRefresh) {
|
|
94
146
|
// First, we iterate over mutations to collect:
|
|
95
147
|
//
|
|
96
148
|
// * nodes that have been added in the document and not removed by a subsequent mutation
|
|
@@ -133,9 +185,13 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
133
185
|
// Then, we iterate over our sorted node sets to emit mutations. We collect the newly serialized
|
|
134
186
|
// node ids in a set to be able to skip subsequent related mutations.
|
|
135
187
|
var serializedNodeIds = new Set();
|
|
136
|
-
var addedNodeMutations = [];
|
|
137
188
|
for (var _a = 0, sortedAddedAndMovedNodes_1 = sortedAddedAndMovedNodes; _a < sortedAddedAndMovedNodes_1.length; _a++) {
|
|
138
189
|
var node = sortedAddedAndMovedNodes_1[_a];
|
|
190
|
+
var pendingRootTask = mutationTasksController.findPendingRootTask(node);
|
|
191
|
+
if (pendingRootTask) {
|
|
192
|
+
pendingRootTasksToRefresh.add(pendingRootTask);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
139
195
|
if (hasBeenSerialized(node)) {
|
|
140
196
|
continue;
|
|
141
197
|
}
|
|
@@ -143,7 +199,7 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
143
199
|
if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
|
|
144
200
|
continue;
|
|
145
201
|
}
|
|
146
|
-
|
|
202
|
+
mutationTasksController.addPendingRootTask(node, {
|
|
147
203
|
serializedNodeIds: serializedNodeIds,
|
|
148
204
|
parentNodePrivacyLevel: parentNodePrivacyLevel,
|
|
149
205
|
serializationContext: {
|
|
@@ -152,19 +208,16 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
152
208
|
},
|
|
153
209
|
configuration: configuration
|
|
154
210
|
});
|
|
155
|
-
if (!serializedNode) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
var parentNode = (0, _browserCore.getParentNode)(node);
|
|
159
|
-
addedNodeMutations.push({
|
|
160
|
-
nextId: getNextSibling(node),
|
|
161
|
-
parentId: (0, _serializationUtils.getSerializedNodeId)(parentNode),
|
|
162
|
-
node: serializedNode
|
|
163
|
-
});
|
|
164
211
|
}
|
|
165
212
|
// Finally, we emit remove mutations.
|
|
166
213
|
var removedNodeMutations = [];
|
|
167
214
|
removedNodes.forEach(function (parent, node) {
|
|
215
|
+
var pendingRootTask = mutationTasksController.findPendingRootTask(node);
|
|
216
|
+
if (pendingRootTask) {
|
|
217
|
+
pendingRootTasksToRefresh["delete"](pendingRootTask);
|
|
218
|
+
mutationTasksController.handlePendingRootRemoval(pendingRootTask, node);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
168
221
|
if ((0, _serializationUtils.hasSerializedNode)(node)) {
|
|
169
222
|
removedNodeMutations.push({
|
|
170
223
|
parentId: (0, _serializationUtils.getSerializedNodeId)(parent),
|
|
@@ -173,7 +226,6 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
173
226
|
}
|
|
174
227
|
});
|
|
175
228
|
return {
|
|
176
|
-
adds: addedNodeMutations,
|
|
177
229
|
removes: removedNodeMutations,
|
|
178
230
|
serializedNodeIds: serializedNodeIds,
|
|
179
231
|
hasBeenSerialized: hasBeenSerialized
|
|
@@ -181,16 +233,6 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
181
233
|
function hasBeenSerialized(node) {
|
|
182
234
|
return (0, _serializationUtils.hasSerializedNode)(node) && serializedNodeIds.has((0, _serializationUtils.getSerializedNodeId)(node));
|
|
183
235
|
}
|
|
184
|
-
function getNextSibling(node) {
|
|
185
|
-
var nextSibling = node.nextSibling;
|
|
186
|
-
while (nextSibling) {
|
|
187
|
-
if ((0, _serializationUtils.hasSerializedNode)(nextSibling)) {
|
|
188
|
-
return (0, _serializationUtils.getSerializedNodeId)(nextSibling);
|
|
189
|
-
}
|
|
190
|
-
nextSibling = nextSibling.nextSibling;
|
|
191
|
-
}
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
236
|
}
|
|
195
237
|
function processCharacterDataMutations(mutations, configuration, nodePrivacyLevelCache) {
|
|
196
238
|
var textMutations = [];
|
|
@@ -293,6 +335,278 @@ function sortAddedAndMovedNodes(nodes) {
|
|
|
293
335
|
return 0;
|
|
294
336
|
});
|
|
295
337
|
}
|
|
338
|
+
function createMutationTasksController(mutationCallback, configuration, shadowRootsController) {
|
|
339
|
+
var generation = 0;
|
|
340
|
+
var nextTaskSequence = 0;
|
|
341
|
+
var nextEmitSequence = 0;
|
|
342
|
+
var pendingRootTasks = [];
|
|
343
|
+
var pendingRootTaskByRootNode = new WeakMap();
|
|
344
|
+
var pendingRootTaskBySequence = new Map();
|
|
345
|
+
var scheduledFlush = undefined;
|
|
346
|
+
var scheduledEmit = undefined;
|
|
347
|
+
var stopped = false;
|
|
348
|
+
var completedRootTasks = [];
|
|
349
|
+
return {
|
|
350
|
+
addPendingRootTask: addPendingRootTask,
|
|
351
|
+
findPendingRootTask: findPendingRootTask,
|
|
352
|
+
refreshPendingRootTask: refreshPendingRootTask,
|
|
353
|
+
handlePendingRootRemoval: handlePendingRootRemoval,
|
|
354
|
+
flush: function flush() {
|
|
355
|
+
processPendingRootTasks(true);
|
|
356
|
+
},
|
|
357
|
+
reset: function reset() {
|
|
358
|
+
generation += 1;
|
|
359
|
+
nextTaskSequence = 0;
|
|
360
|
+
nextEmitSequence = 0;
|
|
361
|
+
clearScheduledFlush();
|
|
362
|
+
clearScheduledEmit();
|
|
363
|
+
pendingRootTasks = [];
|
|
364
|
+
completedRootTasks = [];
|
|
365
|
+
pendingRootTaskByRootNode = new WeakMap();
|
|
366
|
+
pendingRootTaskBySequence = new Map();
|
|
367
|
+
},
|
|
368
|
+
stop: function stop() {
|
|
369
|
+
stopped = true;
|
|
370
|
+
clearScheduledFlush();
|
|
371
|
+
clearScheduledEmit();
|
|
372
|
+
pendingRootTasks = [];
|
|
373
|
+
completedRootTasks = [];
|
|
374
|
+
pendingRootTaskByRootNode = new WeakMap();
|
|
375
|
+
pendingRootTaskBySequence = new Map();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
function addPendingRootTask(node, serializationOptions) {
|
|
379
|
+
if (findPendingRootTask((0, _browserCore.getParentNode)(node))) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
var serializerTask = (0, _serialize.createMutationSerializerTask)(node, serializationOptions);
|
|
383
|
+
if (!serializerTask) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
var task = {
|
|
387
|
+
generation: generation,
|
|
388
|
+
sequence: nextTaskSequence++,
|
|
389
|
+
rootNode: node,
|
|
390
|
+
parentId: (0, _serializationUtils.getSerializedNodeId)((0, _browserCore.getParentNode)(node)),
|
|
391
|
+
nextId: getNextSibling(node),
|
|
392
|
+
serializerTask: serializerTask
|
|
393
|
+
};
|
|
394
|
+
pendingRootTasks.push(task);
|
|
395
|
+
pendingRootTaskByRootNode.set(node, task);
|
|
396
|
+
pendingRootTaskBySequence.set(task.sequence, task);
|
|
397
|
+
schedulePendingRootTasks();
|
|
398
|
+
}
|
|
399
|
+
function findPendingRootTask(node) {
|
|
400
|
+
var current = node;
|
|
401
|
+
while (current) {
|
|
402
|
+
var task = pendingRootTaskByRootNode.get(current);
|
|
403
|
+
if (task && task.generation === generation) {
|
|
404
|
+
return task;
|
|
405
|
+
}
|
|
406
|
+
current = (0, _browserCore.getParentNode)(current);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function refreshPendingRootTask(task) {
|
|
410
|
+
if (!task || task.generation !== generation) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (!task.rootNode.isConnected) {
|
|
414
|
+
cancelPendingRootTask(task);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
var parentNode = (0, _browserCore.getParentNode)(task.rootNode);
|
|
418
|
+
var parentNodePrivacyLevel = (0, _privacy.getNodePrivacyLevel)(parentNode, configuration.defaultPrivacyLevel);
|
|
419
|
+
if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
|
|
420
|
+
cancelPendingRootTask(task);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
var serializerTask = (0, _serialize.createMutationSerializerTask)(task.rootNode, {
|
|
424
|
+
parentNodePrivacyLevel: parentNodePrivacyLevel,
|
|
425
|
+
serializationContext: {
|
|
426
|
+
status: _serialize.SerializationContextStatus.MUTATION,
|
|
427
|
+
shadowRootsController: shadowRootsController
|
|
428
|
+
},
|
|
429
|
+
configuration: configuration
|
|
430
|
+
});
|
|
431
|
+
if (!serializerTask) {
|
|
432
|
+
cancelPendingRootTask(task);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
removeCompletedRootTask(task);
|
|
436
|
+
task.parentId = (0, _serializationUtils.getSerializedNodeId)(parentNode);
|
|
437
|
+
task.nextId = getNextSibling(task.rootNode);
|
|
438
|
+
task.serializerTask = serializerTask;
|
|
439
|
+
task.isCompleted = false;
|
|
440
|
+
schedulePendingRootTasks();
|
|
441
|
+
}
|
|
442
|
+
function handlePendingRootRemoval(task, node) {
|
|
443
|
+
if (!task || task.generation !== generation) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (node === task.rootNode || !task.rootNode.isConnected) {
|
|
447
|
+
cancelPendingRootTask(task);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
refreshPendingRootTask(task);
|
|
451
|
+
}
|
|
452
|
+
function cancelPendingRootTask(task) {
|
|
453
|
+
pendingRootTaskByRootNode["delete"](task.rootNode);
|
|
454
|
+
pendingRootTaskBySequence["delete"](task.sequence);
|
|
455
|
+
removeCompletedRootTask(task);
|
|
456
|
+
pendingRootTasks = pendingRootTasks.filter(function (pendingRootTask) {
|
|
457
|
+
return pendingRootTask !== task;
|
|
458
|
+
});
|
|
459
|
+
advanceEmitSequencePastGaps();
|
|
460
|
+
}
|
|
461
|
+
function schedulePendingRootTasks() {
|
|
462
|
+
if (stopped || scheduledFlush || !pendingRootTasks.length) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
scheduledFlush = setTimeout(function () {
|
|
466
|
+
scheduledFlush = undefined;
|
|
467
|
+
processPendingRootTasks(false);
|
|
468
|
+
}, 0);
|
|
469
|
+
}
|
|
470
|
+
function processPendingRootTasks(forceDrain) {
|
|
471
|
+
clearScheduledFlush();
|
|
472
|
+
if (stopped) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (!pendingRootTasks.length) {
|
|
476
|
+
if (forceDrain && completedRootTasks.length) {
|
|
477
|
+
emitCompletedRootTasks();
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
var deadline = forceDrain ? Infinity : getCurrentTime() + MUTATION_SERIALIZATION_SLICE_MS;
|
|
482
|
+
while (pendingRootTasks.length) {
|
|
483
|
+
var task = pendingRootTasks.shift();
|
|
484
|
+
if (task.generation !== generation) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
var completed = task.serializerTask.advance(deadline);
|
|
488
|
+
if (task.generation !== generation) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (completed) {
|
|
492
|
+
task.isCompleted = true;
|
|
493
|
+
completedRootTasks.push(task);
|
|
494
|
+
} else {
|
|
495
|
+
pendingRootTasks.push(task);
|
|
496
|
+
if (!forceDrain && getCurrentTime() >= deadline) {
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (completedRootTasks.length) {
|
|
502
|
+
if (forceDrain || !pendingRootTasks.length) {
|
|
503
|
+
emitCompletedRootTasks();
|
|
504
|
+
} else {
|
|
505
|
+
scheduleCompletedRootTasksEmit();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (pendingRootTasks.length) {
|
|
509
|
+
schedulePendingRootTasks();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function clearScheduledFlush() {
|
|
513
|
+
if (scheduledFlush) {
|
|
514
|
+
clearTimeout(scheduledFlush);
|
|
515
|
+
scheduledFlush = undefined;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function scheduleCompletedRootTasksEmit() {
|
|
519
|
+
if (stopped || scheduledEmit || !completedRootTasks.length) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
scheduledEmit = setTimeout(function () {
|
|
523
|
+
scheduledEmit = undefined;
|
|
524
|
+
emitCompletedRootTasks();
|
|
525
|
+
}, MUTATION_SERIALIZATION_EMIT_DELAY_MS);
|
|
526
|
+
}
|
|
527
|
+
function emitCompletedRootTasks() {
|
|
528
|
+
clearScheduledEmit();
|
|
529
|
+
if (!completedRootTasks.length) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
var completedTasksBySequence = new Map();
|
|
533
|
+
completedRootTasks.forEach(function (task) {
|
|
534
|
+
completedTasksBySequence.set(task.sequence, task);
|
|
535
|
+
});
|
|
536
|
+
var readyTasks = [];
|
|
537
|
+
advanceEmitSequencePastGaps();
|
|
538
|
+
while (nextEmitSequence < nextTaskSequence) {
|
|
539
|
+
var nextTask = completedTasksBySequence.get(nextEmitSequence);
|
|
540
|
+
if (!nextTask) {
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
readyTasks.push(nextTask);
|
|
544
|
+
completedTasksBySequence["delete"](nextEmitSequence);
|
|
545
|
+
nextEmitSequence += 1;
|
|
546
|
+
}
|
|
547
|
+
if (!readyTasks.length) {
|
|
548
|
+
if (pendingRootTasks.length) {
|
|
549
|
+
schedulePendingRootTasks();
|
|
550
|
+
} else if (completedRootTasks.length) {
|
|
551
|
+
scheduleCompletedRootTasksEmit();
|
|
552
|
+
}
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
var adds = readyTasks.map(function (task) {
|
|
556
|
+
pendingRootTaskByRootNode["delete"](task.rootNode);
|
|
557
|
+
pendingRootTaskBySequence["delete"](task.sequence);
|
|
558
|
+
return {
|
|
559
|
+
nextId: task.nextId,
|
|
560
|
+
parentId: task.parentId,
|
|
561
|
+
node: task.serializerTask.serializedNode
|
|
562
|
+
};
|
|
563
|
+
});
|
|
564
|
+
completedRootTasks = completedRootTasks.filter(function (task) {
|
|
565
|
+
return readyTasks.indexOf(task) === -1;
|
|
566
|
+
});
|
|
567
|
+
mutationCallback({
|
|
568
|
+
adds: adds,
|
|
569
|
+
removes: [],
|
|
570
|
+
texts: [],
|
|
571
|
+
attributes: []
|
|
572
|
+
});
|
|
573
|
+
if (completedRootTasks.length) {
|
|
574
|
+
scheduleCompletedRootTasksEmit();
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function removeCompletedRootTask(task) {
|
|
578
|
+
completedRootTasks = completedRootTasks.filter(function (completedTask) {
|
|
579
|
+
return completedTask !== task;
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function clearScheduledEmit() {
|
|
583
|
+
if (scheduledEmit) {
|
|
584
|
+
clearTimeout(scheduledEmit);
|
|
585
|
+
scheduledEmit = undefined;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function advanceEmitSequencePastGaps() {
|
|
589
|
+
while (nextEmitSequence < nextTaskSequence && !pendingRootTaskBySequence.has(nextEmitSequence)) {
|
|
590
|
+
nextEmitSequence += 1;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function getNextSibling(node) {
|
|
594
|
+
var nextSibling = node.nextSibling;
|
|
595
|
+
while (nextSibling) {
|
|
596
|
+
if ((0, _serializationUtils.hasSerializedNode)(nextSibling)) {
|
|
597
|
+
return (0, _serializationUtils.getSerializedNodeId)(nextSibling);
|
|
598
|
+
}
|
|
599
|
+
nextSibling = nextSibling.nextSibling;
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function getCurrentTime() {
|
|
605
|
+
if (typeof performance !== 'undefined' && performance.now) {
|
|
606
|
+
return performance.now();
|
|
607
|
+
}
|
|
608
|
+
return Date.now();
|
|
609
|
+
}
|
|
296
610
|
function traverseRemovedShadowDom(removedNode, shadowDomRemovedCallback) {
|
|
297
611
|
if ((0, _browserCore.isNodeShadowHost)(removedNode)) {
|
|
298
612
|
shadowDomRemovedCallback(removedNode.shadowRoot);
|