@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { timeStampNow, getScrollX, getScrollY } from '@cloudcare/browser-core';
|
|
1
|
+
import { timeStampNow, getScrollX, getScrollY, assign } from '@cloudcare/browser-core';
|
|
2
2
|
import { getViewportDimension } from '../../initViewportObservable';
|
|
3
3
|
import { RecordType, IncrementalSource } from '../../../types';
|
|
4
4
|
import { serializeDocument, SerializationContextStatus } from './serialize';
|
|
@@ -7,6 +7,19 @@ import { getVisualViewport } from './viewports';
|
|
|
7
7
|
import { assembleIncrementalSnapshot } from './utils';
|
|
8
8
|
import { createElementsScrollPositions } from './elementsScrollPositions';
|
|
9
9
|
import { initShadowRootsController } from './shadowRootsController';
|
|
10
|
+
import { createCanvasObserver } from './canvasObserver';
|
|
11
|
+
import { startCanvasCommandCapture } from './canvasCommandObserver';
|
|
12
|
+
import { getSerializedCanvasNodes, getSerializedNodeId as _getSerializedNodeId } from './serializationUtils';
|
|
13
|
+
import { startContinuousCanvasSnapshotLoop } from './canvasContinuousScheduler';
|
|
14
|
+
var MUTATION_EMIT_DELAY_MS = 16;
|
|
15
|
+
var MAX_MUTATION_EMIT_APPROX_BYTES = 200000;
|
|
16
|
+
var CANVAS_DEBUG_HISTORY_LIMIT = 200;
|
|
17
|
+
function shouldUseCommandCapture(configuration) {
|
|
18
|
+
return configuration.replayCanvasEnabled && configuration.replayCanvasMode === 'auto' && configuration.replayCanvasSampling === 'all';
|
|
19
|
+
}
|
|
20
|
+
function shouldUseContinuousCanvasSnapshot(configuration) {
|
|
21
|
+
return configuration.replayCanvasEnabled && configuration.replayCanvasMode === 'auto' && configuration.replayCanvasSampling !== 'all';
|
|
22
|
+
}
|
|
10
23
|
export function record(options) {
|
|
11
24
|
var emit = options.emit;
|
|
12
25
|
// runtime checks for user options
|
|
@@ -14,9 +27,58 @@ export function record(options) {
|
|
|
14
27
|
throw new Error('emit function is required');
|
|
15
28
|
}
|
|
16
29
|
var elementsScrollPositions = createElementsScrollPositions();
|
|
30
|
+
var replayPerformanceStats = createReplayPerformanceStats();
|
|
31
|
+
var pendingMutationPayload;
|
|
32
|
+
var pendingMutationTimeout;
|
|
33
|
+
var updateReplayPerformanceStats = function updateReplayPerformanceStats(delta) {
|
|
34
|
+
accumulateReplayPerformanceStats(replayPerformanceStats, delta);
|
|
35
|
+
};
|
|
17
36
|
var mutationCb = function mutationCb(mutation) {
|
|
18
|
-
|
|
37
|
+
if (pendingMutationPayload && shouldFlushPendingMutationPayloadBeforeMerge(pendingMutationPayload, mutation)) {
|
|
38
|
+
flushPendingMutations();
|
|
39
|
+
}
|
|
40
|
+
pendingMutationPayload = mergeMutationPayloads(pendingMutationPayload, mutation);
|
|
41
|
+
scheduleMutationEmit();
|
|
19
42
|
};
|
|
43
|
+
function scheduleMutationEmit() {
|
|
44
|
+
if (pendingMutationTimeout) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
pendingMutationTimeout = setTimeout(function () {
|
|
48
|
+
pendingMutationTimeout = undefined;
|
|
49
|
+
flushPendingMutations();
|
|
50
|
+
}, MUTATION_EMIT_DELAY_MS);
|
|
51
|
+
}
|
|
52
|
+
function flushPendingMutations() {
|
|
53
|
+
if (pendingMutationTimeout) {
|
|
54
|
+
clearTimeout(pendingMutationTimeout);
|
|
55
|
+
pendingMutationTimeout = undefined;
|
|
56
|
+
}
|
|
57
|
+
if (!pendingMutationPayload) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var mutationPayloads = splitPendingMutationPayloadForEmit(pendingMutationPayload);
|
|
61
|
+
pendingMutationPayload = undefined;
|
|
62
|
+
updateReplayPerformanceStats(mutationPayloads.reduce(function (stats, mutationPayload) {
|
|
63
|
+
stats.mutationCallbackCount += 1;
|
|
64
|
+
stats.mutationRecordCount += countMutationPayloadRecords(mutationPayload);
|
|
65
|
+
stats.mutationAddCount += mutationPayload.adds.length;
|
|
66
|
+
stats.mutationRemoveCount += mutationPayload.removes.length;
|
|
67
|
+
stats.mutationTextCount += mutationPayload.texts.length;
|
|
68
|
+
stats.mutationAttributeCount += mutationPayload.attributes.length;
|
|
69
|
+
return stats;
|
|
70
|
+
}, {
|
|
71
|
+
mutationCallbackCount: 0,
|
|
72
|
+
mutationRecordCount: 0,
|
|
73
|
+
mutationAddCount: 0,
|
|
74
|
+
mutationRemoveCount: 0,
|
|
75
|
+
mutationTextCount: 0,
|
|
76
|
+
mutationAttributeCount: 0
|
|
77
|
+
}));
|
|
78
|
+
mutationPayloads.forEach(function (mutationPayload) {
|
|
79
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.Mutation, mutationPayload));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
20
82
|
var inputCb = function inputCb(s) {
|
|
21
83
|
emit(assembleIncrementalSnapshot(IncrementalSource.Input, s));
|
|
22
84
|
};
|
|
@@ -24,6 +86,73 @@ export function record(options) {
|
|
|
24
86
|
mutationCb: mutationCb,
|
|
25
87
|
inputCb: inputCb
|
|
26
88
|
});
|
|
89
|
+
var lastAutoCanvasSnapshotResult;
|
|
90
|
+
var autoCanvasSnapshotDebugHistoryForDebug = [];
|
|
91
|
+
var lastCanvasMutationForDebug;
|
|
92
|
+
var canvasMutationHistoryForDebug = [];
|
|
93
|
+
var shouldUseCanvasCommandCapture = shouldUseCommandCapture(options.configuration);
|
|
94
|
+
var canvasObserver = (options.createCanvasObserver || createCanvasObserver)({
|
|
95
|
+
configuration: options.configuration,
|
|
96
|
+
emit: emit,
|
|
97
|
+
onMutationDebug: function onMutationDebug(result) {
|
|
98
|
+
lastCanvasMutationForDebug = cloneCanvasMutationDebugResult(result);
|
|
99
|
+
pushCanvasDebugHistoryEntry(canvasMutationHistoryForDebug, lastCanvasMutationForDebug);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
var startCanvasSnapshotLoop = options.startContinuousCanvasSnapshotLoop || startContinuousCanvasSnapshotLoop;
|
|
103
|
+
var canvasSnapshotLoop = shouldUseCanvasCommandCapture ? {
|
|
104
|
+
stop: function stop() {},
|
|
105
|
+
reset: function reset() {}
|
|
106
|
+
} : startCanvasSnapshotLoop({
|
|
107
|
+
configuration: options.configuration,
|
|
108
|
+
getCanvases: function getCanvases() {
|
|
109
|
+
return getSerializedCanvasNodes();
|
|
110
|
+
},
|
|
111
|
+
getSerializedNodeId: function getSerializedNodeId(canvas) {
|
|
112
|
+
return _getSerializedNodeId(canvas);
|
|
113
|
+
},
|
|
114
|
+
onDebug: function onDebug(result) {
|
|
115
|
+
var keepSessionAliveTriggered = false;
|
|
116
|
+
if (shouldKeepSessionAliveAfterAutoCanvasSnapshot(result) && options.sessionManager && options.sessionManager.keepSessionAlive) {
|
|
117
|
+
options.sessionManager.keepSessionAlive();
|
|
118
|
+
keepSessionAliveTriggered = true;
|
|
119
|
+
}
|
|
120
|
+
lastAutoCanvasSnapshotResult = cloneAutoCanvasSnapshotDebugResult(result, keepSessionAliveTriggered);
|
|
121
|
+
pushCanvasDebugHistoryEntry(autoCanvasSnapshotDebugHistoryForDebug, lastAutoCanvasSnapshotResult);
|
|
122
|
+
},
|
|
123
|
+
snapshotCanvas: function snapshotCanvas(canvas) {
|
|
124
|
+
return canvasObserver.snapshot(canvas, {
|
|
125
|
+
trigger: 'auto',
|
|
126
|
+
scheduler: 'continuous_snapshot'
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
var canvasCommandCapture = (options.startCanvasCommandCapture || startCanvasCommandCapture)({
|
|
131
|
+
configuration: options.configuration,
|
|
132
|
+
emit: emit,
|
|
133
|
+
snapshotCanvas: function snapshotCanvas(canvas, snapshotOptions) {
|
|
134
|
+
return canvasObserver.snapshot(canvas, snapshotOptions);
|
|
135
|
+
},
|
|
136
|
+
getCanvases: function getCanvases() {
|
|
137
|
+
return getSerializedCanvasNodes();
|
|
138
|
+
},
|
|
139
|
+
getSerializedNodeId: function getSerializedNodeId(canvas) {
|
|
140
|
+
return _getSerializedNodeId(canvas);
|
|
141
|
+
},
|
|
142
|
+
onDebug: function onDebug(result) {
|
|
143
|
+
var keepSessionAliveTriggered = false;
|
|
144
|
+
if (shouldKeepSessionAliveAfterAutoCanvasSnapshot(result) && options.sessionManager && options.sessionManager.keepSessionAlive) {
|
|
145
|
+
options.sessionManager.keepSessionAlive();
|
|
146
|
+
keepSessionAliveTriggered = true;
|
|
147
|
+
}
|
|
148
|
+
lastAutoCanvasSnapshotResult = cloneAutoCanvasSnapshotDebugResult(result, keepSessionAliveTriggered);
|
|
149
|
+
pushCanvasDebugHistoryEntry(autoCanvasSnapshotDebugHistoryForDebug, lastAutoCanvasSnapshotResult);
|
|
150
|
+
},
|
|
151
|
+
onMutationDebug: function onMutationDebug(result) {
|
|
152
|
+
lastCanvasMutationForDebug = cloneCanvasMutationDebugResult(result);
|
|
153
|
+
pushCanvasDebugHistoryEntry(canvasMutationHistoryForDebug, lastCanvasMutationForDebug);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
27
156
|
var takeFullSnapshot = function takeFullSnapshot(timestamp, serializationContext) {
|
|
28
157
|
if (typeof timestamp === 'undefined') {
|
|
29
158
|
timestamp = timeStampNow();
|
|
@@ -74,6 +203,9 @@ export function record(options) {
|
|
|
74
203
|
}
|
|
75
204
|
};
|
|
76
205
|
takeFullSnapshot();
|
|
206
|
+
if (canvasCommandCapture.scanExistingCanvases) {
|
|
207
|
+
canvasCommandCapture.scanExistingCanvases();
|
|
208
|
+
}
|
|
77
209
|
var _initObservers = initObservers({
|
|
78
210
|
lifeCycle: options.lifeCycle,
|
|
79
211
|
configuration: options.configuration,
|
|
@@ -91,6 +223,7 @@ export function record(options) {
|
|
|
91
223
|
}));
|
|
92
224
|
},
|
|
93
225
|
mutationCb: mutationCb,
|
|
226
|
+
mutationPerfCb: updateReplayPerformanceStats,
|
|
94
227
|
scrollCb: function scrollCb(p) {
|
|
95
228
|
emit(assembleIncrementalSnapshot(IncrementalSource.Scroll, p));
|
|
96
229
|
},
|
|
@@ -121,25 +254,369 @@ export function record(options) {
|
|
|
121
254
|
});
|
|
122
255
|
var stopObservers = _initObservers.stop;
|
|
123
256
|
var flushMutationsFromObservers = _initObservers.flush;
|
|
257
|
+
var resetMutationsFromObservers = _initObservers.reset || function () {};
|
|
124
258
|
function flushMutations() {
|
|
125
259
|
shadowRootsController.flush();
|
|
126
260
|
flushMutationsFromObservers();
|
|
261
|
+
flushPendingMutations();
|
|
127
262
|
}
|
|
128
263
|
return {
|
|
129
264
|
stop: function stop() {
|
|
265
|
+
flushPendingMutations();
|
|
130
266
|
shadowRootsController.stop();
|
|
267
|
+
canvasCommandCapture.stop();
|
|
268
|
+
canvasObserver.stop();
|
|
269
|
+
stopCanvasSnapshots(canvasSnapshotLoop);
|
|
131
270
|
stopObservers();
|
|
132
271
|
},
|
|
272
|
+
snapshotCanvas: function snapshotCanvas(canvas, snapshotOptions) {
|
|
273
|
+
return canvasObserver.snapshot(canvas, assign({
|
|
274
|
+
trigger: 'manual'
|
|
275
|
+
}, snapshotOptions));
|
|
276
|
+
},
|
|
277
|
+
getSerializedNodeIdForDebug: function getSerializedNodeIdForDebug(node) {
|
|
278
|
+
return _getSerializedNodeId(node);
|
|
279
|
+
},
|
|
280
|
+
getLastAutoCanvasSnapshotResultForDebug: function getLastAutoCanvasSnapshotResultForDebug() {
|
|
281
|
+
return cloneAutoCanvasSnapshotDebugResult(lastAutoCanvasSnapshotResult);
|
|
282
|
+
},
|
|
283
|
+
getAutoCanvasSnapshotDebugHistoryForDebug: function getAutoCanvasSnapshotDebugHistoryForDebug() {
|
|
284
|
+
return autoCanvasSnapshotDebugHistoryForDebug.map(cloneAutoCanvasSnapshotDebugResult);
|
|
285
|
+
},
|
|
286
|
+
getLastCanvasMutationForDebug: function getLastCanvasMutationForDebug() {
|
|
287
|
+
return cloneCanvasMutationDebugResult(lastCanvasMutationForDebug);
|
|
288
|
+
},
|
|
289
|
+
getCanvasMutationHistoryForDebug: function getCanvasMutationHistoryForDebug() {
|
|
290
|
+
return canvasMutationHistoryForDebug.map(cloneCanvasMutationDebugResult);
|
|
291
|
+
},
|
|
292
|
+
getReplayPerformanceForDebug: function getReplayPerformanceForDebug() {
|
|
293
|
+
return cloneReplayPerformanceStats(replayPerformanceStats);
|
|
294
|
+
},
|
|
133
295
|
takeSubsequentFullSnapshot: function takeSubsequentFullSnapshot(timestamp) {
|
|
134
296
|
flushMutations();
|
|
297
|
+
resetMutationsFromObservers();
|
|
298
|
+
if (canvasObserver.reset) {
|
|
299
|
+
canvasObserver.reset();
|
|
300
|
+
}
|
|
301
|
+
if (canvasCommandCapture.reset) {
|
|
302
|
+
canvasCommandCapture.reset();
|
|
303
|
+
}
|
|
304
|
+
resetCanvasSnapshots(canvasSnapshotLoop);
|
|
135
305
|
takeFullSnapshot(timestamp, {
|
|
136
306
|
shadowRootsController: shadowRootsController,
|
|
137
307
|
status: SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT,
|
|
138
308
|
elementsScrollPositions: elementsScrollPositions
|
|
139
309
|
});
|
|
310
|
+
if (canvasCommandCapture.scanExistingCanvases) {
|
|
311
|
+
canvasCommandCapture.scanExistingCanvases();
|
|
312
|
+
}
|
|
140
313
|
},
|
|
141
314
|
flushMutations: flushMutations,
|
|
142
315
|
shadowRootsController: shadowRootsController
|
|
143
316
|
};
|
|
144
317
|
}
|
|
318
|
+
function materializeMutationPayload(pendingMutationPayload) {
|
|
319
|
+
return {
|
|
320
|
+
adds: pendingMutationPayload.adds,
|
|
321
|
+
removes: pendingMutationPayload.removes,
|
|
322
|
+
texts: pendingMutationPayload.texts,
|
|
323
|
+
attributes: pendingMutationPayload.attributes
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function createEmptyMutationPayload() {
|
|
327
|
+
return {
|
|
328
|
+
adds: [],
|
|
329
|
+
removes: [],
|
|
330
|
+
texts: [],
|
|
331
|
+
attributes: [],
|
|
332
|
+
approxBytes: 0,
|
|
333
|
+
addsApproxBytes: 0,
|
|
334
|
+
removesApproxBytes: 0,
|
|
335
|
+
textsApproxBytes: 0,
|
|
336
|
+
attributesApproxBytes: 0,
|
|
337
|
+
addApproxBytes: [],
|
|
338
|
+
removesByKey: new Map(),
|
|
339
|
+
removeApproxBytesByKey: new Map(),
|
|
340
|
+
textsById: new Map(),
|
|
341
|
+
textApproxBytesById: new Map(),
|
|
342
|
+
attributesById: new Map(),
|
|
343
|
+
attributeApproxBytesById: new Map()
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function mergeMutationPayloads(target, source) {
|
|
347
|
+
var merged = target || createEmptyMutationPayload();
|
|
348
|
+
mergeAddMutations(merged, source.adds);
|
|
349
|
+
mergeRemoveMutations(merged, source.removes);
|
|
350
|
+
mergeTextMutations(merged, source.texts);
|
|
351
|
+
mergeAttributeMutations(merged, source.attributes);
|
|
352
|
+
updateMutationPayloadApproxBytes(merged);
|
|
353
|
+
return merged;
|
|
354
|
+
}
|
|
355
|
+
function mergeAddMutations(merged, sourceAdds) {
|
|
356
|
+
if (!sourceAdds.length) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
sourceAdds.forEach(function (add) {
|
|
360
|
+
var addApproxBytes = estimateMutationEntryBytes(add);
|
|
361
|
+
merged.adds.push(add);
|
|
362
|
+
merged.addApproxBytes.push(addApproxBytes);
|
|
363
|
+
merged.addsApproxBytes += addApproxBytes;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function mergeRemoveMutations(merged, sourceRemoves) {
|
|
367
|
+
if (!sourceRemoves.length) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
sourceRemoves.forEach(function (remove) {
|
|
371
|
+
var key = getRemoveMutationKey(remove);
|
|
372
|
+
if (!merged.removesByKey.has(key)) {
|
|
373
|
+
merged.removes.push(remove);
|
|
374
|
+
var removeApproxBytes = estimateMutationEntryBytes(remove);
|
|
375
|
+
merged.removeApproxBytesByKey.set(key, removeApproxBytes);
|
|
376
|
+
merged.removesApproxBytes += removeApproxBytes;
|
|
377
|
+
}
|
|
378
|
+
merged.removesByKey.set(key, remove);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function mergeTextMutations(merged, sourceTexts) {
|
|
382
|
+
if (!sourceTexts.length) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
sourceTexts.forEach(function (textMutation) {
|
|
386
|
+
var existingTextMutation = merged.textsById.get(textMutation.id);
|
|
387
|
+
if (existingTextMutation) {
|
|
388
|
+
merged.textsApproxBytes -= merged.textApproxBytesById.get(textMutation.id) || 0;
|
|
389
|
+
existingTextMutation.value = textMutation.value;
|
|
390
|
+
var nextTextApproxBytes = estimateMutationEntryBytes(existingTextMutation);
|
|
391
|
+
merged.textApproxBytesById.set(textMutation.id, nextTextApproxBytes);
|
|
392
|
+
merged.textsApproxBytes += nextTextApproxBytes;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
merged.texts.push(textMutation);
|
|
396
|
+
merged.textsById.set(textMutation.id, textMutation);
|
|
397
|
+
var textApproxBytes = estimateMutationEntryBytes(textMutation);
|
|
398
|
+
merged.textApproxBytesById.set(textMutation.id, textApproxBytes);
|
|
399
|
+
merged.textsApproxBytes += textApproxBytes;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function mergeAttributeMutations(merged, sourceAttributes) {
|
|
403
|
+
if (!sourceAttributes.length) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
sourceAttributes.forEach(function (attributeMutation) {
|
|
407
|
+
var existingAttributeMutation = merged.attributesById.get(attributeMutation.id);
|
|
408
|
+
if (!existingAttributeMutation) {
|
|
409
|
+
var nextAttributeMutation = {
|
|
410
|
+
id: attributeMutation.id,
|
|
411
|
+
attributes: assign({}, attributeMutation.attributes)
|
|
412
|
+
};
|
|
413
|
+
merged.attributes.push(nextAttributeMutation);
|
|
414
|
+
merged.attributesById.set(attributeMutation.id, nextAttributeMutation);
|
|
415
|
+
var attributeApproxBytes = estimateMutationEntryBytes(nextAttributeMutation);
|
|
416
|
+
merged.attributeApproxBytesById.set(attributeMutation.id, attributeApproxBytes);
|
|
417
|
+
merged.attributesApproxBytes += attributeApproxBytes;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
merged.attributesApproxBytes -= merged.attributeApproxBytesById.get(attributeMutation.id) || 0;
|
|
421
|
+
existingAttributeMutation.attributes = assign(existingAttributeMutation.attributes, attributeMutation.attributes);
|
|
422
|
+
var nextAttributeApproxBytes = estimateMutationEntryBytes(existingAttributeMutation);
|
|
423
|
+
merged.attributeApproxBytesById.set(attributeMutation.id, nextAttributeApproxBytes);
|
|
424
|
+
merged.attributesApproxBytes += nextAttributeApproxBytes;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function getRemoveMutationKey(remove) {
|
|
428
|
+
return remove.parentId + ':' + remove.id;
|
|
429
|
+
}
|
|
430
|
+
function shouldFlushPendingMutationPayloadBeforeMerge(target, source) {
|
|
431
|
+
return target.approxBytes + estimateMutationPayloadBytes(source) > MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
432
|
+
}
|
|
433
|
+
function splitPendingMutationPayloadForEmit(pendingMutationPayload) {
|
|
434
|
+
var mutation = materializeMutationPayload(pendingMutationPayload);
|
|
435
|
+
if (!mutation.adds.length || pendingMutationPayload.approxBytes <= MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
436
|
+
return [mutation];
|
|
437
|
+
}
|
|
438
|
+
var addOnlyPayloads = [];
|
|
439
|
+
var currentAdds = [];
|
|
440
|
+
var currentAddsBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES;
|
|
441
|
+
mutation.adds.forEach(function (add, index) {
|
|
442
|
+
var addBytes = pendingMutationPayload.addApproxBytes[index];
|
|
443
|
+
if (currentAdds.length && currentAddsBytes + addBytes > MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
444
|
+
addOnlyPayloads.push({
|
|
445
|
+
adds: currentAdds,
|
|
446
|
+
removes: [],
|
|
447
|
+
texts: [],
|
|
448
|
+
attributes: []
|
|
449
|
+
});
|
|
450
|
+
currentAdds = [];
|
|
451
|
+
currentAddsBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES;
|
|
452
|
+
}
|
|
453
|
+
currentAdds.push(add);
|
|
454
|
+
currentAddsBytes += addBytes;
|
|
455
|
+
});
|
|
456
|
+
if (currentAdds.length) {
|
|
457
|
+
addOnlyPayloads.push({
|
|
458
|
+
adds: currentAdds,
|
|
459
|
+
removes: [],
|
|
460
|
+
texts: [],
|
|
461
|
+
attributes: []
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
if (mutation.removes.length || mutation.texts.length || mutation.attributes.length) {
|
|
465
|
+
addOnlyPayloads.push({
|
|
466
|
+
adds: [],
|
|
467
|
+
removes: mutation.removes,
|
|
468
|
+
texts: mutation.texts,
|
|
469
|
+
attributes: mutation.attributes
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return addOnlyPayloads;
|
|
473
|
+
}
|
|
474
|
+
function createEmptyMutation() {
|
|
475
|
+
return {
|
|
476
|
+
adds: [],
|
|
477
|
+
removes: [],
|
|
478
|
+
texts: [],
|
|
479
|
+
attributes: []
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
var BASE_MUTATION_PAYLOAD_APPROX_BYTES = 64;
|
|
483
|
+
function estimateMutationPayloadBytes(mutation) {
|
|
484
|
+
return BASE_MUTATION_PAYLOAD_APPROX_BYTES + estimateMutationEntriesBytes(mutation.adds) + estimateMutationEntriesBytes(mutation.removes) + estimateMutationEntriesBytes(mutation.texts) + estimateMutationEntriesBytes(mutation.attributes);
|
|
485
|
+
}
|
|
486
|
+
function estimateMutationEntryBytes(entry) {
|
|
487
|
+
return JSON.stringify(entry).length;
|
|
488
|
+
}
|
|
489
|
+
function estimateMutationEntriesBytes(entries) {
|
|
490
|
+
var total = 0;
|
|
491
|
+
for (var i = 0; i < entries.length; i += 1) {
|
|
492
|
+
total += estimateMutationEntryBytes(entries[i]);
|
|
493
|
+
}
|
|
494
|
+
return total;
|
|
495
|
+
}
|
|
496
|
+
function updateMutationPayloadApproxBytes(mutationPayload) {
|
|
497
|
+
mutationPayload.approxBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES + mutationPayload.addsApproxBytes + mutationPayload.removesApproxBytes + mutationPayload.textsApproxBytes + mutationPayload.attributesApproxBytes;
|
|
498
|
+
}
|
|
499
|
+
function createReplayPerformanceStats() {
|
|
500
|
+
return {
|
|
501
|
+
processMutationsCount: 0,
|
|
502
|
+
processMutationsDuration: 0,
|
|
503
|
+
mutationCallbackCount: 0,
|
|
504
|
+
mutationRecordCount: 0,
|
|
505
|
+
mutationAddCount: 0,
|
|
506
|
+
mutationRemoveCount: 0,
|
|
507
|
+
mutationTextCount: 0,
|
|
508
|
+
mutationAttributeCount: 0
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function accumulateReplayPerformanceStats(stats, delta) {
|
|
512
|
+
if (!delta) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
stats.processMutationsCount += delta.processMutationsCount || 0;
|
|
516
|
+
stats.processMutationsDuration += delta.processMutationsDuration || 0;
|
|
517
|
+
stats.mutationCallbackCount += delta.mutationCallbackCount || 0;
|
|
518
|
+
stats.mutationRecordCount += delta.mutationRecordCount || 0;
|
|
519
|
+
stats.mutationAddCount += delta.mutationAddCount || 0;
|
|
520
|
+
stats.mutationRemoveCount += delta.mutationRemoveCount || 0;
|
|
521
|
+
stats.mutationTextCount += delta.mutationTextCount || 0;
|
|
522
|
+
stats.mutationAttributeCount += delta.mutationAttributeCount || 0;
|
|
523
|
+
}
|
|
524
|
+
function countMutationPayloadRecords(mutation) {
|
|
525
|
+
return mutation.adds.length + mutation.removes.length + mutation.texts.length + mutation.attributes.length;
|
|
526
|
+
}
|
|
527
|
+
function cloneReplayPerformanceStats(stats) {
|
|
528
|
+
if (!stats) {
|
|
529
|
+
return stats;
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
processMutationsCount: stats.processMutationsCount,
|
|
533
|
+
processMutationsDuration: Math.round(stats.processMutationsDuration * 10) / 10,
|
|
534
|
+
mutationCallbackCount: stats.mutationCallbackCount,
|
|
535
|
+
mutationRecordCount: stats.mutationRecordCount,
|
|
536
|
+
mutationAddCount: stats.mutationAddCount,
|
|
537
|
+
mutationRemoveCount: stats.mutationRemoveCount,
|
|
538
|
+
mutationTextCount: stats.mutationTextCount,
|
|
539
|
+
mutationAttributeCount: stats.mutationAttributeCount
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function pushCanvasDebugHistoryEntry(history, entry) {
|
|
543
|
+
if (!entry) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
history.push(entry);
|
|
547
|
+
if (history.length > CANVAS_DEBUG_HISTORY_LIMIT) {
|
|
548
|
+
history.shift();
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function stopCanvasSnapshots(canvasSnapshotLoop) {
|
|
552
|
+
if (typeof canvasSnapshotLoop === 'function') {
|
|
553
|
+
canvasSnapshotLoop();
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (canvasSnapshotLoop && canvasSnapshotLoop.stop) {
|
|
557
|
+
canvasSnapshotLoop.stop();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function resetCanvasSnapshots(canvasSnapshotLoop) {
|
|
561
|
+
if (canvasSnapshotLoop && canvasSnapshotLoop.reset) {
|
|
562
|
+
canvasSnapshotLoop.reset();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function shouldKeepSessionAliveAfterAutoCanvasSnapshot(result) {
|
|
566
|
+
return !!(result && result.status === 'completed' && result.selectedCanvasCount > 0 && (result.results || []).some(function (entry) {
|
|
567
|
+
return isKeepAliveWorthyAutoCanvasResult(entry);
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
function isKeepAliveWorthyAutoCanvasResult(entry) {
|
|
571
|
+
return !!(entry && (entry.ok || entry.reason === 'unchanged' || entry.reason === 'below_threshold'));
|
|
572
|
+
}
|
|
573
|
+
function cloneAutoCanvasSnapshotDebugResult(result, keepSessionAliveTriggered) {
|
|
574
|
+
if (!result) {
|
|
575
|
+
return result;
|
|
576
|
+
}
|
|
577
|
+
if (typeof keepSessionAliveTriggered === 'undefined') {
|
|
578
|
+
keepSessionAliveTriggered = result.keepSessionAliveTriggered;
|
|
579
|
+
}
|
|
580
|
+
return {
|
|
581
|
+
scheduler: result.scheduler,
|
|
582
|
+
status: result.status,
|
|
583
|
+
startedAt: typeof result.startedAt === 'number' ? result.startedAt : result.timestamp,
|
|
584
|
+
completedAt: typeof result.completedAt === 'number' ? result.completedAt : result.timestamp,
|
|
585
|
+
timestamp: result.timestamp,
|
|
586
|
+
eligibleCanvasCount: result.eligibleCanvasCount,
|
|
587
|
+
selectedCanvasCount: result.selectedCanvasCount,
|
|
588
|
+
skippedBudgetCount: result.skippedBudgetCount,
|
|
589
|
+
keepSessionAliveTriggered: !!keepSessionAliveTriggered,
|
|
590
|
+
results: (result.results || []).map(function (entry) {
|
|
591
|
+
return {
|
|
592
|
+
canvasId: entry.canvasId,
|
|
593
|
+
ok: entry.ok,
|
|
594
|
+
reason: entry.reason,
|
|
595
|
+
priority: entry.priority
|
|
596
|
+
};
|
|
597
|
+
})
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function cloneCanvasMutationDebugResult(result) {
|
|
601
|
+
if (!result) {
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
604
|
+
var clonedResult = {
|
|
605
|
+
timestamp: result.timestamp,
|
|
606
|
+
canvasId: result.canvasId,
|
|
607
|
+
trigger: result.trigger,
|
|
608
|
+
encodedBytesCount: result.encodedBytesCount,
|
|
609
|
+
approxBytesCount: result.approxBytesCount,
|
|
610
|
+
commandCount: result.commandCount,
|
|
611
|
+
width: result.width,
|
|
612
|
+
height: result.height
|
|
613
|
+
};
|
|
614
|
+
if (typeof result.reason !== 'undefined') {
|
|
615
|
+
clonedResult.reason = result.reason;
|
|
616
|
+
}
|
|
617
|
+
if (typeof result.diagnostics !== 'undefined') {
|
|
618
|
+
clonedResult.diagnostics = result.diagnostics;
|
|
619
|
+
}
|
|
620
|
+
return clonedResult;
|
|
621
|
+
}
|
|
145
622
|
//# sourceMappingURL=record.js.map
|