@cloudcare/browser-rum 3.3.6 → 3.3.7
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 +24 -3
- package/README.zh.md +19 -3
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/buildEnv.js.map +1 -1
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +170 -200
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/recorderApiStub.js +3 -29
- package/cjs/boot/recorderApiStub.js.map +1 -1
- package/cjs/boot/rum.entry.js.map +1 -1
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rum.slim.entry.js.map +1 -1
- package/cjs/boot/rumEntryFactory.js.map +1 -1
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/boot/rumRecorderApiStub.js.map +1 -1
- package/cjs/boot/rumSlimConfiguration.js.map +1 -1
- package/cjs/boot/sessionReplayPublicApi.js +14 -27
- package/cjs/boot/sessionReplayPublicApi.js.map +1 -1
- package/cjs/boot/startRecording.js +333 -108
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/constants.js.map +1 -1
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +31 -43
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/contexts/commonContext.js.map +1 -1
- package/cjs/domain/contexts/displayContext.js.map +1 -1
- package/cjs/domain/contexts/foregroundContexts.js.map +1 -1
- package/cjs/domain/contexts/internalContext.js.map +1 -1
- package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
- package/cjs/domain/contexts/urlContexts.js +10 -1
- package/cjs/domain/contexts/urlContexts.js.map +1 -1
- package/cjs/domain/contexts/viewContexts.js.map +1 -1
- package/cjs/domain/deflate/deflateEncoder.js +517 -39
- package/cjs/domain/deflate/deflateEncoder.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +194 -115
- package/cjs/domain/deflate/deflateWorker.js.map +1 -1
- package/cjs/domain/deflate/index.js.map +1 -1
- package/cjs/domain/domMutationObservable.js.map +1 -1
- package/cjs/domain/encoderStreamId.js.map +1 -1
- package/cjs/domain/firstInputPolyfill.js.map +1 -1
- package/cjs/domain/initViewportObservable.js.map +1 -1
- package/cjs/domain/locationChangeObservable.js.map +1 -1
- package/cjs/domain/performanceObservable.js.map +1 -1
- package/cjs/domain/performanceUtils.js.map +1 -1
- package/cjs/domain/plugins.js.map +1 -1
- package/cjs/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandCapture.js +968 -167
- package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandObserver.js +1058 -119
- package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +61 -37
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/cjs/domain/replay/record/canvasContext.js +63 -0
- package/cjs/domain/replay/record/canvasContext.js.map +1 -0
- package/cjs/domain/replay/record/canvasContinuousScheduler.js +246 -118
- package/cjs/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeBridge.js +539 -87
- package/cjs/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +50 -32
- package/cjs/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/cjs/domain/replay/record/canvasFrameSignature.js +49 -17
- package/cjs/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/cjs/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/cjs/domain/replay/record/canvasObserver.js +295 -59
- package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
- package/cjs/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/cjs/domain/replay/record/canvasWebGLPluginHost.js +33 -0
- package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
- package/cjs/domain/replay/record/elementsScrollPositions.js +3 -0
- package/cjs/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/cjs/domain/replay/record/index.js.map +1 -1
- package/cjs/domain/replay/record/mutationBatch.js +542 -25
- package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +1900 -191
- package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
- package/cjs/domain/replay/record/mutationResourceBudget.js +144 -0
- package/cjs/domain/replay/record/mutationResourceBudget.js.map +1 -0
- package/cjs/domain/replay/record/observers.js +222 -53
- package/cjs/domain/replay/record/observers.js.map +1 -1
- package/cjs/domain/replay/record/privacy.js +31 -8
- package/cjs/domain/replay/record/privacy.js.map +1 -1
- package/cjs/domain/replay/record/record.js +3083 -321
- package/cjs/domain/replay/record/record.js.map +1 -1
- package/cjs/domain/replay/record/serializationUtils.js +426 -26
- package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
- package/cjs/domain/replay/record/serialize.js +259 -49
- package/cjs/domain/replay/record/serialize.js.map +1 -1
- package/cjs/domain/replay/record/shadowRootsController.js +875 -21
- package/cjs/domain/replay/record/shadowRootsController.js.map +1 -1
- package/cjs/domain/replay/record/utils.js.map +1 -1
- package/cjs/domain/replay/record/viewports.js.map +1 -1
- package/cjs/domain/replay/replayStats.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/index.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segment.js +315 -11
- package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +956 -71
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/cjs/domain/replay/startRecordBridge.js.map +1 -1
- package/cjs/domain/requestCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/cjs/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +29 -11
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/cjs/domain/tracing/ddtraceTracer.js.map +1 -1
- package/cjs/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/cjs/domain/tracing/jaegerTracer.js.map +1 -1
- package/cjs/domain/tracing/sampler.js.map +1 -1
- package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
- package/cjs/domain/tracing/traceIdentifier.js.map +1 -1
- package/cjs/domain/tracing/tracer.js +2 -2
- package/cjs/domain/tracing/tracer.js.map +1 -1
- package/cjs/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/cjs/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/cjs/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/cjs/domain/trackEventCounts.js.map +1 -1
- package/cjs/domain/usr/index.js.map +1 -1
- package/cjs/domain/waitPageActivityEnd.js.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/transport/startRumBatch.js +3 -1
- package/cjs/transport/startRumBatch.js.map +1 -1
- package/cjs/transport/startRumEventBridge.js.map +1 -1
- package/cjs/types/index.js.map +1 -1
- package/cjs/types/sessionReplayConstants.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/buildEnv.js.map +1 -1
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +172 -202
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/recorderApiStub.js +3 -29
- package/esm/boot/recorderApiStub.js.map +1 -1
- package/esm/boot/rum.entry.js.map +1 -1
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rum.slim.entry.js.map +1 -1
- package/esm/boot/rumEntryFactory.js.map +1 -1
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/rumRecorderApiStub.js.map +1 -1
- package/esm/boot/rumSlimConfiguration.js.map +1 -1
- package/esm/boot/sessionReplayPublicApi.js +14 -27
- package/esm/boot/sessionReplayPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +334 -109
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/constants.js.map +1 -1
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +31 -43
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/commonContext.js.map +1 -1
- package/esm/domain/contexts/displayContext.js.map +1 -1
- package/esm/domain/contexts/foregroundContexts.js.map +1 -1
- package/esm/domain/contexts/internalContext.js.map +1 -1
- package/esm/domain/contexts/pageStateHistory.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +11 -2
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateEncoder.js +517 -39
- package/esm/domain/deflate/deflateEncoder.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +193 -116
- package/esm/domain/deflate/deflateWorker.js.map +1 -1
- package/esm/domain/deflate/index.js.map +1 -1
- package/esm/domain/domMutationObservable.js.map +1 -1
- package/esm/domain/encoderStreamId.js.map +1 -1
- package/esm/domain/firstInputPolyfill.js.map +1 -1
- package/esm/domain/initViewportObservable.js.map +1 -1
- package/esm/domain/locationChangeObservable.js.map +1 -1
- package/esm/domain/performanceObservable.js.map +1 -1
- package/esm/domain/performanceUtils.js.map +1 -1
- package/esm/domain/plugins.js.map +1 -1
- package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandCapture.js +968 -168
- package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandObserver.js +1058 -119
- package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js +60 -37
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasContext.js +50 -0
- package/esm/domain/replay/record/canvasContext.js.map +1 -0
- package/esm/domain/replay/record/canvasContinuousScheduler.js +246 -118
- package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeBridge.js +539 -87
- package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +51 -33
- package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/esm/domain/replay/record/canvasFrameSignature.js +50 -17
- package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/esm/domain/replay/record/canvasObserver.js +295 -59
- package/esm/domain/replay/record/canvasObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasWebGLPluginHost.js +26 -0
- package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
- package/esm/domain/replay/record/elementsScrollPositions.js +3 -0
- package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/esm/domain/replay/record/index.js.map +1 -1
- package/esm/domain/replay/record/mutationBatch.js +541 -25
- package/esm/domain/replay/record/mutationBatch.js.map +1 -1
- package/esm/domain/replay/record/mutationObserver.js +1892 -195
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/mutationResourceBudget.js +137 -0
- package/esm/domain/replay/record/mutationResourceBudget.js.map +1 -0
- package/esm/domain/replay/record/observers.js +224 -55
- package/esm/domain/replay/record/observers.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +30 -7
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/record.js +3086 -325
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +422 -25
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +258 -50
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/replay/record/shadowRootsController.js +875 -21
- package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
- package/esm/domain/replay/record/utils.js.map +1 -1
- package/esm/domain/replay/record/viewports.js.map +1 -1
- package/esm/domain/replay/replayStats.js.map +1 -1
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/esm/domain/replay/segmentCollection/index.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +315 -10
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +957 -72
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/replay/startRecordBridge.js.map +1 -1
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +30 -12
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
- package/esm/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/esm/domain/tracing/jaegerTracer.js.map +1 -1
- package/esm/domain/tracing/sampler.js.map +1 -1
- package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
- package/esm/domain/tracing/traceIdentifier.js.map +1 -1
- package/esm/domain/tracing/tracer.js +2 -2
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/esm/domain/trackEventCounts.js.map +1 -1
- package/esm/domain/usr/index.js.map +1 -1
- package/esm/domain/waitPageActivityEnd.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/transport/startRumBatch.js +4 -2
- package/esm/transport/startRumBatch.js.map +1 -1
- package/esm/transport/startRumEventBridge.js.map +1 -1
- package/esm/types/index.js.map +1 -1
- package/esm/types/sessionReplayConstants.js.map +1 -1
- package/package.json +12 -7
- package/src/boot/recorderApi.js +247 -220
- package/src/boot/recorderApiStub.js +3 -29
- package/src/boot/sessionReplayPublicApi.js +15 -28
- package/src/boot/startRecording.js +429 -146
- package/src/domain/assembly.js +5 -4
- package/src/domain/configuration.js +63 -100
- package/src/domain/contexts/urlContexts.js +16 -4
- package/src/domain/deflate/deflateEncoder.js +699 -43
- package/src/domain/deflate/deflateWorker.js +237 -136
- package/src/domain/replay/record/canvasCommandCapture.js +1374 -180
- package/src/domain/replay/record/canvasCommandObserver.js +1585 -150
- package/src/domain/replay/record/canvasCommandSerializeArgs.js +79 -42
- package/src/domain/replay/record/canvasContext.js +67 -0
- package/src/domain/replay/record/canvasContinuousScheduler.js +379 -143
- package/src/domain/replay/record/canvasEncodeBridge.js +691 -106
- package/src/domain/replay/record/canvasEncodeWorker.js +67 -43
- package/src/domain/replay/record/canvasFrameSignature.js +58 -24
- package/src/domain/replay/record/canvasObserver.js +461 -89
- package/src/domain/replay/record/canvasWebGLPluginHost.js +43 -0
- package/src/domain/replay/record/elementsScrollPositions.js +3 -0
- package/src/domain/replay/record/mutationBatch.js +761 -27
- package/src/domain/replay/record/mutationObserver.js +2992 -261
- package/src/domain/replay/record/mutationResourceBudget.js +191 -0
- package/src/domain/replay/record/observers.js +367 -97
- package/src/domain/replay/record/privacy.js +34 -12
- package/src/domain/replay/record/record.js +4284 -413
- package/src/domain/replay/record/serializationUtils.js +587 -28
- package/src/domain/replay/record/serialize.js +432 -66
- package/src/domain/replay/record/shadowRootsController.js +1108 -30
- package/src/domain/replay/segmentCollection/segment.js +441 -11
- package/src/domain/replay/segmentCollection/segmentCollection.js +1300 -77
- package/src/domain/rumEventsCollection/view/trackViews.js +36 -12
- package/src/domain/tracing/tracer.js +4 -5
- package/src/transport/startRumBatch.js +6 -1
- package/types/index.d.ts +15 -2
- package/cjs/domain/replay/record/canvasReplayFixtures.js +0 -105
- package/cjs/domain/replay/record/canvasReplayFixtures.js.map +0 -1
- package/esm/domain/replay/record/canvasReplayFixtures.js +0 -96
- package/esm/domain/replay/record/canvasReplayFixtures.js.map +0 -1
- package/src/domain/replay/record/canvasReplayFixtures.js +0 -113
|
@@ -1,44 +1,730 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import { timeStampNow, getScrollX, getScrollY, assign } from '@cloudcare/browser-core';
|
|
2
|
+
import { timeStampNow, getScrollX, getScrollY, assign, addTelemetryDebug, getParentNode } from '@cloudcare/browser-core';
|
|
3
3
|
import { getViewportDimension } from '../../initViewportObservable';
|
|
4
4
|
import { RecordType, IncrementalSource } from '../../../types';
|
|
5
|
-
import {
|
|
5
|
+
import { NodePrivacyLevel } from '../../../constants';
|
|
6
|
+
import { createMutationSerializerTask, SerializationContextStatus, getSerializedNodeApproxBytes, SERIALIZATION_MAX_NODE_COUNT, SERIALIZATION_MAX_APPROX_BYTES } from './serialize';
|
|
6
7
|
import { initObservers } from './observers';
|
|
7
8
|
import { getVisualViewport } from './viewports';
|
|
8
9
|
import { assembleIncrementalSnapshot } from './utils';
|
|
9
10
|
import { createElementsScrollPositions } from './elementsScrollPositions';
|
|
10
11
|
import { initShadowRootsController } from './shadowRootsController';
|
|
11
12
|
import { createCanvasObserver } from './canvasObserver';
|
|
13
|
+
import { createCanvasEncodeBridge } from './canvasEncodeBridge';
|
|
14
|
+
import { isWebGLReplayCanvas } from './canvasContext';
|
|
15
|
+
import { createNoopObserver, createSessionReplayWebGLRuntime } from './canvasWebGLPluginHost';
|
|
12
16
|
import { startCanvasCommandCapture } from './canvasCommandObserver';
|
|
13
|
-
import { getSerializedCanvasNodes, getSerializedNodeId
|
|
17
|
+
import { getSerializedCanvasNodes, getSerializedCanvasNodesSnapshot, getSerializedNodeId, startSerializedCanvasTracking, MAX_SERIALIZED_NODE_ANCESTOR_DEPTH } from './serializationUtils';
|
|
18
|
+
import { cancelMutationAddPublicationToken, consumeMutationAddPublicationToken, consumeMutationRemoveSourceNode, createMutationAddPublicationToken, getMutationAddPublicationToken, getMutationRemoveSourceNode, publishMutationAddPublicationToken, registerMutationAddPublicationToken } from './mutationObserver';
|
|
19
|
+
import { createMutationResourceBudget } from './mutationResourceBudget';
|
|
20
|
+
import { getNodePrivacyLevel } from './privacy';
|
|
14
21
|
import { startContinuousCanvasSnapshotLoop } from './canvasContinuousScheduler';
|
|
15
22
|
var MUTATION_EMIT_DELAY_MS = 16;
|
|
16
23
|
var MAX_MUTATION_EMIT_APPROX_BYTES = 200000;
|
|
24
|
+
var MUTATION_ADMISSION_RETRY_DELAY_MS = 32;
|
|
25
|
+
var MUTATION_ADMISSION_DRAIN_SLICE_MS = 4;
|
|
26
|
+
var MUTATION_ADMISSION_DRAIN_SLICE_APPROX_BYTES = 256 * 1024;
|
|
27
|
+
var MUTATION_SOURCE_BOUNDARY_FLUSH_BUDGET_MS = 12;
|
|
28
|
+
var MAX_PENDING_MUTATION_ADMISSION_PAYLOADS = 512;
|
|
29
|
+
var MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES = 32 * 1024 * 1024;
|
|
30
|
+
var DYNAMIC_SHADOW_ROOT_SERIALIZATION_MAX_NODE_COUNT = 5000;
|
|
31
|
+
var DYNAMIC_SHADOW_ROOT_SERIALIZATION_MAX_APPROX_BYTES = MAX_MUTATION_EMIT_APPROX_BYTES - 1024;
|
|
32
|
+
var INITIAL_FULL_SNAPSHOT_SERIALIZATION_SLICE_MS = 8;
|
|
33
|
+
var FULL_SNAPSHOT_SERIALIZATION_SLICE_MS = 4;
|
|
34
|
+
// The churn fallback runs without yielding so the baseline cannot mix DOM
|
|
35
|
+
// generations. Keep the whole transaction within one frame.
|
|
36
|
+
var FULL_SNAPSHOT_SYNCHRONOUS_FINALIZATION_BUDGET_MS = 12;
|
|
37
|
+
// Initial snapshots may need several serializer watermarks, but the complete
|
|
38
|
+
// record must still fit below the segment layer's 4 MiB pending-raw budget.
|
|
39
|
+
var FULL_SNAPSHOT_SERIALIZATION_MAX_NODE_COUNT = SERIALIZATION_MAX_NODE_COUNT * 4;
|
|
40
|
+
var FULL_SNAPSHOT_SERIALIZATION_MAX_APPROX_BYTES = SERIALIZATION_MAX_APPROX_BYTES * 4 - 64 * 1024;
|
|
41
|
+
var FULL_SNAPSHOT_MAX_RESTART_COUNT = 3;
|
|
42
|
+
var FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS = 1000;
|
|
43
|
+
var FULL_SNAPSHOT_MAX_WALL_DURATION_MS = 30000;
|
|
44
|
+
var FULL_SNAPSHOT_MUTATION_QUIET_DELAY_MS = 250;
|
|
45
|
+
export var MAX_FULL_SNAPSHOT_CANVAS_BASELINE_COUNT = 64;
|
|
46
|
+
var FULL_SNAPSHOT_CANVAS_BASELINE_TOTAL_TIMEOUT_MS = 2000;
|
|
47
|
+
var FULL_SNAPSHOT_CANVAS_BASELINE_ITEM_TIMEOUT_MS = 1000;
|
|
17
48
|
var CANVAS_DEBUG_HISTORY_LIMIT = 200;
|
|
49
|
+
var DOM_MUTATION_DEBUG_HISTORY_LIMIT = 20;
|
|
50
|
+
var DOM_MUTATION_DEBUG_SAMPLE_LIMIT = 5;
|
|
51
|
+
export var MAX_DEFERRED_RECORDS = 100;
|
|
52
|
+
export var MAX_DEFERRED_RECORD_APPROX_BYTES = 512 * 1024;
|
|
18
53
|
function shouldUseCommandCapture(configuration) {
|
|
19
54
|
return configuration.replayCanvasEnabled && configuration.replayCanvasMode === 'auto' && configuration.replayCanvasSampling === 'all';
|
|
20
55
|
}
|
|
21
56
|
function shouldUseContinuousCanvasSnapshot(configuration) {
|
|
22
57
|
return configuration.replayCanvasEnabled && configuration.replayCanvasMode === 'auto' && configuration.replayCanvasSampling !== 'all';
|
|
23
58
|
}
|
|
59
|
+
function isDomMutationRecord(record) {
|
|
60
|
+
return record && record.type === RecordType.IncrementalSnapshot && record.data && record.data.source === IncrementalSource.Mutation;
|
|
61
|
+
}
|
|
62
|
+
function isStatefulDeferredRecord(record) {
|
|
63
|
+
return record && (record.type === RecordType.Focus || record.type === RecordType.VisualViewport || record.type === RecordType.IncrementalSnapshot && record.data && (record.data.source === IncrementalSource.CanvasMutation || record.data.source === IncrementalSource.StyleSheetRule || record.data.source === IncrementalSource.Input || record.data.source === IncrementalSource.Scroll || record.data.source === IncrementalSource.MediaInteraction || record.data.source === IncrementalSource.ViewportResize));
|
|
64
|
+
}
|
|
65
|
+
function reportWebGLReplayFailure(phase, error) {
|
|
66
|
+
addTelemetryDebug(phase, {
|
|
67
|
+
error: String(error)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
24
70
|
export function record(options) {
|
|
25
|
-
var
|
|
71
|
+
var rawEmit = options.emit;
|
|
72
|
+
var rawEmitBaseline = options.$rEmitBaseline;
|
|
26
73
|
// runtime checks for user options
|
|
27
|
-
if (!
|
|
74
|
+
if (!rawEmit) {
|
|
28
75
|
throw new Error('emit function is required');
|
|
29
76
|
}
|
|
77
|
+
var configuration = options.configuration;
|
|
78
|
+
var initializationCleanupTasks = [];
|
|
79
|
+
var recordStopping = false;
|
|
80
|
+
var recordStopped = false;
|
|
81
|
+
function registerInitializationCleanup(cleanupTask) {
|
|
82
|
+
if (typeof cleanupTask === 'function') {
|
|
83
|
+
initializationCleanupTasks.push(cleanupTask);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function abortRecorderInitialization(reason, initializationError) {
|
|
87
|
+
recordStopping = true;
|
|
88
|
+
recordStopped = true;
|
|
89
|
+
var firstCleanupError;
|
|
90
|
+
initializationCleanupTasks.slice().reverse().forEach(function (cleanupTask) {
|
|
91
|
+
try {
|
|
92
|
+
cleanupTask();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (!firstCleanupError) {
|
|
95
|
+
firstCleanupError = error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
initializationCleanupTasks = [];
|
|
100
|
+
addTelemetryDebug('Session Replay recorder initialization failed.', {
|
|
101
|
+
reason: reason,
|
|
102
|
+
error: String(initializationError || firstCleanupError)
|
|
103
|
+
});
|
|
104
|
+
if (options.onFullSnapshotFailure) {
|
|
105
|
+
try {
|
|
106
|
+
options.onFullSnapshotFailure(reason);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
addTelemetryDebug('Session Replay recorder initialization failure callback failed.', {
|
|
109
|
+
reason: reason,
|
|
110
|
+
error: String(error)
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return createInactiveRecorder();
|
|
115
|
+
}
|
|
116
|
+
var stopSerializedCanvasTracking;
|
|
117
|
+
try {
|
|
118
|
+
stopSerializedCanvasTracking = shouldUseCommandCapture(configuration) || shouldUseContinuousCanvasSnapshot(configuration) ? startSerializedCanvasTracking() : function () {};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
121
|
+
}
|
|
122
|
+
registerInitializationCleanup(stopSerializedCanvasTracking);
|
|
123
|
+
var suppressRecordsUntilFullSnapshot = false;
|
|
124
|
+
var deferredRecords = [];
|
|
125
|
+
var deferredRecordsApproxBytes = 0;
|
|
126
|
+
var previousReplayTreeRecords = [];
|
|
127
|
+
var previousReplayTreeRecordsApproxBytes = 0;
|
|
128
|
+
var previousReplayTreeLastRecordTimestamp;
|
|
129
|
+
var previousReplayTreeAdmissionActive = false;
|
|
130
|
+
var captureRecordsAgainstPreviousReplayTree = false;
|
|
131
|
+
var deferredRecordAdmissionTimeout;
|
|
132
|
+
var mutationAdmissionEmitInProgress = false;
|
|
133
|
+
var mutationPublicationBarrier;
|
|
134
|
+
var lastEmitWasLocallyBackpressured = false;
|
|
135
|
+
function deferNonDomRecord(record, mutationAdmissionBarrier, insertBeforeLaterBarrier) {
|
|
136
|
+
var recordApproxBytes = estimateJsonValueBytes(record, MAX_DEFERRED_RECORD_APPROX_BYTES);
|
|
137
|
+
if (recordApproxBytes > MAX_DEFERRED_RECORD_APPROX_BYTES) {
|
|
138
|
+
handleDeferredRecordLoss(record);
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
var evictedStatefulRecord;
|
|
142
|
+
while (deferredRecords.length && (deferredRecords.length >= MAX_DEFERRED_RECORDS || deferredRecordsApproxBytes + recordApproxBytes > MAX_DEFERRED_RECORD_APPROX_BYTES)) {
|
|
143
|
+
var removedEntry = deferredRecords.shift();
|
|
144
|
+
deferredRecordsApproxBytes -= removedEntry.$rApproxBytes;
|
|
145
|
+
if (!evictedStatefulRecord && isStatefulDeferredRecord(removedEntry.$rRecord)) {
|
|
146
|
+
evictedStatefulRecord = removedEntry.$rRecord;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (evictedStatefulRecord) {
|
|
150
|
+
handleDeferredRecordLoss(evictedStatefulRecord);
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
if (mutationAdmissionBarrier) {
|
|
154
|
+
// Once a non-DOM record observes this exact boundary, later pure adds
|
|
155
|
+
// must not be folded into it and move ahead of the observed state.
|
|
156
|
+
mutationAdmissionBarrier.$rReferencedByDeferredRecord = true;
|
|
157
|
+
}
|
|
158
|
+
var deferredEntry = {
|
|
159
|
+
$rRecord: record,
|
|
160
|
+
$rApproxBytes: recordApproxBytes,
|
|
161
|
+
// Keep the exact structural boundary that was pending when this
|
|
162
|
+
// record was observed. The drain uses it to interleave input/CSSOM
|
|
163
|
+
// and other node-dependent state after its add, but before later DOM
|
|
164
|
+
// mutations.
|
|
165
|
+
$rMutationAdmissionBarrier: mutationAdmissionBarrier
|
|
166
|
+
};
|
|
167
|
+
if (insertBeforeLaterBarrier && mutationAdmissionBarrier) {
|
|
168
|
+
var insertionIndex = deferredRecords.length;
|
|
169
|
+
for (var deferredIndex = 0; deferredIndex < deferredRecords.length; deferredIndex += 1) {
|
|
170
|
+
var queuedBarrier = deferredRecords[deferredIndex].$rMutationAdmissionBarrier;
|
|
171
|
+
if (queuedBarrier && queuedBarrier !== mutationAdmissionBarrier) {
|
|
172
|
+
insertionIndex = deferredIndex;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
deferredRecords.splice(insertionIndex, 0, deferredEntry);
|
|
177
|
+
} else {
|
|
178
|
+
deferredRecords.push(deferredEntry);
|
|
179
|
+
}
|
|
180
|
+
deferredRecordsApproxBytes += recordApproxBytes;
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
function clearPreviousReplayTreeRecords() {
|
|
184
|
+
previousReplayTreeRecords = [];
|
|
185
|
+
previousReplayTreeRecordsApproxBytes = 0;
|
|
186
|
+
}
|
|
187
|
+
function resetPreviousReplayTreeRecords() {
|
|
188
|
+
clearPreviousReplayTreeRecords();
|
|
189
|
+
previousReplayTreeLastRecordTimestamp = undefined;
|
|
190
|
+
}
|
|
191
|
+
function updatePendingFullSnapshotTimestampFromRecord(record) {
|
|
192
|
+
if (!record || typeof record.timestamp !== 'number' || !isFinite(record.timestamp) || typeof pendingFullSnapshotTimestamp !== 'number' || record.timestamp <= pendingFullSnapshotTimestamp) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
pendingFullSnapshotTimestamp = record.timestamp;
|
|
196
|
+
previousReplayTreeLastRecordTimestamp = Math.max(typeof previousReplayTreeLastRecordTimestamp === 'number' ? previousReplayTreeLastRecordTimestamp : 0, record.timestamp);
|
|
197
|
+
if (pendingFullSnapshotBaselineRecords && isStatefulDeferredRecord(record)) {
|
|
198
|
+
// The replacement baseline belongs after every event admitted against
|
|
199
|
+
// the previous replay tree. Stateful changes also invalidate the
|
|
200
|
+
// serialized DOM/CSSOM state; stateless events only need fresh immutable
|
|
201
|
+
// baseline record wrappers, rebuilt immediately before admission.
|
|
202
|
+
pendingFullSnapshotRestartRequested = true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function queuePreviousReplayTreeRecord(record) {
|
|
206
|
+
var recordApproxBytes = estimateJsonValueBytes(record, MAX_DEFERRED_RECORD_APPROX_BYTES);
|
|
207
|
+
if (recordApproxBytes > MAX_DEFERRED_RECORD_APPROX_BYTES) {
|
|
208
|
+
if (isStatefulDeferredRecord(record)) {
|
|
209
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
210
|
+
pendingFullSnapshotRestartRequested = true;
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
while (previousReplayTreeRecords.length && (previousReplayTreeRecords.length >= MAX_DEFERRED_RECORDS || previousReplayTreeRecordsApproxBytes + recordApproxBytes > MAX_DEFERRED_RECORD_APPROX_BYTES)) {
|
|
216
|
+
var removedEntry = previousReplayTreeRecords.shift();
|
|
217
|
+
previousReplayTreeRecordsApproxBytes -= removedEntry.$rApproxBytes;
|
|
218
|
+
if (isStatefulDeferredRecord(removedEntry.$rRecord)) {
|
|
219
|
+
// A state gap makes restoring the old tail unsafe. The candidate
|
|
220
|
+
// baseline must complete and supersede it.
|
|
221
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
222
|
+
pendingFullSnapshotRestartRequested = true;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
previousReplayTreeRecords.push({
|
|
226
|
+
$rRecord: record,
|
|
227
|
+
$rApproxBytes: recordApproxBytes
|
|
228
|
+
});
|
|
229
|
+
previousReplayTreeRecordsApproxBytes += recordApproxBytes;
|
|
230
|
+
updatePendingFullSnapshotTimestampFromRecord(record);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
function emitAgainstPreviousReplayTree(record) {
|
|
234
|
+
if (previousReplayTreeRecords.length) {
|
|
235
|
+
return queuePreviousReplayTreeRecord(record);
|
|
236
|
+
}
|
|
237
|
+
if (rawEmit(record) !== false) {
|
|
238
|
+
updatePendingFullSnapshotTimestampFromRecord(record);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (wasLastEmitBackpressured()) {
|
|
242
|
+
return queuePreviousReplayTreeRecord(record);
|
|
243
|
+
}
|
|
244
|
+
if (isStatefulDeferredRecord(record)) {
|
|
245
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
246
|
+
pendingFullSnapshotRestartRequested = true;
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
function drainPreviousReplayTreeRecords() {
|
|
252
|
+
while (previousReplayTreeRecords.length) {
|
|
253
|
+
var entry = previousReplayTreeRecords[0];
|
|
254
|
+
if (rawEmit(entry.$rRecord) !== false) {
|
|
255
|
+
previousReplayTreeRecords.shift();
|
|
256
|
+
previousReplayTreeRecordsApproxBytes -= entry.$rApproxBytes;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (wasLastEmitBackpressured()) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
previousReplayTreeRecords.shift();
|
|
263
|
+
previousReplayTreeRecordsApproxBytes -= entry.$rApproxBytes;
|
|
264
|
+
if (isStatefulDeferredRecord(entry.$rRecord)) {
|
|
265
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
266
|
+
pendingFullSnapshotRestartRequested = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
function restorePreviousReplayTreeRecords() {
|
|
272
|
+
var records = previousReplayTreeRecords;
|
|
273
|
+
clearPreviousReplayTreeRecords();
|
|
274
|
+
records.forEach(function (entry) {
|
|
275
|
+
deferNonDomRecord(entry.$rRecord);
|
|
276
|
+
});
|
|
277
|
+
flushDeferredRecords();
|
|
278
|
+
}
|
|
279
|
+
var emit = function emit(record) {
|
|
280
|
+
lastEmitWasLocallyBackpressured = false;
|
|
281
|
+
if (suppressRecordsUntilFullSnapshot && previousReplayTreeAdmissionActive && !isDomMutationRecord(record)) {
|
|
282
|
+
return emitAgainstPreviousReplayTree(record);
|
|
283
|
+
}
|
|
284
|
+
if (suppressRecordsUntilFullSnapshot && isDomMutationRecord(record)) {
|
|
285
|
+
// The mutation activity callback already invalidated this mixed-time
|
|
286
|
+
// candidate. Retire the serialized payload locally and let the rebuilt
|
|
287
|
+
// FullSnapshot absorb it; reporting a rejection here would incorrectly
|
|
288
|
+
// classify an intentional suppression as an admission gap.
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
if (!suppressRecordsUntilFullSnapshot && !mutationPublicationBarrier && (!deferredRecords.length || mutationAdmissionEmitInProgress && deferredRecords[0].$rMutationAdmissionBarrier && deferredRecords[0].$rMutationAdmissionBarrier.$rPendingAdmission) && deferredRecordAdmissionTimeout === undefined && (mutationAdmissionEmitInProgress || !pendingMutationAdmissionQueue.length)) {
|
|
292
|
+
if (rawEmit(record) !== false) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
if (isDomMutationRecord(record)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (wasLastEmitBackpressured()) {
|
|
299
|
+
var wasDeferred = deferNonDomRecord(record);
|
|
300
|
+
if (wasDeferred) {
|
|
301
|
+
// A direct segment rejection has no DOM dependency to trigger its
|
|
302
|
+
// retry. Keep the exact record object (and any encoder-side cached
|
|
303
|
+
// serialization keyed by it) on the shared deferred drain.
|
|
304
|
+
scheduleDeferredRecordAdmissionRetry();
|
|
305
|
+
}
|
|
306
|
+
return wasDeferred;
|
|
307
|
+
}
|
|
308
|
+
handleDeferredRecordLoss(record);
|
|
309
|
+
return false;
|
|
310
|
+
} else if (!suppressRecordsUntilFullSnapshot && isDomMutationRecord(record)) {
|
|
311
|
+
// DOM publication membership is committed only after the segment layer
|
|
312
|
+
// accepts the record. Keep it in the mutation admission queue while
|
|
313
|
+
// post-baseline deferred records drain, so it cannot overtake them.
|
|
314
|
+
lastEmitWasLocallyBackpressured = true;
|
|
315
|
+
return false;
|
|
316
|
+
} else if (!isDomMutationRecord(record)) {
|
|
317
|
+
var mutationAdmissionBarrier = mutationPublicationBarrier || (!suppressRecordsUntilFullSnapshot && pendingMutationAdmissionQueue.length ? pendingMutationAdmissionQueue[pendingMutationAdmissionQueue.length - 1] : undefined);
|
|
318
|
+
return deferNonDomRecord(record, mutationAdmissionBarrier, Boolean(mutationPublicationBarrier));
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
};
|
|
30
322
|
var elementsScrollPositions = createElementsScrollPositions();
|
|
31
|
-
var replayPerformanceStats = createReplayPerformanceStats();
|
|
323
|
+
var replayPerformanceStats = false ? createReplayPerformanceStats() : undefined;
|
|
32
324
|
var pendingMutationPayload;
|
|
33
325
|
var pendingMutationTimeout;
|
|
326
|
+
var pendingMutationAdmissionQueue = [];
|
|
327
|
+
var pendingMutationAdmissionApproxBytes = 0;
|
|
328
|
+
var pendingMutationAdmissionTimeout;
|
|
329
|
+
var pendingFullSnapshotTimeout;
|
|
330
|
+
var pendingFullSnapshotTimestamp;
|
|
331
|
+
var pendingFullSnapshotCanBeDiscarded = false;
|
|
332
|
+
var pendingFullSnapshotRequiresTailDiscard = false;
|
|
333
|
+
var pendingFullSnapshotTask;
|
|
334
|
+
var pendingFullSnapshotMutationVersion;
|
|
335
|
+
var pendingFullSnapshotStartedAt;
|
|
336
|
+
var pendingFullSnapshotActiveDuration = 0;
|
|
337
|
+
var pendingFullSnapshotRestartCount = 0;
|
|
338
|
+
var pendingFullSnapshotRestartRequested = false;
|
|
339
|
+
var pendingFullSnapshotSynchronousFallbackAttempted = false;
|
|
340
|
+
var pendingFullSnapshotIsInitial = false;
|
|
341
|
+
var pendingFullSnapshotBaselineRecords;
|
|
342
|
+
var pendingFullSnapshotBaselineMutationVersion;
|
|
343
|
+
var fullSnapshotWasPublished = false;
|
|
344
|
+
var domMutationVersion = 0;
|
|
345
|
+
var mutationActivityTargets = new Set();
|
|
346
|
+
var mutationActivityFlushScheduled = false;
|
|
347
|
+
var fullSnapshotCanvasBaselineGeneration = 0;
|
|
348
|
+
var publishedNodeParentByNode = new WeakMap();
|
|
349
|
+
var publicationTokenByNode = new WeakMap();
|
|
350
|
+
var pendingNodeParentByNode = new WeakMap();
|
|
351
|
+
var pendingPublicationTokenByNode = new WeakMap();
|
|
352
|
+
var refreshAndFlushPendingRootForNode = function refreshAndFlushPendingRootForNode() {};
|
|
353
|
+
var currentFullSnapshotPublicationToken = createPublicationToken();
|
|
354
|
+
var previousPublishedReplayTree;
|
|
355
|
+
function getPublishedReplayTree() {
|
|
356
|
+
return {
|
|
357
|
+
$rPublishedNodeParentByNode: publishedNodeParentByNode,
|
|
358
|
+
$rPublicationTokenByNode: publicationTokenByNode,
|
|
359
|
+
$rPendingNodeParentByNode: pendingNodeParentByNode,
|
|
360
|
+
$rPendingPublicationTokenByNode: pendingPublicationTokenByNode,
|
|
361
|
+
$rCurrentFullSnapshotPublicationToken: currentFullSnapshotPublicationToken
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
function restorePreviousPublishedReplayTree() {
|
|
365
|
+
if (!previousPublishedReplayTree) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
publishedNodeParentByNode = previousPublishedReplayTree.$rPublishedNodeParentByNode;
|
|
369
|
+
publicationTokenByNode = previousPublishedReplayTree.$rPublicationTokenByNode;
|
|
370
|
+
pendingNodeParentByNode = previousPublishedReplayTree.$rPendingNodeParentByNode;
|
|
371
|
+
pendingPublicationTokenByNode = previousPublishedReplayTree.$rPendingPublicationTokenByNode;
|
|
372
|
+
currentFullSnapshotPublicationToken = previousPublishedReplayTree.$rCurrentFullSnapshotPublicationToken;
|
|
373
|
+
previousPublishedReplayTree = undefined;
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
function resetPublishedReplayTree() {
|
|
377
|
+
publishedNodeParentByNode = new WeakMap();
|
|
378
|
+
publicationTokenByNode = new WeakMap();
|
|
379
|
+
pendingNodeParentByNode = new WeakMap();
|
|
380
|
+
pendingPublicationTokenByNode = new WeakMap();
|
|
381
|
+
currentFullSnapshotPublicationToken = createPublicationToken();
|
|
382
|
+
}
|
|
383
|
+
function createPublicationToken() {
|
|
384
|
+
return {
|
|
385
|
+
$rPublished: false
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function stageFullSnapshotNodePublication(node, parentNode, publicationToken) {
|
|
389
|
+
publishedNodeParentByNode.set(node, parentNode);
|
|
390
|
+
publicationTokenByNode.set(node, publicationToken);
|
|
391
|
+
}
|
|
392
|
+
function stageMutationNodePublication(node, parentNode, publicationToken) {
|
|
393
|
+
var previousPendingToken = pendingPublicationTokenByNode.get(node);
|
|
394
|
+
if (previousPendingToken && previousPendingToken.$rPublished) {
|
|
395
|
+
publishedNodeParentByNode.set(node, pendingNodeParentByNode.get(node));
|
|
396
|
+
publicationTokenByNode.set(node, previousPendingToken);
|
|
397
|
+
}
|
|
398
|
+
pendingNodeParentByNode.set(node, parentNode);
|
|
399
|
+
pendingPublicationTokenByNode.set(node, publicationToken);
|
|
400
|
+
if (publicationToken && typeof HTMLCanvasElement !== 'undefined' && node instanceof HTMLCanvasElement) {
|
|
401
|
+
if (!publicationToken.$rCanvasNodes) {
|
|
402
|
+
publicationToken.$rCanvasNodes = new Set();
|
|
403
|
+
}
|
|
404
|
+
publicationToken.$rCanvasNodes.add(node);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function isNodePublished(node) {
|
|
408
|
+
if (!node) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
var pendingPublicationToken = pendingPublicationTokenByNode.get(node);
|
|
412
|
+
if (pendingPublicationToken) {
|
|
413
|
+
if (pendingPublicationToken.$rPublished) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
if (!pendingPublicationToken.$rCanceled) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (!publishedNodeParentByNode.has(node)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
var publicationToken = publicationTokenByNode.get(node);
|
|
424
|
+
return Boolean(publicationToken && publicationToken.$rPublished);
|
|
425
|
+
}
|
|
426
|
+
function wasNodePublishedBeforePendingMutation(node) {
|
|
427
|
+
var publicationToken = publicationTokenByNode.get(node);
|
|
428
|
+
return Boolean(publishedNodeParentByNode.has(node) && publicationToken && publicationToken.$rPublished);
|
|
429
|
+
}
|
|
430
|
+
function isNodeQueuedOrPublished(node) {
|
|
431
|
+
if (!node) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
var pendingPublicationToken = pendingPublicationTokenByNode.get(node);
|
|
435
|
+
if (pendingPublicationToken) {
|
|
436
|
+
if (pendingPublicationToken.$rPublished || pendingPublicationToken.$rQueued) {
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
if (!pendingPublicationToken.$rCanceled) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
var publicationToken = publicationTokenByNode.get(node);
|
|
444
|
+
return Boolean(publicationToken && (publicationToken.$rPublished || publicationToken.$rQueued));
|
|
445
|
+
}
|
|
446
|
+
function getPublishedParent(node, includeQueued) {
|
|
447
|
+
var pendingPublicationToken = pendingPublicationTokenByNode.get(node);
|
|
448
|
+
if (pendingPublicationToken && (pendingPublicationToken.$rPublished || includeQueued && pendingPublicationToken.$rQueued && !pendingPublicationToken.$rCanceled)) {
|
|
449
|
+
return pendingNodeParentByNode.get(node);
|
|
450
|
+
}
|
|
451
|
+
return publishedNodeParentByNode.get(node);
|
|
452
|
+
}
|
|
453
|
+
function isNodeInPublishedReplayTree(node, includeQueued) {
|
|
454
|
+
var current = node;
|
|
455
|
+
var depth = 0;
|
|
456
|
+
while (current) {
|
|
457
|
+
if (depth >= MAX_SERIALIZED_NODE_ANCESTOR_DEPTH || !publishedNodeParentByNode.has(current) && !pendingNodeParentByNode.has(current)) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
if (!(includeQueued ? isNodeQueuedOrPublished(current) : isNodePublished(current))) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
var publishedParent = getPublishedParent(current, includeQueued);
|
|
464
|
+
var currentParent;
|
|
465
|
+
try {
|
|
466
|
+
currentParent = getParentNode(current);
|
|
467
|
+
} catch (_) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
if (currentParent !== publishedParent) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
current = currentParent;
|
|
474
|
+
depth += 1;
|
|
475
|
+
}
|
|
476
|
+
return Boolean(node);
|
|
477
|
+
}
|
|
478
|
+
function isNodeInPreviousPublishedReplayTree(node) {
|
|
479
|
+
if (!node || !previousPublishedReplayTree) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
var previousParents = previousPublishedReplayTree.$rPublishedNodeParentByNode;
|
|
483
|
+
var previousTokens = previousPublishedReplayTree.$rPublicationTokenByNode;
|
|
484
|
+
var current = node;
|
|
485
|
+
var depth = 0;
|
|
486
|
+
while (current) {
|
|
487
|
+
if (depth >= MAX_SERIALIZED_NODE_ANCESTOR_DEPTH || !previousParents.has(current)) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
var publicationToken = previousTokens.get(current);
|
|
491
|
+
if (!publicationToken || !publicationToken.$rPublished) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
var publishedParent = previousParents.get(current);
|
|
495
|
+
var currentParent;
|
|
496
|
+
try {
|
|
497
|
+
currentParent = getParentNode(current);
|
|
498
|
+
} catch (_) {
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
if (currentParent !== publishedParent) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
current = currentParent;
|
|
505
|
+
depth += 1;
|
|
506
|
+
}
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
function publishMutationMembership(mutationPayload) {
|
|
510
|
+
var acceptedPublicationTokens = new Set();
|
|
511
|
+
var publicationTokens = mutationPayload.adds.map(function (add) {
|
|
512
|
+
var publicationToken = consumeMutationAddPublicationToken(add);
|
|
513
|
+
if (publicationToken) {
|
|
514
|
+
acceptedPublicationTokens.add(publicationToken);
|
|
515
|
+
}
|
|
516
|
+
return publicationToken;
|
|
517
|
+
});
|
|
518
|
+
mutationPayload.removes.forEach(function (remove) {
|
|
519
|
+
var removedNode = consumeMutationRemoveSourceNode(remove);
|
|
520
|
+
if (removedNode) {
|
|
521
|
+
publishedNodeParentByNode["delete"](removedNode);
|
|
522
|
+
publicationTokenByNode["delete"](removedNode);
|
|
523
|
+
// A move is encoded as remove + add with the same serialized id.
|
|
524
|
+
// Preserve staged destination membership for any node serialized
|
|
525
|
+
// under an accepted add root, including moved descendants.
|
|
526
|
+
if (!acceptedPublicationTokens.has(pendingPublicationTokenByNode.get(removedNode))) {
|
|
527
|
+
pendingNodeParentByNode["delete"](removedNode);
|
|
528
|
+
pendingPublicationTokenByNode["delete"](removedNode);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
publicationTokens.forEach(function (publicationToken) {
|
|
533
|
+
publishMutationAddPublicationToken(publicationToken);
|
|
534
|
+
if (publicationToken && publicationToken.$rCanvasNodes && canvasCommandCapture && canvasCommandCapture.$rRetryPublishedCanvas) {
|
|
535
|
+
publicationToken.$rCanvasNodes.forEach(function (canvas) {
|
|
536
|
+
canvasCommandCapture.$rRetryPublishedCanvas(canvas);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (publicationToken) {
|
|
540
|
+
publicationToken.$rCanvasNodes = undefined;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function discardMutationMembership(mutationPayload) {
|
|
545
|
+
mutationPayload.removes.forEach(function (remove) {
|
|
546
|
+
consumeMutationRemoveSourceNode(remove);
|
|
547
|
+
});
|
|
548
|
+
mutationPayload.adds.forEach(function (add) {
|
|
549
|
+
var publicationToken = consumeMutationAddPublicationToken(add);
|
|
550
|
+
if (publicationToken && !publicationToken.$rPublished) {
|
|
551
|
+
cancelMutationAddPublicationToken(publicationToken);
|
|
552
|
+
}
|
|
553
|
+
if (publicationToken) {
|
|
554
|
+
publicationToken.$rCanvasNodes = undefined;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
function trackDomMutationActivity(target) {
|
|
559
|
+
if (suppressRecordsUntilFullSnapshot && previousReplayTreeAdmissionActive) {
|
|
560
|
+
pendingFullSnapshotTimestamp = Math.max(typeof pendingFullSnapshotTimestamp === 'number' ? pendingFullSnapshotTimestamp : 0, timeStampNow());
|
|
561
|
+
}
|
|
562
|
+
if (suppressRecordsUntilFullSnapshot && pendingFullSnapshotCanBeDiscarded) {
|
|
563
|
+
// DOM mutation payloads are serialized against the pending tree and
|
|
564
|
+
// cannot also be replayed safely against the previous tree. Promote the
|
|
565
|
+
// optional transaction so it cannot abandon after retiring that change.
|
|
566
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
567
|
+
pendingFullSnapshotRestartRequested = true;
|
|
568
|
+
}
|
|
569
|
+
domMutationVersion += 1;
|
|
570
|
+
if (!target || mutationActivityFlushScheduled || recordStopping || recordStopped) {
|
|
571
|
+
if (target) {
|
|
572
|
+
mutationActivityTargets.add(target);
|
|
573
|
+
}
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
mutationActivityTargets.add(target);
|
|
577
|
+
mutationActivityFlushScheduled = true;
|
|
578
|
+
setTimeout(function () {
|
|
579
|
+
mutationActivityFlushScheduled = false;
|
|
580
|
+
var activeTargets = mutationActivityTargets;
|
|
581
|
+
mutationActivityTargets = new Set();
|
|
582
|
+
if (activeTargets.size > 1 && !recordStopping && !recordStopped && !suppressRecordsUntilFullSnapshot && !mutationSourceFlushInProgress) {
|
|
583
|
+
flushMutations();
|
|
584
|
+
}
|
|
585
|
+
}, MUTATION_EMIT_DELAY_MS);
|
|
586
|
+
}
|
|
587
|
+
function captureDynamicShadowRoot(shadowRoot, host) {
|
|
588
|
+
if (recordStopping || recordStopped) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
var hostIsConnected;
|
|
592
|
+
try {
|
|
593
|
+
hostIsConnected = host.isConnected;
|
|
594
|
+
} catch (_) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (!hostIsConnected) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// attachShadow() itself does not enqueue a document MutationRecord. Mark
|
|
602
|
+
// the active full-snapshot transaction dirty so a root attached after its
|
|
603
|
+
// host was traversed cannot be omitted from the published baseline.
|
|
604
|
+
trackDomMutationActivity();
|
|
605
|
+
if (suppressRecordsUntilFullSnapshot) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// An unpublished host will be serialized by its pending outer add, which
|
|
610
|
+
// naturally includes the new root. Refresh and synchronously drain the
|
|
611
|
+
// owning document/shadow mutation controller before returning from
|
|
612
|
+
// attachShadow(), so children appended immediately afterwards are
|
|
613
|
+
// observed behind a published host/root boundary.
|
|
614
|
+
if (!isNodeQueuedOrPublished(host)) {
|
|
615
|
+
var pendingHostFlushResult = refreshAndFlushPendingRootForNode(host);
|
|
616
|
+
if (typeof pendingHostFlushResult === 'undefined' && shadowRootsController.refreshAndFlushPendingRootForNode) {
|
|
617
|
+
pendingHostFlushResult = shadowRootsController.refreshAndFlushPendingRootForNode(host);
|
|
618
|
+
}
|
|
619
|
+
if (pendingHostFlushResult === true) {
|
|
620
|
+
// The rebuilt host add contains the empty ShadowRoot inline and its
|
|
621
|
+
// publication token owns the provisional shadow observer. Commit or
|
|
622
|
+
// roll it back before application code can append the first child.
|
|
623
|
+
flushPendingMutations();
|
|
624
|
+
}
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// A host add can still be waiting in the mutation emit buffer here.
|
|
629
|
+
// Resolve that structural dependency before creating the shadow-root add:
|
|
630
|
+
// if the host record is rejected synchronously, accepting a later shadow
|
|
631
|
+
// record would reference a parent id that the replay backend never saw.
|
|
632
|
+
flushPendingMutations();
|
|
633
|
+
if (!isNodeInPublishedReplayTree(host)) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
var hostPrivacyLevel = getNodePrivacyLevel(host, configuration.defaultPrivacyLevel);
|
|
637
|
+
if (hostPrivacyLevel === NodePrivacyLevel.HIDDEN || hostPrivacyLevel === NodePrivacyLevel.IGNORE) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
var publicationToken = createMutationAddPublicationToken(shadowRootsController);
|
|
641
|
+
var serializerTask = createMutationSerializerTask(shadowRoot, {
|
|
642
|
+
serializationContext: {
|
|
643
|
+
status: SerializationContextStatus.MUTATION,
|
|
644
|
+
shadowRootsController: shadowRootsController,
|
|
645
|
+
publicationToken: publicationToken
|
|
646
|
+
},
|
|
647
|
+
parentNodePrivacyLevel: hostPrivacyLevel,
|
|
648
|
+
configuration: configuration,
|
|
649
|
+
onSerializedNode: function onSerializedNode(node, parentNode) {
|
|
650
|
+
stageMutationNodePublication(node, parentNode, publicationToken);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
if (!serializerTask || !serializerTask.advance(getPerformanceTime() + FULL_SNAPSHOT_SERIALIZATION_SLICE_MS, DYNAMIC_SHADOW_ROOT_SERIALIZATION_MAX_NODE_COUNT, DYNAMIC_SHADOW_ROOT_SERIALIZATION_MAX_APPROX_BYTES) || serializerTask.isMaxNodeCountReached || serializerTask.isMaxApproxBytesReached || serializerTask.isMaxDepthReached || serializerTask.isMaxNodeComplexityReached) {
|
|
654
|
+
cancelMutationAddPublicationToken(publicationToken);
|
|
655
|
+
beginAdmissionGapRecovery('dynamic_shadow_root_serialization');
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
var add = {
|
|
659
|
+
parentId: getSerializedNodeId(host),
|
|
660
|
+
nextId: null,
|
|
661
|
+
node: serializerTask.serializedNode
|
|
662
|
+
};
|
|
663
|
+
publicationToken.$rQueued = true;
|
|
664
|
+
registerMutationAddPublicationToken(add, publicationToken);
|
|
665
|
+
mutationCb({
|
|
666
|
+
adds: [add],
|
|
667
|
+
removes: [],
|
|
668
|
+
texts: [],
|
|
669
|
+
attributes: []
|
|
670
|
+
});
|
|
671
|
+
// attachShadow() returns control to the application immediately. Publish
|
|
672
|
+
// the empty root boundary first so synchronous children added by the
|
|
673
|
+
// caller can be observed without ever overtaking their parent root.
|
|
674
|
+
flushPendingMutations();
|
|
675
|
+
}
|
|
676
|
+
var mutationLocalDropTelemetryReported = false;
|
|
34
677
|
var updateReplayPerformanceStats = function updateReplayPerformanceStats(delta) {
|
|
35
|
-
|
|
678
|
+
if (false) {
|
|
679
|
+
accumulateReplayPerformanceStats(replayPerformanceStats, delta);
|
|
680
|
+
} else if (!mutationLocalDropTelemetryReported) {
|
|
681
|
+
mutationLocalDropTelemetryReported = true;
|
|
682
|
+
addTelemetryDebug('Session Replay record discarded.', {
|
|
683
|
+
reason: delta
|
|
684
|
+
});
|
|
685
|
+
}
|
|
36
686
|
};
|
|
687
|
+
var mutationSourceFlushInProgress = false;
|
|
688
|
+
var mutationFlushDocumentPending = false;
|
|
689
|
+
var mutationSourceFlushContinuationTimeout;
|
|
37
690
|
var mutationCb = function mutationCb(mutation) {
|
|
38
|
-
|
|
691
|
+
var mutationMeasurements = measureMutationPayload(mutation);
|
|
692
|
+
if (hasOversizedMutationEntry(mutationMeasurements)) {
|
|
693
|
+
if (hasStructuralMutationEntries(mutation)) {
|
|
694
|
+
// An oversized add/remove cannot be partitioned independently from
|
|
695
|
+
// structural work that may have arrived in another observer callback.
|
|
696
|
+
// A move is reported as remove + add, and emitting only the bounded
|
|
697
|
+
// half would make the player delete a node whose destination was
|
|
698
|
+
// never published. Discard the complete local recovery window and
|
|
699
|
+
// require a replacement baseline. Mandatory recovery also holds (and
|
|
700
|
+
// eventually discards) the current segment, covering a structural
|
|
701
|
+
// prefix that may already have been admitted before this callback.
|
|
702
|
+
discardPendingMutationPayload();
|
|
703
|
+
discardPendingMutationAdmissions();
|
|
704
|
+
discardMutationMembership(mutation);
|
|
705
|
+
beginAdmissionGapRecovery('oversized_structural_mutation');
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
var mutationPartition = partitionMutationPayloadByEntrySize(mutation, mutationMeasurements);
|
|
709
|
+
// Preserve safe work that was already waiting to be emitted, then replace
|
|
710
|
+
// the dropped mutation with a new DOM baseline. Never merge an
|
|
711
|
+
// indivisible oversized entry into the pending payload: doing so would
|
|
712
|
+
// retain it in debug history and make the segment layer stringify it
|
|
713
|
+
// before eventually rejecting it.
|
|
714
|
+
flushPendingMutations();
|
|
715
|
+
if (hasMutationEntries(mutationPartition.mutation)) {
|
|
716
|
+
pendingMutationPayload = mergeMutationPayloads(undefined, mutationPartition.mutation, mutationPartition.measurements);
|
|
717
|
+
flushPendingMutations();
|
|
718
|
+
}
|
|
719
|
+
requestFullSnapshotAfterMutationDrop({
|
|
720
|
+
reason: 'oversized_non_structural_mutation'
|
|
721
|
+
});
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
if (!mutationSourceFlushInProgress && pendingMutationPayload && shouldFlushPendingMutationPayloadBeforeMerge(pendingMutationPayload, mutation, mutationMeasurements.approxBytes, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation)) {
|
|
39
725
|
flushPendingMutations();
|
|
40
726
|
}
|
|
41
|
-
pendingMutationPayload = mergeMutationPayloads(pendingMutationPayload, mutation);
|
|
727
|
+
pendingMutationPayload = mergeMutationPayloads(pendingMutationPayload, mutation, mutationMeasurements);
|
|
42
728
|
scheduleMutationEmit();
|
|
43
729
|
};
|
|
44
730
|
function scheduleMutationEmit() {
|
|
@@ -47,284 +733,1895 @@ export function record(options) {
|
|
|
47
733
|
}
|
|
48
734
|
pendingMutationTimeout = setTimeout(function () {
|
|
49
735
|
pendingMutationTimeout = undefined;
|
|
736
|
+
if (mutationFlushDocumentPending) {
|
|
737
|
+
scheduleMutationSourceFlushContinuation();
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
50
740
|
flushPendingMutations();
|
|
51
741
|
}, MUTATION_EMIT_DELAY_MS);
|
|
52
742
|
}
|
|
743
|
+
function wasLastEmitBackpressured() {
|
|
744
|
+
return Boolean(lastEmitWasLocallyBackpressured || options.$rWasLastEmitBackpressured && options.$rWasLastEmitBackpressured());
|
|
745
|
+
}
|
|
746
|
+
function scheduleMutationAdmissionRetry() {
|
|
747
|
+
scheduleMutationAdmissionDrain(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
748
|
+
}
|
|
749
|
+
function scheduleMutationAdmissionContinuation() {
|
|
750
|
+
scheduleMutationAdmissionDrain(0);
|
|
751
|
+
}
|
|
752
|
+
function scheduleMutationAdmissionDrain(delay) {
|
|
753
|
+
if (pendingMutationAdmissionTimeout !== undefined || !pendingMutationAdmissionQueue.length || recordStopping || recordStopped) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
pendingMutationAdmissionTimeout = setTimeout(function () {
|
|
757
|
+
pendingMutationAdmissionTimeout = undefined;
|
|
758
|
+
drainPendingMutationAdmissions();
|
|
759
|
+
}, delay);
|
|
760
|
+
}
|
|
761
|
+
function discardPendingMutationAdmissions() {
|
|
762
|
+
if (pendingMutationAdmissionTimeout !== undefined) {
|
|
763
|
+
clearTimeout(pendingMutationAdmissionTimeout);
|
|
764
|
+
pendingMutationAdmissionTimeout = undefined;
|
|
765
|
+
}
|
|
766
|
+
pendingMutationAdmissionQueue.forEach(function (entry) {
|
|
767
|
+
entry.$rPendingAdmission = false;
|
|
768
|
+
discardMutationMembership(entry[0]);
|
|
769
|
+
});
|
|
770
|
+
pendingMutationAdmissionQueue = [];
|
|
771
|
+
pendingMutationAdmissionApproxBytes = 0;
|
|
772
|
+
}
|
|
773
|
+
function isPureAddMutationPayload(mutationPayload) {
|
|
774
|
+
return Boolean(mutationPayload && mutationPayload.adds.length && !mutationPayload.removes.length && !mutationPayload.texts.length && !mutationPayload.attributes.length);
|
|
775
|
+
}
|
|
776
|
+
function tryMergePendingPureAddMutationAdmission(entry) {
|
|
777
|
+
var previousEntry = pendingMutationAdmissionQueue[pendingMutationAdmissionQueue.length - 1];
|
|
778
|
+
var mutationPayload = entry[0];
|
|
779
|
+
if (!previousEntry || previousEntry[3] || previousEntry.$rReferencedByDeferredRecord || !isPureAddMutationPayload(previousEntry[0]) || !isPureAddMutationPayload(mutationPayload) || previousEntry[1] + entry[1] > MAX_MUTATION_EMIT_APPROX_BYTES || pendingMutationAdmissionApproxBytes + entry[1] > MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES) {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// The previous record has been assembled but never offered to the
|
|
784
|
+
// segment encoder, so its mutation arrays have not been serialized or
|
|
785
|
+
// cached yet. Keep one exact admission boundary for adjacent independent
|
|
786
|
+
// adds while retaining insertion order and every publication token.
|
|
787
|
+
// Never mutate an attempted entry: a rejected encoder admission can cache
|
|
788
|
+
// its serialized bytes for the exact-object retry contract.
|
|
789
|
+
mutationPayload.adds.forEach(function (addMutation) {
|
|
790
|
+
previousEntry[0].adds.push(addMutation);
|
|
791
|
+
});
|
|
792
|
+
previousEntry[1] += entry[1];
|
|
793
|
+
pendingMutationAdmissionApproxBytes += entry[1];
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
function enqueueMutationEntriesForAdmission(mutationEntries) {
|
|
797
|
+
if (!mutationEntries.length) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (suppressRecordsUntilFullSnapshot || recordStopped) {
|
|
801
|
+
mutationEntries.forEach(function (entry) {
|
|
802
|
+
discardMutationMembership(entry[0]);
|
|
803
|
+
});
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
for (var entryIndex = 0; entryIndex < mutationEntries.length; entryIndex += 1) {
|
|
807
|
+
var entry = mutationEntries[entryIndex];
|
|
808
|
+
if (tryMergePendingPureAddMutationAdmission(entry)) {
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
if (pendingMutationAdmissionQueue.length + 1 > MAX_PENDING_MUTATION_ADMISSION_PAYLOADS || pendingMutationAdmissionApproxBytes + entry[1] > MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES) {
|
|
812
|
+
var rejectedTail = mutationEntries.slice(entryIndex);
|
|
813
|
+
rejectedTail.forEach(function (rejectedEntry) {
|
|
814
|
+
discardMutationMembership(rejectedEntry[0]);
|
|
815
|
+
});
|
|
816
|
+
discardPendingMutationAdmissions();
|
|
817
|
+
beginAdmissionGapRecovery('mutation_admission_queue_overflow');
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
entry[2] = assembleIncrementalSnapshot(IncrementalSource.Mutation, entry[0]);
|
|
821
|
+
entry.$rPendingAdmission = true;
|
|
822
|
+
pendingMutationAdmissionQueue.push(entry);
|
|
823
|
+
pendingMutationAdmissionApproxBytes += entry[1];
|
|
824
|
+
}
|
|
825
|
+
// Assemble the complete callback batch before attempting admission. A
|
|
826
|
+
// per-entry drain would reset the slice budget for every push and could
|
|
827
|
+
// synchronously consume the full pending-raw window.
|
|
828
|
+
if (pendingMutationAdmissionTimeout === undefined) {
|
|
829
|
+
drainPendingMutationAdmissions();
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function drainPendingMutationAdmissions() {
|
|
833
|
+
if (pendingMutationAdmissionTimeout !== undefined) {
|
|
834
|
+
clearTimeout(pendingMutationAdmissionTimeout);
|
|
835
|
+
pendingMutationAdmissionTimeout = undefined;
|
|
836
|
+
}
|
|
837
|
+
if (suppressRecordsUntilFullSnapshot) {
|
|
838
|
+
if (pendingFullSnapshotBaselineRecords) {
|
|
839
|
+
// Serialization is complete and the exact baseline transaction is
|
|
840
|
+
// only waiting for encoder capacity. Keep later DOM records ordered
|
|
841
|
+
// behind it; once the same baseline objects are admitted they can
|
|
842
|
+
// drain normally instead of forcing a re-serialization loop.
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
// The replacement baseline supersedes every queued mutation. Retrying a
|
|
846
|
+
// formerly backpressured record through emit() while suppression is
|
|
847
|
+
// active would look like a permanent rejection and recursively start a
|
|
848
|
+
// second full-snapshot transaction before the first task exists.
|
|
849
|
+
discardPendingMutationAdmissions();
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
if (recordStopped || !pendingMutationAdmissionQueue.length) {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
var drainStartedAt = getPerformanceTime();
|
|
856
|
+
var drainedApproxBytes = 0;
|
|
857
|
+
while (pendingMutationAdmissionQueue.length) {
|
|
858
|
+
var entry = pendingMutationAdmissionQueue[0];
|
|
859
|
+
var mutationPayload = entry[0];
|
|
860
|
+
if (false) {
|
|
861
|
+
lastDomMutationForDebug = createDomMutationDebugSummary(mutationPayload);
|
|
862
|
+
pushCanvasDebugHistoryEntry(domMutationHistoryForDebug, lastDomMutationForDebug, DOM_MUTATION_DEBUG_HISTORY_LIMIT);
|
|
863
|
+
}
|
|
864
|
+
entry[3] = true;
|
|
865
|
+
var wasAdmitted;
|
|
866
|
+
mutationAdmissionEmitInProgress = true;
|
|
867
|
+
try {
|
|
868
|
+
wasAdmitted = emit(entry[2]);
|
|
869
|
+
} finally {
|
|
870
|
+
mutationAdmissionEmitInProgress = false;
|
|
871
|
+
}
|
|
872
|
+
if (wasAdmitted) {
|
|
873
|
+
pendingMutationAdmissionQueue.shift();
|
|
874
|
+
entry.$rPendingAdmission = false;
|
|
875
|
+
pendingMutationAdmissionApproxBytes -= entry[1];
|
|
876
|
+
var previousMutationPublicationBarrier = mutationPublicationBarrier;
|
|
877
|
+
mutationPublicationBarrier = entry;
|
|
878
|
+
try {
|
|
879
|
+
publishMutationMembership(mutationPayload);
|
|
880
|
+
} finally {
|
|
881
|
+
mutationPublicationBarrier = previousMutationPublicationBarrier;
|
|
882
|
+
}
|
|
883
|
+
drainedApproxBytes += entry[1];
|
|
884
|
+
var mutationDrainState = {
|
|
885
|
+
$rStartedAt: drainStartedAt,
|
|
886
|
+
$rApproxBytes: drainedApproxBytes
|
|
887
|
+
};
|
|
888
|
+
var deferredBarrierWasDrained = flushDeferredRecords(entry, mutationDrainState);
|
|
889
|
+
drainedApproxBytes = mutationDrainState.$rApproxBytes;
|
|
890
|
+
if (suppressRecordsUntilFullSnapshot || recordStopped) {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
if (!deferredBarrierWasDrained) {
|
|
894
|
+
// The dependent records use the same time/byte slice and retry
|
|
895
|
+
// scheduler. Mutation admission resumes only after this exact
|
|
896
|
+
// structural barrier has drained.
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
if (pendingMutationAdmissionQueue.length && (drainedApproxBytes >= MUTATION_ADMISSION_DRAIN_SLICE_APPROX_BYTES || getPerformanceTime() - drainStartedAt >= MUTATION_ADMISSION_DRAIN_SLICE_MS)) {
|
|
900
|
+
scheduleMutationAdmissionContinuation();
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
if (wasLastEmitBackpressured()) {
|
|
906
|
+
scheduleMutationAdmissionRetry();
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
// The rejected payload was never admitted. Discard it and every later
|
|
910
|
+
// payload so no dependent parent/next id can overtake the gap. A generic
|
|
911
|
+
// structural rejection keeps the conservative baseline recovery; only
|
|
912
|
+
// transient encoder backpressure is retried in place.
|
|
913
|
+
discardPendingMutationAdmissions();
|
|
914
|
+
beginAdmissionGapRecovery('mutation_admission_rejected');
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
return true;
|
|
918
|
+
}
|
|
53
919
|
function flushPendingMutations() {
|
|
54
920
|
if (pendingMutationTimeout) {
|
|
55
921
|
clearTimeout(pendingMutationTimeout);
|
|
56
922
|
pendingMutationTimeout = undefined;
|
|
57
923
|
}
|
|
58
924
|
if (!pendingMutationPayload) {
|
|
925
|
+
drainPendingMutationAdmissions();
|
|
59
926
|
return;
|
|
60
927
|
}
|
|
61
|
-
var
|
|
928
|
+
var mutationPayloadToFlush = pendingMutationPayload;
|
|
929
|
+
var splitResult = splitPendingMutationPayloadForEmit(mutationPayloadToFlush, pendingPublicationTokenByNode, wasNodePublishedBeforePendingMutation);
|
|
62
930
|
pendingMutationPayload = undefined;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
931
|
+
var mutationEntries = splitResult.mutationEntries;
|
|
932
|
+
if (!mutationEntries.length) {
|
|
933
|
+
discardMutationMembership(materializeMutationPayload(mutationPayloadToFlush));
|
|
934
|
+
}
|
|
935
|
+
if (false) {
|
|
936
|
+
updateReplayPerformanceStats(mutationEntries.reduce(function (stats, mutationEntry) {
|
|
937
|
+
var mutationPayload = mutationEntry[0];
|
|
938
|
+
stats.mutationCallbackCount += 1;
|
|
939
|
+
stats.mutationRecordCount += countMutationPayloadRecords(mutationPayload);
|
|
940
|
+
stats.mutationAddCount += mutationPayload.adds.length;
|
|
941
|
+
stats.mutationRemoveCount += mutationPayload.removes.length;
|
|
942
|
+
stats.mutationTextCount += mutationPayload.texts.length;
|
|
943
|
+
stats.mutationAttributeCount += mutationPayload.attributes.length;
|
|
944
|
+
return stats;
|
|
945
|
+
}, {
|
|
946
|
+
mutationCallbackCount: 0,
|
|
947
|
+
mutationRecordCount: 0,
|
|
948
|
+
mutationAddCount: 0,
|
|
949
|
+
mutationRemoveCount: 0,
|
|
950
|
+
mutationTextCount: 0,
|
|
951
|
+
mutationAttributeCount: 0
|
|
952
|
+
}));
|
|
953
|
+
}
|
|
954
|
+
enqueueMutationEntriesForAdmission(mutationEntries);
|
|
955
|
+
if (splitResult.hasOversizedEntry) {
|
|
956
|
+
requestFullSnapshotAfterMutationDrop({
|
|
957
|
+
reason: 'split_oversized_mutation_entry'
|
|
958
|
+
});
|
|
959
|
+
}
|
|
84
960
|
}
|
|
85
961
|
var inputCb = function inputCb(s) {
|
|
86
962
|
emit(assembleIncrementalSnapshot(IncrementalSource.Input, s));
|
|
87
963
|
};
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
964
|
+
var mutationResourceBudget = createMutationResourceBudget();
|
|
965
|
+
var shadowRootsController;
|
|
966
|
+
try {
|
|
967
|
+
shadowRootsController = initShadowRootsController(configuration, {
|
|
968
|
+
mutationCb: mutationCb,
|
|
969
|
+
mutationPerfCb: updateReplayPerformanceStats,
|
|
970
|
+
mutationOverflowCb: requestFullSnapshotAfterMutationDrop,
|
|
971
|
+
mutationActivityCb: trackDomMutationActivity,
|
|
972
|
+
inputCb: inputCb,
|
|
973
|
+
isNodeIgnored: isObservedNodeIgnored,
|
|
974
|
+
isInputNodeIgnored: isNodeIgnoredForObserver,
|
|
975
|
+
isNodePublished: isNodeQueuedOrPublished,
|
|
976
|
+
mutationNodeSerializationCb: stageMutationNodePublication,
|
|
977
|
+
mutationResourceBudget: mutationResourceBudget,
|
|
978
|
+
shadowRootCreatedCb: captureDynamicShadowRoot
|
|
979
|
+
});
|
|
980
|
+
} catch (error) {
|
|
981
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
982
|
+
}
|
|
983
|
+
registerInitializationCleanup(shadowRootsController.stop);
|
|
984
|
+
function isNodeIgnored(node, includeQueued) {
|
|
985
|
+
try {
|
|
986
|
+
return !isNodeInPublishedReplayTree(node, includeQueued);
|
|
987
|
+
} catch (_) {
|
|
988
|
+
// Publication membership is part of the replay baseline contract. If it
|
|
989
|
+
// cannot be established, fail closed instead of emitting a stale id.
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
function isObservedNodeIgnored(node, includeQueued) {
|
|
994
|
+
var ignored = isNodeIgnored(node, includeQueued);
|
|
995
|
+
if (ignored && (pendingFullSnapshotTask || pendingFullSnapshotBaselineRecords) && publishedNodeParentByNode.has(node)) {
|
|
996
|
+
// Input, media, scroll and CSSOM state are not DOM mutations. If an
|
|
997
|
+
// observer ignores one after the node was serialized, rebuild the
|
|
998
|
+
// mixed-time baseline so the state change is represented by the next
|
|
999
|
+
// attempt. This
|
|
1000
|
+
// also covers an exact baseline waiting for encoder capacity: the
|
|
1001
|
+
// unpublished tree cannot accept an incremental state record there.
|
|
1002
|
+
pendingFullSnapshotRestartRequested = true;
|
|
1003
|
+
}
|
|
1004
|
+
return ignored;
|
|
1005
|
+
}
|
|
1006
|
+
function isNodeIgnoredForObserver(node, mutationAssembly) {
|
|
1007
|
+
if (mutationAssembly) {
|
|
1008
|
+
return isObservedNodeIgnored(node, true);
|
|
1009
|
+
}
|
|
1010
|
+
if (captureRecordsAgainstPreviousReplayTree && !mutationSourceFlushInProgress) {
|
|
1011
|
+
// Native DOM records queued earlier in the same task must be observed
|
|
1012
|
+
// before admitting this state record against the previous replay tail.
|
|
1013
|
+
// The activity callback promotes an optional baseline when necessary.
|
|
1014
|
+
capturePendingMutationActivityForPreviousReplayTree(false);
|
|
1015
|
+
}
|
|
1016
|
+
var ignored = isObservedNodeIgnored(node, true);
|
|
1017
|
+
var pendingPublicationToken = pendingPublicationTokenByNode.get(node);
|
|
1018
|
+
if (pendingPublicationToken && !pendingPublicationToken.$rPublished && !pendingPublicationToken.$rCanceled) {
|
|
1019
|
+
if (!pendingPublicationToken.$rQueued) {
|
|
1020
|
+
// A time-sliced add serializer may already have walked this node while
|
|
1021
|
+
// its root is not publishable yet. Rebuild that root from current DOM
|
|
1022
|
+
// state so input/CSSOM changes between slices are not omitted.
|
|
1023
|
+
flushMutationRootForNode(node);
|
|
1024
|
+
} else if (pendingMutationPayload) {
|
|
1025
|
+
// The add is complete but still waiting in the 16 ms mutation emit
|
|
1026
|
+
// buffer. Move it into admission before the dependent state callback;
|
|
1027
|
+
// the state will then emit after a successful add or bind its barrier.
|
|
1028
|
+
flushPendingMutations();
|
|
1029
|
+
}
|
|
1030
|
+
ignored = isObservedNodeIgnored(node, true);
|
|
1031
|
+
}
|
|
1032
|
+
if (ignored && captureRecordsAgainstPreviousReplayTree && isNodeInPreviousPublishedReplayTree(node)) {
|
|
1033
|
+
// The candidate tree is unpublished, but this node still belongs to the
|
|
1034
|
+
// previous replay tail. Let the shared admission path publish its state
|
|
1035
|
+
// before the replacement baseline (or queue it on encoder backpressure).
|
|
1036
|
+
return false;
|
|
1037
|
+
}
|
|
1038
|
+
return ignored;
|
|
1039
|
+
}
|
|
1040
|
+
function isNodeIgnoredForStatelessObserver(node) {
|
|
1041
|
+
if (captureRecordsAgainstPreviousReplayTree && !mutationSourceFlushInProgress) {
|
|
1042
|
+
capturePendingMutationActivityForPreviousReplayTree(false);
|
|
1043
|
+
}
|
|
1044
|
+
var ignored = isNodeIgnored(node);
|
|
1045
|
+
if (ignored && captureRecordsAgainstPreviousReplayTree && isNodeInPreviousPublishedReplayTree(node)) {
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
return ignored;
|
|
1049
|
+
}
|
|
1050
|
+
function getActiveSerializedNodeId(node) {
|
|
1051
|
+
if (isNodeIgnored(node)) {
|
|
1052
|
+
return undefined;
|
|
1053
|
+
}
|
|
1054
|
+
return getSerializedNodeId(node);
|
|
1055
|
+
}
|
|
1056
|
+
function filterActiveSerializedCanvases(canvases) {
|
|
1057
|
+
return canvases.filter(function (canvas) {
|
|
1058
|
+
return !isNodeIgnored(canvas);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function getActiveSerializedCanvases(maxScanCount) {
|
|
1062
|
+
return filterActiveSerializedCanvases(getSerializedCanvasNodes(maxScanCount));
|
|
1063
|
+
}
|
|
92
1064
|
var lastAutoCanvasSnapshotResult;
|
|
93
|
-
var autoCanvasSnapshotDebugHistoryForDebug = [];
|
|
1065
|
+
var autoCanvasSnapshotDebugHistoryForDebug = false ? [] : undefined;
|
|
94
1066
|
var lastCanvasMutationForDebug;
|
|
95
|
-
var canvasMutationHistoryForDebug = [];
|
|
1067
|
+
var canvasMutationHistoryForDebug = false ? [] : undefined;
|
|
96
1068
|
var lastDomMutationForDebug;
|
|
97
|
-
var domMutationHistoryForDebug = [];
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
1069
|
+
var domMutationHistoryForDebug = false ? [] : undefined;
|
|
1070
|
+
function handleAutoCanvasSnapshotDebug(result) {
|
|
1071
|
+
var keepSessionAliveTriggered = false;
|
|
1072
|
+
if (shouldKeepSessionAliveAfterAutoCanvasSnapshot(result) && options.sessionManager && options.sessionManager.keepSessionAlive) {
|
|
1073
|
+
options.sessionManager.keepSessionAlive();
|
|
1074
|
+
keepSessionAliveTriggered = true;
|
|
1075
|
+
}
|
|
1076
|
+
if (false) {
|
|
1077
|
+
lastAutoCanvasSnapshotResult = cloneAutoCanvasSnapshotDebugResult(result, keepSessionAliveTriggered);
|
|
1078
|
+
pushCanvasDebugHistoryEntry(autoCanvasSnapshotDebugHistoryForDebug, lastAutoCanvasSnapshotResult);
|
|
105
1079
|
}
|
|
1080
|
+
}
|
|
1081
|
+
function handleCanvasMutationDebug(result) {
|
|
1082
|
+
lastCanvasMutationForDebug = cloneCanvasMutationDebugResult(result);
|
|
1083
|
+
pushCanvasDebugHistoryEntry(canvasMutationHistoryForDebug, lastCanvasMutationForDebug);
|
|
1084
|
+
}
|
|
1085
|
+
var shouldUseCanvasCommandCapture = shouldUseCommandCapture(configuration);
|
|
1086
|
+
var baseCanvasEncodeBridge;
|
|
1087
|
+
var webGLReplayRuntime;
|
|
1088
|
+
var canvasEncodeBridge;
|
|
1089
|
+
try {
|
|
1090
|
+
var createCanvasEncodeBridgeImpl = false ? options.createCanvasEncodeBridge || createCanvasEncodeBridge : createCanvasEncodeBridge;
|
|
1091
|
+
var createSessionReplayWebGLRuntimeImpl = false ? options.createSessionReplayWebGLRuntime || createSessionReplayWebGLRuntime : createSessionReplayWebGLRuntime;
|
|
1092
|
+
baseCanvasEncodeBridge = createCanvasEncodeBridgeImpl(configuration);
|
|
1093
|
+
webGLReplayRuntime = createSessionReplayWebGLRuntimeImpl(configuration, baseCanvasEncodeBridge, reportWebGLReplayFailure);
|
|
1094
|
+
canvasEncodeBridge = webGLReplayRuntime[0] || baseCanvasEncodeBridge;
|
|
1095
|
+
} catch (error) {
|
|
1096
|
+
if (baseCanvasEncodeBridge && baseCanvasEncodeBridge.stop) {
|
|
1097
|
+
baseCanvasEncodeBridge.stop();
|
|
1098
|
+
}
|
|
1099
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1100
|
+
}
|
|
1101
|
+
registerInitializationCleanup(canvasEncodeBridge.stop);
|
|
1102
|
+
var canvasObserver;
|
|
1103
|
+
try {
|
|
1104
|
+
var createCanvasObserverImpl = false ? options.createCanvasObserver || createCanvasObserver : createCanvasObserver;
|
|
1105
|
+
canvasObserver = createCanvasObserverImpl({
|
|
1106
|
+
configuration: configuration,
|
|
1107
|
+
emit: emit,
|
|
1108
|
+
encodeBridge: canvasEncodeBridge,
|
|
1109
|
+
isNodeActive: function isNodeActive(node) {
|
|
1110
|
+
return !isNodeIgnored(node);
|
|
1111
|
+
},
|
|
1112
|
+
flushMutations: function flushMutations(canvas) {
|
|
1113
|
+
return flushMutationRootForNode(canvas);
|
|
1114
|
+
},
|
|
1115
|
+
onMutationDebug: false ? handleCanvasMutationDebug : undefined
|
|
1116
|
+
});
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1119
|
+
}
|
|
1120
|
+
registerInitializationCleanup(canvasObserver.stop);
|
|
1121
|
+
var startCanvasSnapshotLoop = false ? options.startContinuousCanvasSnapshotLoop || startContinuousCanvasSnapshotLoop : startContinuousCanvasSnapshotLoop;
|
|
1122
|
+
var canvasSnapshotLoop;
|
|
1123
|
+
try {
|
|
1124
|
+
canvasSnapshotLoop = shouldUseCanvasCommandCapture ? {
|
|
1125
|
+
stop: function stop() {},
|
|
1126
|
+
reset: function reset() {}
|
|
1127
|
+
} : startCanvasSnapshotLoop({
|
|
1128
|
+
configuration: configuration,
|
|
1129
|
+
getCanvases: function getCanvases(maxScanCount) {
|
|
1130
|
+
return getActiveSerializedCanvases(maxScanCount).filter(function (canvas) {
|
|
1131
|
+
return !isDrawDrivenWebGLCanvas(canvas);
|
|
1132
|
+
});
|
|
1133
|
+
},
|
|
1134
|
+
getSerializedNodeId: function getSerializedNodeId(canvas) {
|
|
1135
|
+
return getActiveSerializedNodeId(canvas);
|
|
1136
|
+
},
|
|
1137
|
+
onDebug: handleAutoCanvasSnapshotDebug,
|
|
1138
|
+
snapshotCanvas: function snapshotCanvas(canvas) {
|
|
1139
|
+
return snapshotCanvasIfActive(canvas, {
|
|
1140
|
+
trigger: 'auto',
|
|
1141
|
+
scheduler: 'continuous_snapshot'
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1147
|
+
}
|
|
1148
|
+
registerInitializationCleanup(function () {
|
|
1149
|
+
stopCanvasSnapshots(canvasSnapshotLoop);
|
|
106
1150
|
});
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
1151
|
+
var canvasCommandCapture;
|
|
1152
|
+
try {
|
|
1153
|
+
var startCanvasCommandCaptureImpl = false ? options.startCanvasCommandCapture || startCanvasCommandCapture : startCanvasCommandCapture;
|
|
1154
|
+
canvasCommandCapture = startCanvasCommandCaptureImpl({
|
|
1155
|
+
configuration: configuration,
|
|
1156
|
+
emit: emit,
|
|
1157
|
+
snapshotCanvas: function snapshotCanvas(canvas, snapshotOptions) {
|
|
1158
|
+
return snapshotCanvasIfActive(canvas, snapshotOptions);
|
|
1159
|
+
},
|
|
1160
|
+
getCanvases: function getCanvases(maxScanCount) {
|
|
1161
|
+
return getActiveSerializedCanvases(maxScanCount);
|
|
1162
|
+
},
|
|
1163
|
+
getSerializedNodeId: function getSerializedNodeId(canvas) {
|
|
1164
|
+
return getActiveSerializedNodeId(canvas);
|
|
1165
|
+
},
|
|
1166
|
+
onDebug: handleAutoCanvasSnapshotDebug,
|
|
1167
|
+
onMutationDebug: false ? handleCanvasMutationDebug : undefined,
|
|
1168
|
+
flushMutations: function flushMutations(canvas) {
|
|
1169
|
+
return flushMutationRootForNode(canvas);
|
|
1170
|
+
},
|
|
1171
|
+
startPaused: true
|
|
1172
|
+
});
|
|
1173
|
+
} catch (error) {
|
|
1174
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1175
|
+
}
|
|
1176
|
+
var canvasWebGLSnapshotObserver = createNoopObserver();
|
|
1177
|
+
try {
|
|
1178
|
+
var startCanvasWebGLSnapshotObserver = false && options.startCanvasWebGLSnapshotObserver || webGLReplayRuntime[1];
|
|
1179
|
+
if (startCanvasWebGLSnapshotObserver) {
|
|
1180
|
+
canvasWebGLSnapshotObserver = startCanvasWebGLSnapshotObserver(function (canvas, snapshotOptions) {
|
|
1181
|
+
return snapshotCanvasIfActive(canvas, snapshotOptions);
|
|
1182
|
+
}, function (canvas) {
|
|
1183
|
+
return getActiveSerializedNodeId(canvas);
|
|
1184
|
+
}, handleAutoCanvasSnapshotDebug) || createNoopObserver();
|
|
1185
|
+
}
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
addTelemetryDebug('Session Replay WebGL observer failed.', {
|
|
1188
|
+
error: String(error)
|
|
1189
|
+
});
|
|
1190
|
+
canvasWebGLSnapshotObserver = createNoopObserver();
|
|
1191
|
+
}
|
|
1192
|
+
registerInitializationCleanup(canvasWebGLSnapshotObserver.stop);
|
|
1193
|
+
// The optional WebGL plugin installs its bootstrap getContext wrapper from
|
|
1194
|
+
// plugin.onInit(), before command capture wraps the same prototype. Always
|
|
1195
|
+
// unwind command capture first so the WebGL observer can still recognize
|
|
1196
|
+
// and restore its own wrapper. Keep initialization rollback in the same
|
|
1197
|
+
// order (cleanup tasks run in reverse registration order).
|
|
1198
|
+
registerInitializationCleanup(canvasCommandCapture.stop);
|
|
1199
|
+
function isDrawDrivenWebGLCanvas(canvas) {
|
|
1200
|
+
if (isWebGLReplayCanvas(canvas)) {
|
|
1201
|
+
return true;
|
|
1202
|
+
}
|
|
1203
|
+
try {
|
|
1204
|
+
return !!canvasWebGLSnapshotObserver.isWebGLCanvas(canvas);
|
|
1205
|
+
} catch (_) {
|
|
1206
|
+
// A failing optional plugin must not block the ordinary 2D baseline.
|
|
1207
|
+
return false;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
function snapshotCanvasIfActive(canvas, snapshotOptions) {
|
|
1211
|
+
if (isNodeIgnored(canvas)) {
|
|
1212
|
+
return Promise.resolve({
|
|
1213
|
+
ok: false,
|
|
1214
|
+
reason: 'not_serialized'
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
var isCommandBaselineSnapshot = snapshotOptions && (snapshotOptions.scheduler === 'full_snapshot_baseline' || snapshotOptions.scheduler === 'command_capture' && snapshotOptions.force === true);
|
|
1218
|
+
var snapshotConsistencyToken = shouldUseCanvasCommandCapture && canvasCommandCapture && canvasCommandCapture.createCanvasSnapshotBaselineToken ? canvasCommandCapture.createCanvasSnapshotBaselineToken(canvas) : undefined;
|
|
1219
|
+
var baselineToken = isCommandBaselineSnapshot ? snapshotConsistencyToken : undefined;
|
|
1220
|
+
var effectiveSnapshotOptions = snapshotOptions;
|
|
1221
|
+
if (snapshotConsistencyToken && canvasCommandCapture && canvasCommandCapture.$rIsSnapshotBaselineCurrent) {
|
|
1222
|
+
var originalIsCancelled = effectiveSnapshotOptions && effectiveSnapshotOptions.$rIsCancelled;
|
|
1223
|
+
effectiveSnapshotOptions = assign({}, effectiveSnapshotOptions, {
|
|
1224
|
+
$rIsCancelled: function $rIsCancelled() {
|
|
1225
|
+
if (typeof originalIsCancelled === 'function') {
|
|
1226
|
+
try {
|
|
1227
|
+
if (originalIsCancelled()) {
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
} catch (_) {
|
|
1231
|
+
return true;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
try {
|
|
1235
|
+
return !canvasCommandCapture.$rIsSnapshotBaselineCurrent(canvas, snapshotConsistencyToken);
|
|
1236
|
+
} catch (_) {
|
|
1237
|
+
return true;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
return Promise.resolve(canvasObserver.snapshot(canvas, effectiveSnapshotOptions)).then(function (result) {
|
|
1243
|
+
if (result && result.ok === true && baselineToken && canvasCommandCapture && canvasCommandCapture.markCanvasSnapshotBaseline) {
|
|
1244
|
+
canvasCommandCapture.markCanvasSnapshotBaseline(canvas, baselineToken, effectiveSnapshotOptions.reason || effectiveSnapshotOptions.scheduler);
|
|
1245
|
+
}
|
|
1246
|
+
return result;
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
function createFullSnapshotSerializerTask(serializationContext) {
|
|
1250
|
+
var publicationToken = currentFullSnapshotPublicationToken;
|
|
1251
|
+
var createSerializerTask = false && options.$rCreateFullSnapshotSerializerTask || createMutationSerializerTask;
|
|
1252
|
+
return createSerializerTask(document, {
|
|
1253
|
+
serializationContext: serializationContext,
|
|
1254
|
+
parentNodePrivacyLevel: configuration.defaultPrivacyLevel,
|
|
1255
|
+
configuration: configuration,
|
|
1256
|
+
onSerializedNode: function onSerializedNode(node, parentNode) {
|
|
1257
|
+
stageFullSnapshotNodePublication(node, parentNode, publicationToken);
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
function advanceFullSnapshotSerializerTask(serializerTask, deadline) {
|
|
1262
|
+
var maxNodeCount = Math.min(serializerTask.processedNodeCount + SERIALIZATION_MAX_NODE_COUNT, FULL_SNAPSHOT_SERIALIZATION_MAX_NODE_COUNT);
|
|
1263
|
+
var maxApproxBytes = Math.min(serializerTask.approxBytes + SERIALIZATION_MAX_APPROX_BYTES, FULL_SNAPSHOT_SERIALIZATION_MAX_APPROX_BYTES);
|
|
1264
|
+
var completed = serializerTask.advance(deadline, maxNodeCount, maxApproxBytes);
|
|
1265
|
+
return {
|
|
1266
|
+
completed: completed,
|
|
1267
|
+
isWatermarkReached: !completed && (serializerTask.isMaxDepthReached || serializerTask.isMaxNodeComplexityReached || serializerTask.isMaxNodeCountReached && maxNodeCount >= FULL_SNAPSHOT_SERIALIZATION_MAX_NODE_COUNT || serializerTask.isMaxApproxBytesReached && maxApproxBytes >= FULL_SNAPSHOT_SERIALIZATION_MAX_APPROX_BYTES)
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
function createFullSnapshotBaselineRecords(timestamp, serializedDocument) {
|
|
1271
|
+
var _viewportDimension = getViewportDimension();
|
|
1272
|
+
var width = _viewportDimension.width;
|
|
1273
|
+
var height = _viewportDimension.height;
|
|
1274
|
+
return [{
|
|
1275
|
+
data: {
|
|
1276
|
+
height: height,
|
|
1277
|
+
href: window.location.href,
|
|
1278
|
+
width: width
|
|
1279
|
+
},
|
|
1280
|
+
type: RecordType.Meta,
|
|
1281
|
+
timestamp: timestamp
|
|
1282
|
+
}, {
|
|
1283
|
+
data: {
|
|
1284
|
+
has_focus: document.hasFocus()
|
|
1285
|
+
},
|
|
1286
|
+
type: RecordType.Focus,
|
|
1287
|
+
timestamp: timestamp
|
|
1288
|
+
}, {
|
|
1289
|
+
data: {
|
|
1290
|
+
node: serializedDocument,
|
|
1291
|
+
initialOffset: {
|
|
1292
|
+
left: getScrollX(),
|
|
1293
|
+
top: getScrollY()
|
|
1294
|
+
}
|
|
1295
|
+
},
|
|
1296
|
+
type: RecordType.FullSnapshot,
|
|
1297
|
+
timestamp: timestamp
|
|
1298
|
+
}];
|
|
1299
|
+
}
|
|
1300
|
+
function emitFullSnapshot(baselineRecords, startedAt) {
|
|
1301
|
+
// Baseline admission bypasses emit(). Do not inherit a local DOM-barrier
|
|
1302
|
+
// result from an earlier record: only the segment/encoder result for this
|
|
1303
|
+
// exact baseline may classify its rejection as transient backpressure.
|
|
1304
|
+
lastEmitWasLocallyBackpressured = false;
|
|
1305
|
+
var timestamp = baselineRecords[0].timestamp;
|
|
1306
|
+
var fullSnapshotAccepted;
|
|
1307
|
+
if (rawEmitBaseline) {
|
|
1308
|
+
fullSnapshotAccepted = rawEmitBaseline(baselineRecords) !== false;
|
|
1309
|
+
} else {
|
|
1310
|
+
fullSnapshotAccepted = rawEmit(baselineRecords[0]) !== false && rawEmit(baselineRecords[1]) !== false && rawEmit(baselineRecords[2]) !== false;
|
|
1311
|
+
}
|
|
1312
|
+
if (!fullSnapshotAccepted) {
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
fullSnapshotWasPublished = true;
|
|
1316
|
+
currentFullSnapshotPublicationToken.$rPublished = true;
|
|
1317
|
+
if (window.visualViewport) {
|
|
1318
|
+
rawEmit({
|
|
1319
|
+
data: getVisualViewport(),
|
|
1320
|
+
type: RecordType.VisualViewport,
|
|
1321
|
+
timestamp: timestamp
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
if (false) {
|
|
1325
|
+
updateReplayPerformanceStats({
|
|
1326
|
+
fullSnapshotCount: 1,
|
|
1327
|
+
fullSnapshotDuration: getPerformanceTime() - startedAt
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
return true;
|
|
1331
|
+
}
|
|
1332
|
+
function invalidateFullSnapshotCanvasBaseline() {
|
|
1333
|
+
fullSnapshotCanvasBaselineGeneration += 1;
|
|
1334
|
+
}
|
|
1335
|
+
function scanExistingCommandCaptureCanvases() {
|
|
1336
|
+
try {
|
|
1337
|
+
if (canvasCommandCapture.scanExistingCanvases) {
|
|
1338
|
+
canvasCommandCapture.scanExistingCanvases();
|
|
1339
|
+
}
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
if (false) {
|
|
1342
|
+
addTelemetryDebug('Session Replay canvas baseline scan failed.', {
|
|
1343
|
+
error: String(error)
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
function takeFullSnapshotCanvasBaseline() {
|
|
1349
|
+
if (!configuration.replayCanvasEnabled || configuration.replayCanvasMode !== 'auto') {
|
|
1350
|
+
scanExistingCommandCaptureCanvases();
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
var baselineGeneration = fullSnapshotCanvasBaselineGeneration + 1;
|
|
1354
|
+
fullSnapshotCanvasBaselineGeneration = baselineGeneration;
|
|
1355
|
+
var baselineStartedAt = getPerformanceTime();
|
|
1356
|
+
// The registry is already bounded and contains only canvases assigned an id
|
|
1357
|
+
// by the successful full snapshot. Do not inspect or create a target
|
|
1358
|
+
// context here. Static 2D/unknown canvases get a bitmap baseline, while a
|
|
1359
|
+
// known WebGL canvas must wait for its next real draw: staging it from this
|
|
1360
|
+
// asynchronous baseline task is unsafe with preserveDrawingBuffer=false.
|
|
1361
|
+
var canvases;
|
|
1362
|
+
try {
|
|
1363
|
+
canvases = filterActiveSerializedCanvases(getSerializedCanvasNodesSnapshot(MAX_FULL_SNAPSHOT_CANVAS_BASELINE_COUNT)).filter(function (canvas) {
|
|
1364
|
+
return !isDrawDrivenWebGLCanvas(canvas);
|
|
1365
|
+
});
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
if (false) {
|
|
1368
|
+
addTelemetryDebug('Session Replay canvas baseline lookup failed.', {
|
|
1369
|
+
error: String(error)
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
scanExistingCommandCaptureCanvases();
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
var canvasIndex = 0;
|
|
1376
|
+
function runNextCanvasBaseline() {
|
|
1377
|
+
if (recordStopping || recordStopped || baselineGeneration !== fullSnapshotCanvasBaselineGeneration) {
|
|
1378
|
+
return Promise.resolve();
|
|
1379
|
+
}
|
|
1380
|
+
if (canvasIndex >= canvases.length) {
|
|
1381
|
+
scanExistingCommandCaptureCanvases();
|
|
1382
|
+
return Promise.resolve();
|
|
1383
|
+
}
|
|
1384
|
+
var canvas = canvases[canvasIndex];
|
|
1385
|
+
canvasIndex += 1;
|
|
1386
|
+
var remainingBaselineTime = FULL_SNAPSHOT_CANVAS_BASELINE_TOTAL_TIMEOUT_MS - (getPerformanceTime() - baselineStartedAt);
|
|
1387
|
+
if (remainingBaselineTime <= 0) {
|
|
1388
|
+
if (false) {
|
|
1389
|
+
addTelemetryDebug('Session Replay canvas baseline budget exhausted.', {
|
|
1390
|
+
canvasCount: canvases.length,
|
|
1391
|
+
completedCanvasCount: canvasIndex - 1
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
scanExistingCommandCaptureCanvases();
|
|
1395
|
+
return Promise.resolve();
|
|
1396
|
+
}
|
|
1397
|
+
var canvasBaselineCancelled = false;
|
|
1398
|
+
var snapshotResult;
|
|
1399
|
+
try {
|
|
1400
|
+
snapshotResult = snapshotCanvasIfActive(canvas, {
|
|
1401
|
+
trigger: 'auto',
|
|
1402
|
+
scheduler: 'full_snapshot_baseline',
|
|
1403
|
+
$rIsCancelled: function $rIsCancelled() {
|
|
1404
|
+
return canvasBaselineCancelled || recordStopping || recordStopped || baselineGeneration !== fullSnapshotCanvasBaselineGeneration;
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
} catch (_) {
|
|
1408
|
+
snapshotResult = undefined;
|
|
1409
|
+
}
|
|
1410
|
+
var canvasBaselineTimeoutId;
|
|
1411
|
+
var canvasBaselineTimeout = new Promise(function (resolve) {
|
|
1412
|
+
canvasBaselineTimeoutId = setTimeout(function () {
|
|
1413
|
+
canvasBaselineTimeoutId = undefined;
|
|
1414
|
+
canvasBaselineCancelled = true;
|
|
1415
|
+
if (false) {
|
|
1416
|
+
addTelemetryDebug('Session Replay canvas baseline timed out.', {
|
|
1417
|
+
canvasIndex: canvasIndex,
|
|
1418
|
+
canvasCount: canvases.length
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
resolve();
|
|
1422
|
+
}, Math.min(FULL_SNAPSHOT_CANVAS_BASELINE_ITEM_TIMEOUT_MS, remainingBaselineTime));
|
|
1423
|
+
});
|
|
1424
|
+
return Promise.race([Promise.resolve(snapshotResult)["catch"](function () {}), canvasBaselineTimeout]).then(function () {
|
|
1425
|
+
if (canvasBaselineTimeoutId !== undefined) {
|
|
1426
|
+
clearTimeout(canvasBaselineTimeoutId);
|
|
1427
|
+
}
|
|
1428
|
+
return runNextCanvasBaseline();
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// Invoke the first item synchronously so the baseline gets the first
|
|
1433
|
+
// encode slot after the full snapshot. Remaining canvases are strictly
|
|
1434
|
+
// serial and failures never turn a valid DOM full snapshot into a failure.
|
|
1435
|
+
runNextCanvasBaseline();
|
|
1436
|
+
}
|
|
1437
|
+
var takeInitialFullSnapshot = function takeInitialFullSnapshot(timestamp, serializationContext) {
|
|
1438
|
+
var fullSnapshotStartedAt = getPerformanceTime();
|
|
1439
|
+
if (typeof timestamp === 'undefined') {
|
|
1440
|
+
timestamp = timeStampNow();
|
|
1441
|
+
}
|
|
1442
|
+
if (typeof serializationContext === 'undefined') {
|
|
1443
|
+
serializationContext = {
|
|
1444
|
+
status: SerializationContextStatus.INITIAL_FULL_SNAPSHOT,
|
|
1445
|
+
elementsScrollPositions: elementsScrollPositions,
|
|
1446
|
+
shadowRootsController: shadowRootsController
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
var serializerTask = createFullSnapshotSerializerTask(serializationContext);
|
|
1450
|
+
if (!serializerTask) {
|
|
1451
|
+
return {
|
|
1452
|
+
status: 'failed',
|
|
1453
|
+
reason: 'initial_full_snapshot_serialization_error'
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
var advanceResult = advanceFullSnapshotSerializerTask(serializerTask, getPerformanceTime() + INITIAL_FULL_SNAPSHOT_SERIALIZATION_SLICE_MS);
|
|
1457
|
+
if (advanceResult.isWatermarkReached) {
|
|
1458
|
+
return {
|
|
1459
|
+
status: 'failed',
|
|
1460
|
+
reason: 'initial_full_snapshot_serialization_watermark'
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
if (!advanceResult.completed) {
|
|
1464
|
+
return {
|
|
1465
|
+
status: 'pending',
|
|
1466
|
+
timestamp: timestamp
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
var baselineRecords = createFullSnapshotBaselineRecords(timestamp, serializerTask.serializedNode);
|
|
1470
|
+
if (emitFullSnapshot(baselineRecords, fullSnapshotStartedAt)) {
|
|
1471
|
+
return {
|
|
1472
|
+
status: 'completed'
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
if (wasLastEmitBackpressured()) {
|
|
1476
|
+
pendingFullSnapshotTimestamp = timestamp;
|
|
1477
|
+
pendingFullSnapshotStartedAt = fullSnapshotStartedAt;
|
|
1478
|
+
pendingFullSnapshotIsInitial = true;
|
|
1479
|
+
pendingFullSnapshotBaselineRecords = baselineRecords;
|
|
1480
|
+
pendingFullSnapshotBaselineMutationVersion = domMutationVersion;
|
|
1481
|
+
suppressRecordsUntilFullSnapshot = true;
|
|
1482
|
+
return {
|
|
1483
|
+
status: 'admission_pending',
|
|
1484
|
+
timestamp: timestamp
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
status: 'failed',
|
|
1489
|
+
reason: 'initial_full_snapshot_admission_rejected'
|
|
1490
|
+
};
|
|
1491
|
+
};
|
|
1492
|
+
var initialFullSnapshotResult;
|
|
1493
|
+
try {
|
|
1494
|
+
initialFullSnapshotResult = takeInitialFullSnapshot();
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1497
|
+
}
|
|
1498
|
+
if (initialFullSnapshotResult.status === 'completed') {
|
|
1499
|
+
takeFullSnapshotCanvasBaseline();
|
|
1500
|
+
} else if (initialFullSnapshotResult.status === 'failed') {
|
|
1501
|
+
return abortRecorderInitialization(initialFullSnapshotResult.reason);
|
|
1502
|
+
} else if (initialFullSnapshotResult.status === 'pending') {
|
|
1503
|
+
// The first short attempt ran before MutationObservers existed. Restart
|
|
1504
|
+
// from a clean tree after observers are attached, so changes made between
|
|
1505
|
+
// slices cannot produce a mixed-time initial baseline.
|
|
1506
|
+
resetPublishedReplayTree();
|
|
1507
|
+
}
|
|
1508
|
+
var _initObservers;
|
|
1509
|
+
try {
|
|
1510
|
+
var initObserversImpl = false ? options.initObservers || initObservers : initObservers;
|
|
1511
|
+
_initObservers = initObserversImpl({
|
|
1512
|
+
lifeCycle: options.lifeCycle,
|
|
1513
|
+
configuration: configuration,
|
|
1514
|
+
elementsScrollPositions: elementsScrollPositions,
|
|
1515
|
+
inputCb: inputCb,
|
|
1516
|
+
mediaInteractionCb: function mediaInteractionCb(p) {
|
|
1517
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.MediaInteraction, p));
|
|
1518
|
+
},
|
|
1519
|
+
mouseInteractionCb: function mouseInteractionCb(mouseInteractionRecord) {
|
|
1520
|
+
emit(mouseInteractionRecord);
|
|
1521
|
+
},
|
|
1522
|
+
mousemoveCb: function mousemoveCb(positions, source) {
|
|
1523
|
+
emit(assembleIncrementalSnapshot(source, {
|
|
1524
|
+
positions: positions
|
|
1525
|
+
}));
|
|
1526
|
+
},
|
|
1527
|
+
mutationCb: mutationCb,
|
|
1528
|
+
mutationPerfCb: updateReplayPerformanceStats,
|
|
1529
|
+
mutationOverflowCb: requestFullSnapshotAfterMutationDrop,
|
|
1530
|
+
mutationActivityCb: trackDomMutationActivity,
|
|
1531
|
+
mutationNodeSerializationCb: stageMutationNodePublication,
|
|
1532
|
+
mutationResourceBudget: mutationResourceBudget,
|
|
1533
|
+
isNodeIgnored: isNodeIgnoredForObserver,
|
|
1534
|
+
isNodeIgnoredForStatelessObserver: isNodeIgnoredForStatelessObserver,
|
|
1535
|
+
isNodePublished: isNodeQueuedOrPublished,
|
|
1536
|
+
scrollCb: function scrollCb(p) {
|
|
1537
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.Scroll, p));
|
|
1538
|
+
},
|
|
1539
|
+
styleSheetCb: function styleSheetCb(r) {
|
|
1540
|
+
// The shared state-record admission path distinguishes transient
|
|
1541
|
+
// backpressure from a permanent CSSOM gap and starts exactly one
|
|
1542
|
+
// replacement baseline for the latter.
|
|
1543
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.StyleSheetRule, r));
|
|
1544
|
+
},
|
|
1545
|
+
viewportResizeCb: function viewportResizeCb(d) {
|
|
1546
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.ViewportResize, d));
|
|
1547
|
+
},
|
|
1548
|
+
frustrationCb: function frustrationCb(frustrationRecord) {
|
|
1549
|
+
emit(frustrationRecord);
|
|
1550
|
+
},
|
|
1551
|
+
focusCb: function focusCb(data) {
|
|
1552
|
+
emit({
|
|
1553
|
+
data: data,
|
|
1554
|
+
type: RecordType.Focus,
|
|
1555
|
+
timestamp: timeStampNow()
|
|
1556
|
+
});
|
|
1557
|
+
},
|
|
1558
|
+
visualViewportResizeCb: function visualViewportResizeCb(data) {
|
|
1559
|
+
emit({
|
|
1560
|
+
data: data,
|
|
1561
|
+
type: RecordType.VisualViewport,
|
|
1562
|
+
timestamp: timeStampNow()
|
|
1563
|
+
});
|
|
1564
|
+
},
|
|
1565
|
+
shadowRootsController: shadowRootsController
|
|
1566
|
+
});
|
|
1567
|
+
} catch (error) {
|
|
1568
|
+
return abortRecorderInitialization('recorder_initialization_error', error);
|
|
1569
|
+
}
|
|
1570
|
+
registerInitializationCleanup(_initObservers.stop);
|
|
1571
|
+
refreshAndFlushPendingRootForNode = _initObservers.refreshAndFlushPendingRootForNode || function () {};
|
|
1572
|
+
var stopObservers = _initObservers.stop;
|
|
1573
|
+
var flushMutationsFromObservers = _initObservers.flush;
|
|
1574
|
+
var resetMutationsFromObservers = _initObservers.reset || function () {};
|
|
1575
|
+
initializationCleanupTasks = [];
|
|
1576
|
+
if (initialFullSnapshotResult.status === 'pending' && !beginInitialFullSnapshot(initialFullSnapshotResult.timestamp)) {
|
|
1577
|
+
return createInactiveRecorder();
|
|
1578
|
+
}
|
|
1579
|
+
if (initialFullSnapshotResult.status === 'admission_pending') {
|
|
1580
|
+
schedulePendingFullSnapshotSlice(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
1581
|
+
}
|
|
1582
|
+
function requestFullSnapshotAfterMutationDrop(overflow) {
|
|
1583
|
+
if (recordStopping || recordStopped) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
if (false) {
|
|
1587
|
+
replayPerformanceStats.mutationDropRecoveryCount += 1;
|
|
1588
|
+
replayPerformanceStats.mutationDropRecoveryLastReason = overflow && overflow.reason ? overflow.reason : 'unknown';
|
|
1589
|
+
}
|
|
1590
|
+
// Any dropped mutation makes the live DOM diverge from the last uploaded
|
|
1591
|
+
// baseline, even when the missing record only contains text or attributes.
|
|
1592
|
+
// The replacement snapshot must therefore complete. If it cannot fit the
|
|
1593
|
+
// bounded serializer/segment budgets, stop and discard the held tail
|
|
1594
|
+
// instead of restoring a tree that is known to be stale.
|
|
1595
|
+
flushPendingMutations();
|
|
1596
|
+
// Keep a safely admitted prefix, but retire the complete pre-transaction
|
|
1597
|
+
// deferred tail. Even an unbound Scroll/Canvas record can roll state back
|
|
1598
|
+
// if it is replayed after the replacement baseline. Only records produced
|
|
1599
|
+
// after the mandatory transaction starts may follow that baseline.
|
|
1600
|
+
discardPendingMutationPayload();
|
|
1601
|
+
discardPendingMutationAdmissions();
|
|
1602
|
+
clearDeferredRecords();
|
|
1603
|
+
scheduleMandatoryFullSnapshotAfterMutationDrop();
|
|
1604
|
+
}
|
|
1605
|
+
function beginAdmissionGapRecovery(reason) {
|
|
1606
|
+
if (recordStopping || recordStopped) {
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
if (false) {
|
|
1610
|
+
replayPerformanceStats.admissionGapRecoveryCount += 1;
|
|
1611
|
+
replayPerformanceStats.admissionGapRecoveryLastReason = reason || 'unknown';
|
|
1612
|
+
}
|
|
1613
|
+
// A deferred CSSOM/Canvas state rejection can leave later DOM admissions
|
|
1614
|
+
// queued. Never pre-flush after that gap: the replacement baseline must
|
|
1615
|
+
// supersede the complete local admission window before any tail escapes.
|
|
1616
|
+
discardPendingMutationPayload();
|
|
1617
|
+
discardPendingMutationAdmissions();
|
|
1618
|
+
clearDeferredRecords();
|
|
1619
|
+
scheduleMandatoryFullSnapshotAfterMutationDrop();
|
|
1620
|
+
}
|
|
1621
|
+
function scheduleMandatoryFullSnapshotAfterMutationDrop() {
|
|
1622
|
+
scheduleSubsequentFullSnapshot(timeStampNow(), false, true);
|
|
1623
|
+
}
|
|
1624
|
+
function flushMutations(forceBoundaryDrain) {
|
|
1625
|
+
var boundaryDeadline = forceBoundaryDrain ? getPerformanceTime() + MUTATION_SOURCE_BOUNDARY_FLUSH_BUDGET_MS : undefined;
|
|
1626
|
+
mutationSourceFlushInProgress = true;
|
|
1627
|
+
try {
|
|
1628
|
+
var shadowFlushResult = true;
|
|
1629
|
+
if (!mutationFlushDocumentPending) {
|
|
1630
|
+
do {
|
|
1631
|
+
shadowFlushResult = shadowRootsController.flush();
|
|
1632
|
+
} while (shadowFlushResult === 'pending' && forceBoundaryDrain && getPerformanceTime() < boundaryDeadline);
|
|
1633
|
+
}
|
|
1634
|
+
if (shadowFlushResult === 'pending') {
|
|
1635
|
+
scheduleMutationSourceFlushContinuation();
|
|
1636
|
+
return 'pending';
|
|
1637
|
+
}
|
|
1638
|
+
if (shadowFlushResult === false) {
|
|
1639
|
+
resetMutationsFromObservers();
|
|
1640
|
+
discardPendingMutationPayload();
|
|
1641
|
+
return false;
|
|
1642
|
+
}
|
|
1643
|
+
mutationFlushDocumentPending = true;
|
|
1644
|
+
var documentFlushResult;
|
|
1645
|
+
do {
|
|
1646
|
+
documentFlushResult = flushMutationsFromObservers();
|
|
1647
|
+
} while (documentFlushResult === 'pending' && forceBoundaryDrain && getPerformanceTime() < boundaryDeadline);
|
|
1648
|
+
if (documentFlushResult === 'pending') {
|
|
1649
|
+
scheduleMutationSourceFlushContinuation();
|
|
1650
|
+
return 'pending';
|
|
1651
|
+
}
|
|
1652
|
+
if (documentFlushResult === false) {
|
|
1653
|
+
mutationFlushDocumentPending = false;
|
|
1654
|
+
resetMutationsFromObservers();
|
|
1655
|
+
if (shadowRootsController.reset) {
|
|
1656
|
+
shadowRootsController.reset();
|
|
1657
|
+
}
|
|
1658
|
+
discardPendingMutationPayload();
|
|
1659
|
+
return false;
|
|
1660
|
+
}
|
|
1661
|
+
} finally {
|
|
1662
|
+
mutationSourceFlushInProgress = false;
|
|
1663
|
+
}
|
|
1664
|
+
mutationFlushDocumentPending = false;
|
|
1665
|
+
flushPendingMutations();
|
|
1666
|
+
return true;
|
|
1667
|
+
}
|
|
1668
|
+
function capturePendingMutationActivityForPreviousReplayTree(includeShadowRoots) {
|
|
1669
|
+
if (!captureRecordsAgainstPreviousReplayTree || mutationSourceFlushInProgress) {
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
var resetShadowMutationsForBaseline = includeShadowRoots ? shadowRootsController.$rResetPendingMutationsForBaseline : undefined;
|
|
1673
|
+
if (resetShadowMutationsForBaseline) {
|
|
1674
|
+
var shadowResetResult = resetShadowMutationsForBaseline();
|
|
1675
|
+
if (shadowResetResult !== true) {
|
|
1676
|
+
// Do not synchronously walk an arbitrary number of roots from an input
|
|
1677
|
+
// handler. An incomplete reset means the optional candidate is no
|
|
1678
|
+
// longer safe to abandon; the rebuilt baseline will absorb the live
|
|
1679
|
+
// DOM.
|
|
1680
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
1681
|
+
pendingFullSnapshotRestartRequested = true;
|
|
1682
|
+
pendingFullSnapshotTimestamp = Math.max(typeof pendingFullSnapshotTimestamp === 'number' ? pendingFullSnapshotTimestamp : 0, timeStampNow());
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
resetMutationsFromObservers();
|
|
1686
|
+
discardPendingMutationPayload();
|
|
1687
|
+
}
|
|
1688
|
+
function scheduleMutationSourceFlushContinuation() {
|
|
1689
|
+
if (mutationSourceFlushContinuationTimeout !== undefined || recordStopping || recordStopped) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
mutationSourceFlushContinuationTimeout = setTimeout(function () {
|
|
1693
|
+
mutationSourceFlushContinuationTimeout = undefined;
|
|
1694
|
+
flushMutations();
|
|
1695
|
+
}, 0);
|
|
1696
|
+
}
|
|
1697
|
+
function cancelMutationSourceFlushContinuation() {
|
|
1698
|
+
if (mutationSourceFlushContinuationTimeout !== undefined) {
|
|
1699
|
+
clearTimeout(mutationSourceFlushContinuationTimeout);
|
|
1700
|
+
mutationSourceFlushContinuationTimeout = undefined;
|
|
1701
|
+
}
|
|
1702
|
+
mutationFlushDocumentPending = false;
|
|
1703
|
+
}
|
|
1704
|
+
function flushMutationRootForNode(node) {
|
|
1705
|
+
if (!node || !flushMutationsFromObservers) {
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
mutationSourceFlushInProgress = true;
|
|
1709
|
+
var flushResult;
|
|
1710
|
+
try {
|
|
1711
|
+
flushResult = refreshAndFlushPendingRootForNode(node);
|
|
1712
|
+
if (typeof flushResult === 'undefined' && shadowRootsController.refreshAndFlushPendingRootForNode) {
|
|
1713
|
+
flushResult = shadowRootsController.refreshAndFlushPendingRootForNode(node);
|
|
1714
|
+
}
|
|
1715
|
+
} finally {
|
|
1716
|
+
mutationSourceFlushInProgress = false;
|
|
1717
|
+
}
|
|
1718
|
+
if (flushResult === false) {
|
|
1719
|
+
return false;
|
|
1720
|
+
}
|
|
1721
|
+
flushPendingMutations();
|
|
1722
|
+
return !pendingMutationAdmissionQueue.length && !suppressRecordsUntilFullSnapshot && !recordStopped;
|
|
1723
|
+
}
|
|
1724
|
+
function discardPendingMutationPayload() {
|
|
1725
|
+
if (pendingMutationTimeout) {
|
|
1726
|
+
clearTimeout(pendingMutationTimeout);
|
|
1727
|
+
pendingMutationTimeout = undefined;
|
|
1728
|
+
}
|
|
1729
|
+
if (pendingMutationPayload) {
|
|
1730
|
+
discardMutationMembership(materializeMutationPayload(pendingMutationPayload));
|
|
1731
|
+
}
|
|
1732
|
+
pendingMutationPayload = undefined;
|
|
1733
|
+
}
|
|
1734
|
+
function prepareMutationBaseline(preserveShadowRootObservers) {
|
|
1735
|
+
// A full snapshot supersedes mutation work that has not been emitted yet.
|
|
1736
|
+
// Do not force-drain time-sliced serializers immediately before traversing
|
|
1737
|
+
// the complete document.
|
|
1738
|
+
cancelMutationSourceFlushContinuation();
|
|
1739
|
+
flushPendingMutations();
|
|
1740
|
+
discardPendingMutationAdmissions();
|
|
1741
|
+
resetMutationsFromObservers();
|
|
1742
|
+
if (!preserveShadowRootObservers && shadowRootsController.reset) {
|
|
1743
|
+
shadowRootsController.reset();
|
|
1744
|
+
}
|
|
1745
|
+
mutationResourceBudget.reset();
|
|
1746
|
+
discardPendingMutationPayload();
|
|
1747
|
+
resetPublishedReplayTree();
|
|
1748
|
+
}
|
|
1749
|
+
function prepareForViewChange() {
|
|
1750
|
+
// View boundaries retire every event ordered against the old replay tree.
|
|
1751
|
+
// Internal baseline retries preserve records captured during serialization,
|
|
1752
|
+
// so keep this clearing behavior on the public view transition only.
|
|
1753
|
+
// Give a paged raw/shadow transaction one final bounded drain before the
|
|
1754
|
+
// old tree is retired. If it is still pending, prepareMutationBaseline()
|
|
1755
|
+
// drops the complete uncommitted transaction; VIEW_CREATED then publishes
|
|
1756
|
+
// the replacement baseline instead of exposing a half-applied move.
|
|
1757
|
+
var flushResult = flushMutations(true);
|
|
1758
|
+
if (flushResult === 'pending') {
|
|
1759
|
+
addTelemetryDebug('Session Replay dropped a pending mutation transaction at a view boundary.', {
|
|
1760
|
+
reason: 'view_boundary_mutation_tail_pending'
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
clearDeferredRecords();
|
|
1764
|
+
prepareMutationBaseline();
|
|
1765
|
+
return flushResult;
|
|
1766
|
+
}
|
|
1767
|
+
function resetCanvasRecordingBaseline() {
|
|
1768
|
+
invalidateFullSnapshotCanvasBaseline();
|
|
1769
|
+
if (canvasObserver.reset) {
|
|
1770
|
+
canvasObserver.reset();
|
|
1771
|
+
}
|
|
1772
|
+
if (canvasWebGLSnapshotObserver.reset) {
|
|
1773
|
+
canvasWebGLSnapshotObserver.reset();
|
|
1774
|
+
}
|
|
1775
|
+
if (canvasCommandCapture.reset) {
|
|
1776
|
+
canvasCommandCapture.reset();
|
|
1777
|
+
}
|
|
1778
|
+
resetCanvasSnapshots(canvasSnapshotLoop);
|
|
1779
|
+
}
|
|
1780
|
+
function prepareForFullSnapshot() {
|
|
1781
|
+
// While the previous replay tail remains valid, keep its ShadowRoot
|
|
1782
|
+
// observers alive until the candidate baseline commits or abandons. This
|
|
1783
|
+
// closes the same-task window where a shadow mutation could otherwise
|
|
1784
|
+
// happen after begin() but before the serializer re-registers the root.
|
|
1785
|
+
prepareMutationBaseline(captureRecordsAgainstPreviousReplayTree && pendingFullSnapshotCanBeDiscarded);
|
|
1786
|
+
resetCanvasRecordingBaseline();
|
|
1787
|
+
}
|
|
1788
|
+
function clearPendingFullSnapshotTimeout() {
|
|
1789
|
+
if (pendingFullSnapshotTimeout !== undefined) {
|
|
1790
|
+
clearTimeout(pendingFullSnapshotTimeout);
|
|
1791
|
+
pendingFullSnapshotTimeout = undefined;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
function cancelScheduledFullSnapshot() {
|
|
1795
|
+
clearPendingFullSnapshotTimeout();
|
|
1796
|
+
pendingFullSnapshotTimestamp = undefined;
|
|
1797
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
1798
|
+
pendingFullSnapshotRequiresTailDiscard = false;
|
|
1799
|
+
pendingFullSnapshotTask = undefined;
|
|
1800
|
+
pendingFullSnapshotMutationVersion = undefined;
|
|
1801
|
+
pendingFullSnapshotStartedAt = undefined;
|
|
1802
|
+
pendingFullSnapshotActiveDuration = 0;
|
|
1803
|
+
pendingFullSnapshotRestartCount = 0;
|
|
1804
|
+
pendingFullSnapshotRestartRequested = false;
|
|
1805
|
+
pendingFullSnapshotSynchronousFallbackAttempted = false;
|
|
1806
|
+
pendingFullSnapshotIsInitial = false;
|
|
1807
|
+
pendingFullSnapshotBaselineRecords = undefined;
|
|
1808
|
+
pendingFullSnapshotBaselineMutationVersion = undefined;
|
|
1809
|
+
}
|
|
1810
|
+
function clearDeferredRecords() {
|
|
1811
|
+
if (deferredRecordAdmissionTimeout !== undefined) {
|
|
1812
|
+
clearTimeout(deferredRecordAdmissionTimeout);
|
|
1813
|
+
deferredRecordAdmissionTimeout = undefined;
|
|
1814
|
+
}
|
|
1815
|
+
deferredRecords = [];
|
|
1816
|
+
deferredRecordsApproxBytes = 0;
|
|
1817
|
+
}
|
|
1818
|
+
function isDeferredRecordAfterFullSnapshot(entry, timestamp) {
|
|
1819
|
+
return Boolean(entry && entry.$rRecord && typeof entry.$rRecord.timestamp === 'number' && entry.$rRecord.timestamp > timestamp);
|
|
1820
|
+
}
|
|
1821
|
+
function flushAndRetireDeferredRecordsBeforeFullSnapshot(timestamp) {
|
|
1822
|
+
if (deferredRecordAdmissionTimeout !== undefined) {
|
|
1823
|
+
clearTimeout(deferredRecordAdmissionTimeout);
|
|
1824
|
+
deferredRecordAdmissionTimeout = undefined;
|
|
1825
|
+
}
|
|
1826
|
+
if (!deferredRecords.length) {
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
var drainStartedAt = getPerformanceTime();
|
|
1830
|
+
var drainedApproxBytes = 0;
|
|
1831
|
+
while (deferredRecords.length) {
|
|
1832
|
+
var entry = deferredRecords[0];
|
|
1833
|
+
if (isDeferredRecordAfterFullSnapshot(entry, timestamp)) {
|
|
1834
|
+
break;
|
|
1835
|
+
}
|
|
1836
|
+
if (entry.$rMutationAdmissionBarrier && entry.$rMutationAdmissionBarrier.$rPendingAdmission) {
|
|
1837
|
+
break;
|
|
1838
|
+
}
|
|
1839
|
+
if (rawEmit(entry.$rRecord) === false) {
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
deferredRecords.shift();
|
|
1843
|
+
deferredRecordsApproxBytes -= entry.$rApproxBytes;
|
|
1844
|
+
drainedApproxBytes += entry.$rApproxBytes;
|
|
1845
|
+
if (drainedApproxBytes >= MUTATION_ADMISSION_DRAIN_SLICE_APPROX_BYTES || getPerformanceTime() - drainStartedAt >= MUTATION_ADMISSION_DRAIN_SLICE_MS) {
|
|
1846
|
+
break;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
// A replacement baseline supersedes only records at or before its own
|
|
1850
|
+
// timestamp. Preserve a future-dated suffix captured inside the current
|
|
1851
|
+
// transaction so it can follow the replacement baseline. The bounded
|
|
1852
|
+
// prefix attempt avoids adding an unbounded encode loop to this boundary.
|
|
1853
|
+
var retainedDeferredRecords = [];
|
|
1854
|
+
var retainedDeferredRecordsApproxBytes = 0;
|
|
1855
|
+
var retiredStatefulRecord = false;
|
|
1856
|
+
deferredRecords.forEach(function (entry) {
|
|
1857
|
+
if (isDeferredRecordAfterFullSnapshot(entry, timestamp)) {
|
|
1858
|
+
retainedDeferredRecords.push(entry);
|
|
1859
|
+
retainedDeferredRecordsApproxBytes += entry.$rApproxBytes;
|
|
1860
|
+
} else if (isStatefulDeferredRecord(entry.$rRecord)) {
|
|
1861
|
+
retiredStatefulRecord = true;
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
deferredRecords = retainedDeferredRecords;
|
|
1865
|
+
deferredRecordsApproxBytes = retainedDeferredRecordsApproxBytes;
|
|
1866
|
+
return retiredStatefulRecord;
|
|
1867
|
+
}
|
|
1868
|
+
function handleDeferredRecordLoss(record) {
|
|
1869
|
+
if (!isStatefulDeferredRecord(record)) {
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
if (pendingFullSnapshotTask) {
|
|
1873
|
+
beginAdmissionGapRecovery('deferred_stateful_record_loss');
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
beginAdmissionGapRecovery('deferred_stateful_record_loss');
|
|
1877
|
+
}
|
|
1878
|
+
function scheduleDeferredRecordAdmissionRetry() {
|
|
1879
|
+
scheduleDeferredRecordAdmissionDrain(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
1880
|
+
}
|
|
1881
|
+
function scheduleDeferredRecordAdmissionContinuation() {
|
|
1882
|
+
scheduleDeferredRecordAdmissionDrain(0);
|
|
1883
|
+
}
|
|
1884
|
+
function scheduleDeferredRecordAdmissionDrain(delay) {
|
|
1885
|
+
if (deferredRecordAdmissionTimeout !== undefined || !deferredRecords.length || recordStopping || recordStopped) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
deferredRecordAdmissionTimeout = setTimeout(function () {
|
|
1889
|
+
deferredRecordAdmissionTimeout = undefined;
|
|
1890
|
+
var mutationAdmissionBarrier = deferredRecords.length ? deferredRecords[0].$rMutationAdmissionBarrier : undefined;
|
|
1891
|
+
var barrierWasDrained = flushDeferredRecords(mutationAdmissionBarrier);
|
|
1892
|
+
if (barrierWasDrained) {
|
|
1893
|
+
scheduleMutationAdmissionContinuation();
|
|
1894
|
+
}
|
|
1895
|
+
}, delay);
|
|
1896
|
+
}
|
|
1897
|
+
function flushDeferredRecords(mutationAdmissionBarrier, drainState) {
|
|
1898
|
+
if (suppressRecordsUntilFullSnapshot || recordStopped) {
|
|
1899
|
+
return false;
|
|
1900
|
+
}
|
|
1901
|
+
if (deferredRecordAdmissionTimeout !== undefined) {
|
|
1902
|
+
clearTimeout(deferredRecordAdmissionTimeout);
|
|
1903
|
+
deferredRecordAdmissionTimeout = undefined;
|
|
1904
|
+
}
|
|
1905
|
+
drainState = drainState || {
|
|
1906
|
+
$rStartedAt: getPerformanceTime(),
|
|
1907
|
+
$rApproxBytes: 0
|
|
1908
|
+
};
|
|
1909
|
+
while (deferredRecords.length) {
|
|
1910
|
+
var entry = deferredRecords[0];
|
|
1911
|
+
if (entry.$rMutationAdmissionBarrier && (entry.$rMutationAdmissionBarrier.$rPendingAdmission || mutationAdmissionBarrier && entry.$rMutationAdmissionBarrier !== mutationAdmissionBarrier)) {
|
|
1912
|
+
// A global/no-barrier drain may consume its unbound prefix, but a
|
|
1913
|
+
// state record for a still-pending DOM add must wait for mutation
|
|
1914
|
+
// admission. A concrete barrier drain likewise stops at the next
|
|
1915
|
+
// structural boundary.
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
if (rawEmit(entry.$rRecord) !== false) {
|
|
1919
|
+
deferredRecords.shift();
|
|
1920
|
+
deferredRecordsApproxBytes -= entry.$rApproxBytes;
|
|
1921
|
+
drainState.$rApproxBytes += entry.$rApproxBytes;
|
|
1922
|
+
if (deferredRecords.length && (!mutationAdmissionBarrier || !deferredRecords[0].$rMutationAdmissionBarrier || deferredRecords[0].$rMutationAdmissionBarrier === mutationAdmissionBarrier) && (drainState.$rApproxBytes >= MUTATION_ADMISSION_DRAIN_SLICE_APPROX_BYTES || getPerformanceTime() - drainState.$rStartedAt >= MUTATION_ADMISSION_DRAIN_SLICE_MS)) {
|
|
1923
|
+
scheduleDeferredRecordAdmissionContinuation();
|
|
1924
|
+
return false;
|
|
1925
|
+
}
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
if (options.$rWasLastEmitBackpressured && options.$rWasLastEmitBackpressured()) {
|
|
1929
|
+
scheduleDeferredRecordAdmissionRetry();
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
deferredRecords.shift();
|
|
1933
|
+
deferredRecordsApproxBytes -= entry.$rApproxBytes;
|
|
1934
|
+
if (isStatefulDeferredRecord(entry.$rRecord)) {
|
|
1935
|
+
// Canvas commands and CSSOM rule indexes form ordered state chains.
|
|
1936
|
+
// A permanent gap cannot be skipped; supersede the remainder with a
|
|
1937
|
+
// fresh mandatory baseline instead.
|
|
1938
|
+
beginAdmissionGapRecovery('deferred_stateful_record_rejected');
|
|
1939
|
+
return false;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return true;
|
|
1943
|
+
}
|
|
1944
|
+
function restoreRecordingAfterAbandonedFullSnapshot(beforeShadowRootRollback) {
|
|
1945
|
+
restorePreviousPublishedReplayTree();
|
|
1946
|
+
suppressRecordsUntilFullSnapshot = false;
|
|
1947
|
+
if (beforeShadowRootRollback) {
|
|
1948
|
+
beforeShadowRootRollback();
|
|
1949
|
+
}
|
|
1950
|
+
if (shadowRootsController.$rRollbackRecovery) {
|
|
1951
|
+
shadowRootsController.$rRollbackRecovery();
|
|
1952
|
+
}
|
|
1953
|
+
// Bitmap snapshots produced while the replacement baseline was being
|
|
1954
|
+
// serialized were deferred and are discarded on abandon. The shared
|
|
1955
|
+
// Canvas observer may already have advanced its frame signature/data URL
|
|
1956
|
+
// baseline, so reset every scheduler before rescanning; otherwise the
|
|
1957
|
+
// unchanged frame would never be emitted after recording resumes.
|
|
1958
|
+
resetCanvasRecordingBaseline();
|
|
1959
|
+
scanExistingCommandCaptureCanvases();
|
|
1960
|
+
}
|
|
1961
|
+
function beginInitialFullSnapshot(timestamp) {
|
|
1962
|
+
if (recordStopping || recordStopped) {
|
|
1963
|
+
return false;
|
|
1964
|
+
}
|
|
1965
|
+
cancelScheduledFullSnapshot();
|
|
1966
|
+
pendingFullSnapshotTimestamp = timestamp;
|
|
1967
|
+
pendingFullSnapshotStartedAt = getPerformanceTime();
|
|
1968
|
+
pendingFullSnapshotActiveDuration = 0;
|
|
1969
|
+
pendingFullSnapshotRestartCount = 0;
|
|
1970
|
+
pendingFullSnapshotRestartRequested = false;
|
|
1971
|
+
pendingFullSnapshotIsInitial = true;
|
|
1972
|
+
suppressRecordsUntilFullSnapshot = true;
|
|
1973
|
+
try {
|
|
1974
|
+
prepareForFullSnapshot();
|
|
1975
|
+
createPendingFullSnapshotTask();
|
|
1976
|
+
} catch (error) {
|
|
1977
|
+
return handleFullSnapshotException('full_snapshot_initialization_error', error);
|
|
1978
|
+
}
|
|
1979
|
+
schedulePendingFullSnapshotSlice();
|
|
1980
|
+
return true;
|
|
1981
|
+
}
|
|
1982
|
+
function beginSubsequentFullSnapshot(timestamp, canBeDiscarded, requiresTailDiscard) {
|
|
1983
|
+
if (recordStopping || recordStopped) {
|
|
1984
|
+
return false;
|
|
1985
|
+
}
|
|
1986
|
+
var replacesPendingFullSnapshot = pendingFullSnapshotTimestamp !== undefined;
|
|
1987
|
+
var previousTransactionTimestamp = pendingFullSnapshotTimestamp;
|
|
1988
|
+
var fullSnapshotTimestamp = typeof timestamp === 'undefined' ? timeStampNow() : timestamp;
|
|
1989
|
+
if (replacesPendingFullSnapshot && typeof previousTransactionTimestamp === 'number') {
|
|
1990
|
+
fullSnapshotTimestamp = Math.max(fullSnapshotTimestamp, previousTransactionTimestamp);
|
|
1991
|
+
}
|
|
1992
|
+
if (typeof previousReplayTreeLastRecordTimestamp === 'number') {
|
|
1993
|
+
fullSnapshotTimestamp = Math.max(fullSnapshotTimestamp, previousReplayTreeLastRecordTimestamp);
|
|
1994
|
+
}
|
|
1995
|
+
var retiredStatefulRecord = flushAndRetireDeferredRecordsBeforeFullSnapshot(fullSnapshotTimestamp);
|
|
1996
|
+
cancelScheduledFullSnapshot();
|
|
1997
|
+
pendingFullSnapshotTimestamp = fullSnapshotTimestamp;
|
|
1998
|
+
pendingFullSnapshotCanBeDiscarded = Boolean(canBeDiscarded) && !retiredStatefulRecord;
|
|
1999
|
+
pendingFullSnapshotRequiresTailDiscard = Boolean(requiresTailDiscard);
|
|
2000
|
+
if (pendingFullSnapshotRequiresTailDiscard && options.$rOnMandatoryFullSnapshotStarted) {
|
|
2001
|
+
options.$rOnMandatoryFullSnapshotStarted();
|
|
2002
|
+
}
|
|
2003
|
+
pendingFullSnapshotStartedAt = getPerformanceTime();
|
|
2004
|
+
pendingFullSnapshotActiveDuration = 0;
|
|
2005
|
+
pendingFullSnapshotRestartCount = 0;
|
|
2006
|
+
pendingFullSnapshotRestartRequested = false;
|
|
2007
|
+
pendingFullSnapshotIsInitial = !fullSnapshotWasPublished;
|
|
2008
|
+
if (!replacesPendingFullSnapshot || pendingFullSnapshotRequiresTailDiscard) {
|
|
2009
|
+
resetPreviousReplayTreeRecords();
|
|
2010
|
+
}
|
|
2011
|
+
captureRecordsAgainstPreviousReplayTree = !pendingFullSnapshotIsInitial && !pendingFullSnapshotRequiresTailDiscard;
|
|
2012
|
+
previousReplayTreeAdmissionActive = captureRecordsAgainstPreviousReplayTree;
|
|
2013
|
+
suppressRecordsUntilFullSnapshot = true;
|
|
2014
|
+
if (!previousPublishedReplayTree) {
|
|
2015
|
+
previousPublishedReplayTree = getPublishedReplayTree();
|
|
2016
|
+
}
|
|
2017
|
+
try {
|
|
2018
|
+
if (!pendingFullSnapshotIsInitial && shadowRootsController.$rBeginRecovery) {
|
|
2019
|
+
shadowRootsController.$rBeginRecovery();
|
|
2020
|
+
}
|
|
2021
|
+
prepareForFullSnapshot();
|
|
2022
|
+
createPendingFullSnapshotTask();
|
|
2023
|
+
} catch (error) {
|
|
2024
|
+
return handleFullSnapshotException('full_snapshot_initialization_error', error);
|
|
2025
|
+
}
|
|
2026
|
+
return true;
|
|
2027
|
+
}
|
|
2028
|
+
function createPendingFullSnapshotTask() {
|
|
2029
|
+
if (pendingFullSnapshotIsInitial) {
|
|
2030
|
+
elementsScrollPositions.reset();
|
|
2031
|
+
}
|
|
2032
|
+
pendingFullSnapshotTask = createFullSnapshotSerializerTask({
|
|
2033
|
+
shadowRootsController: shadowRootsController,
|
|
2034
|
+
status: pendingFullSnapshotIsInitial ? SerializationContextStatus.INITIAL_FULL_SNAPSHOT : SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT,
|
|
2035
|
+
elementsScrollPositions: elementsScrollPositions
|
|
2036
|
+
});
|
|
2037
|
+
if (!pendingFullSnapshotTask) {
|
|
2038
|
+
throw new Error('Full snapshot unavailable.');
|
|
2039
|
+
}
|
|
2040
|
+
pendingFullSnapshotMutationVersion = domMutationVersion;
|
|
2041
|
+
}
|
|
2042
|
+
function schedulePendingFullSnapshotSlice(delay) {
|
|
2043
|
+
if (recordStopping || recordStopped || pendingFullSnapshotTimeout !== undefined || pendingFullSnapshotTimestamp === undefined) {
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
delay = delay || 0;
|
|
2047
|
+
pendingFullSnapshotTimeout = setTimeout(function () {
|
|
2048
|
+
pendingFullSnapshotTimeout = undefined;
|
|
2049
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2050
|
+
return;
|
|
2051
|
+
}
|
|
2052
|
+
if (pendingFullSnapshotBaselineRecords) {
|
|
2053
|
+
runPendingFullSnapshotSliceSafely(true);
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2056
|
+
if (!pendingFullSnapshotTask) {
|
|
2057
|
+
var completeSynchronously = false;
|
|
2058
|
+
if (pendingFullSnapshotMutationVersion !== domMutationVersion) {
|
|
2059
|
+
pendingFullSnapshotMutationVersion = domMutationVersion;
|
|
2060
|
+
if (pendingFullSnapshotSynchronousFallbackAttempted || getPerformanceTime() - pendingFullSnapshotStartedAt < FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS) {
|
|
2061
|
+
schedulePendingFullSnapshotSlice(delay);
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
pendingFullSnapshotSynchronousFallbackAttempted = true;
|
|
2065
|
+
completeSynchronously = true;
|
|
2066
|
+
}
|
|
2067
|
+
try {
|
|
2068
|
+
prepareForFullSnapshot();
|
|
2069
|
+
clearDeferredRecords();
|
|
2070
|
+
createPendingFullSnapshotTask();
|
|
2071
|
+
} catch (error) {
|
|
2072
|
+
return handleFullSnapshotException('full_snapshot_initialization_error', error);
|
|
2073
|
+
}
|
|
2074
|
+
if (completeSynchronously) {
|
|
2075
|
+
var synchronousStartedAt = getPerformanceTime();
|
|
2076
|
+
var synchronousDeadline = synchronousStartedAt + FULL_SNAPSHOT_SYNCHRONOUS_FINALIZATION_BUDGET_MS;
|
|
2077
|
+
var synchronousMaxSliceCount = Math.ceil(FULL_SNAPSHOT_SYNCHRONOUS_FINALIZATION_BUDGET_MS / FULL_SNAPSHOT_SERIALIZATION_SLICE_MS);
|
|
2078
|
+
var synchronousSliceCount = 0;
|
|
2079
|
+
while (pendingFullSnapshotTask) {
|
|
2080
|
+
if (synchronousSliceCount >= synchronousMaxSliceCount || getPerformanceTime() >= synchronousDeadline) {
|
|
2081
|
+
deferPendingFullSnapshotUntilQuiet();
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
2084
|
+
synchronousSliceCount += 1;
|
|
2085
|
+
if (runPendingFullSnapshotSliceSafely(false, synchronousDeadline)) {
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
if (pendingFullSnapshotBaselineRecords) {
|
|
2089
|
+
schedulePendingFullSnapshotSlice(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
runPendingFullSnapshotSliceSafely(true);
|
|
2097
|
+
}, delay);
|
|
2098
|
+
}
|
|
2099
|
+
function deferPendingFullSnapshotUntilQuiet() {
|
|
2100
|
+
pendingFullSnapshotTask = undefined;
|
|
2101
|
+
pendingFullSnapshotRestartRequested = false;
|
|
2102
|
+
try {
|
|
2103
|
+
prepareForFullSnapshot();
|
|
2104
|
+
clearDeferredRecords();
|
|
2105
|
+
pendingFullSnapshotMutationVersion = domMutationVersion;
|
|
2106
|
+
} catch (error) {
|
|
2107
|
+
return handleFullSnapshotException('full_snapshot_initialization_error', error);
|
|
2108
|
+
}
|
|
2109
|
+
schedulePendingFullSnapshotSlice(FULL_SNAPSHOT_MUTATION_QUIET_DELAY_MS);
|
|
2110
|
+
}
|
|
2111
|
+
function restartPendingFullSnapshot(allowScheduling) {
|
|
2112
|
+
pendingFullSnapshotRestartCount += 1;
|
|
2113
|
+
pendingFullSnapshotRestartRequested = false;
|
|
2114
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
if (pendingFullSnapshotRestartCount > FULL_SNAPSHOT_MAX_RESTART_COUNT) {
|
|
2118
|
+
if (!pendingFullSnapshotCanBeDiscarded && allowScheduling) {
|
|
2119
|
+
// Keep one bounded transaction alive while a large dashboard mutates.
|
|
2120
|
+
// A single timer waits for a quiet window; no serializer task or
|
|
2121
|
+
// deferred tail grows while churn continues.
|
|
2122
|
+
deferPendingFullSnapshotUntilQuiet();
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
failOrAbandonFullSnapshot('full_snapshot_changed_during_serialization');
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
// Records produced while serializing a discarded attempt may reference
|
|
2129
|
+
// nodes (including canvases) that are not part of the replacement
|
|
2130
|
+
// baseline. Never carry them across the generation boundary.
|
|
2131
|
+
try {
|
|
2132
|
+
clearDeferredRecords();
|
|
2133
|
+
prepareMutationBaseline();
|
|
2134
|
+
resetCanvasRecordingBaseline();
|
|
2135
|
+
createPendingFullSnapshotTask();
|
|
2136
|
+
} catch (error) {
|
|
2137
|
+
return handleFullSnapshotException('full_snapshot_initialization_error', error);
|
|
2138
|
+
}
|
|
2139
|
+
if (allowScheduling) {
|
|
2140
|
+
schedulePendingFullSnapshotSlice();
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
function runPendingFullSnapshotSlice(allowScheduling, serializationDeadline) {
|
|
2144
|
+
if (pendingFullSnapshotBaselineRecords) {
|
|
2145
|
+
return tryPendingFullSnapshotAdmission(allowScheduling);
|
|
2146
|
+
}
|
|
2147
|
+
if (!pendingFullSnapshotTask || recordStopped) {
|
|
2148
|
+
return false;
|
|
2149
|
+
}
|
|
2150
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2151
|
+
return false;
|
|
2152
|
+
}
|
|
2153
|
+
if (pendingFullSnapshotRestartRequested || pendingFullSnapshotMutationVersion !== domMutationVersion) {
|
|
2154
|
+
restartPendingFullSnapshot(allowScheduling);
|
|
2155
|
+
return false;
|
|
2156
|
+
}
|
|
2157
|
+
var sliceStartedAt = getPerformanceTime();
|
|
2158
|
+
var sliceDeadline = sliceStartedAt + FULL_SNAPSHOT_SERIALIZATION_SLICE_MS;
|
|
2159
|
+
if (typeof serializationDeadline === 'number' && isFinite(serializationDeadline)) {
|
|
2160
|
+
sliceDeadline = Math.min(sliceDeadline, serializationDeadline);
|
|
2161
|
+
}
|
|
2162
|
+
var advanceResult = advanceFullSnapshotSerializerTask(pendingFullSnapshotTask, sliceDeadline);
|
|
2163
|
+
pendingFullSnapshotActiveDuration += Math.max(getPerformanceTime() - sliceStartedAt, 0);
|
|
2164
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2165
|
+
return false;
|
|
2166
|
+
}
|
|
2167
|
+
if (advanceResult.isWatermarkReached) {
|
|
2168
|
+
failOrAbandonFullSnapshot('full_snapshot_serialization_watermark');
|
|
2169
|
+
return false;
|
|
2170
|
+
}
|
|
2171
|
+
if (!advanceResult.completed) {
|
|
2172
|
+
if (allowScheduling) {
|
|
2173
|
+
schedulePendingFullSnapshotSlice();
|
|
2174
|
+
}
|
|
2175
|
+
return false;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// Capture native records that have not reached their observer callback yet.
|
|
2179
|
+
// Shadow observers are reset in bounded pages: reset() performs
|
|
2180
|
+
// takeRecords() and reports activity without serializing a mutation tail
|
|
2181
|
+
// that this replacement baseline will supersede.
|
|
2182
|
+
var resetShadowMutationsForBaseline = shadowRootsController.$rResetPendingMutationsForBaseline;
|
|
2183
|
+
if (resetShadowMutationsForBaseline) {
|
|
2184
|
+
var shadowResetResult = resetShadowMutationsForBaseline();
|
|
2185
|
+
if (shadowResetResult === 'pending') {
|
|
2186
|
+
if (allowScheduling) {
|
|
2187
|
+
schedulePendingFullSnapshotSlice();
|
|
2188
|
+
}
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
if (shadowResetResult === false) {
|
|
2192
|
+
restartPendingFullSnapshot(allowScheduling);
|
|
2193
|
+
return false;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
resetMutationsFromObservers();
|
|
2197
|
+
// Shadow-root observers created while the snapshot was serialized already
|
|
2198
|
+
// belong to the new generation. Mutations between slices have delivered an
|
|
2199
|
+
// activity callback and will restart the snapshot; retiring this generation
|
|
2200
|
+
// here would leave the emitted baseline without active shadow observers.
|
|
2201
|
+
discardPendingMutationPayload();
|
|
2202
|
+
if (pendingFullSnapshotMutationVersion !== domMutationVersion) {
|
|
2203
|
+
restartPendingFullSnapshot(allowScheduling);
|
|
2204
|
+
return false;
|
|
2205
|
+
}
|
|
2206
|
+
var serializedDocument = pendingFullSnapshotTask.serializedNode;
|
|
2207
|
+
pendingFullSnapshotBaselineRecords = createFullSnapshotBaselineRecords(pendingFullSnapshotTimestamp, serializedDocument);
|
|
2208
|
+
pendingFullSnapshotBaselineMutationVersion = pendingFullSnapshotMutationVersion;
|
|
2209
|
+
return tryPendingFullSnapshotAdmission(allowScheduling);
|
|
2210
|
+
}
|
|
2211
|
+
function tryPendingFullSnapshotAdmission(allowScheduling) {
|
|
2212
|
+
if (!pendingFullSnapshotBaselineRecords || recordStopped) {
|
|
2213
|
+
return false;
|
|
2214
|
+
}
|
|
2215
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2216
|
+
return false;
|
|
2217
|
+
}
|
|
2218
|
+
if (!drainPreviousReplayTreeRecords()) {
|
|
2219
|
+
if (allowScheduling) {
|
|
2220
|
+
schedulePendingFullSnapshotSlice(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
2221
|
+
}
|
|
2222
|
+
return false;
|
|
2223
|
+
}
|
|
2224
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2225
|
+
return false;
|
|
2226
|
+
}
|
|
2227
|
+
if (pendingFullSnapshotRestartRequested || pendingFullSnapshotBaselineMutationVersion !== domMutationVersion) {
|
|
2228
|
+
pendingFullSnapshotBaselineRecords = undefined;
|
|
2229
|
+
pendingFullSnapshotBaselineMutationVersion = undefined;
|
|
2230
|
+
discardPendingMutationPayload();
|
|
2231
|
+
discardPendingMutationAdmissions();
|
|
2232
|
+
prepareForFullSnapshot();
|
|
2233
|
+
createPendingFullSnapshotTask();
|
|
2234
|
+
pendingFullSnapshotRestartRequested = false;
|
|
2235
|
+
if (allowScheduling) {
|
|
2236
|
+
schedulePendingFullSnapshotSlice();
|
|
2237
|
+
}
|
|
2238
|
+
return false;
|
|
2239
|
+
}
|
|
2240
|
+
if (pendingFullSnapshotBaselineRecords[0].timestamp !== pendingFullSnapshotTimestamp) {
|
|
2241
|
+
pendingFullSnapshotBaselineRecords = createFullSnapshotBaselineRecords(pendingFullSnapshotTimestamp, pendingFullSnapshotBaselineRecords[2].data.node);
|
|
2242
|
+
}
|
|
2243
|
+
var baselineRecords = pendingFullSnapshotBaselineRecords;
|
|
2244
|
+
var startedAt = pendingFullSnapshotStartedAt;
|
|
2245
|
+
var wasInitialFullSnapshot = pendingFullSnapshotIsInitial;
|
|
2246
|
+
// Release the completed serializer and its timer while preserving the
|
|
2247
|
+
// exact baseline transaction for a possible backpressure retry.
|
|
2248
|
+
pendingFullSnapshotTask = undefined;
|
|
2249
|
+
clearPendingFullSnapshotTimeout();
|
|
2250
|
+
if (!emitFullSnapshot(baselineRecords, startedAt)) {
|
|
2251
|
+
if (wasLastEmitBackpressured()) {
|
|
2252
|
+
if (allowScheduling) {
|
|
2253
|
+
schedulePendingFullSnapshotSlice(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
2254
|
+
}
|
|
2255
|
+
return false;
|
|
2256
|
+
}
|
|
2257
|
+
pendingFullSnapshotBaselineRecords = undefined;
|
|
2258
|
+
pendingFullSnapshotBaselineMutationVersion = undefined;
|
|
2259
|
+
failOrAbandonFullSnapshot('full_snapshot_admission_rejected');
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2262
|
+
pendingFullSnapshotBaselineRecords = undefined;
|
|
2263
|
+
pendingFullSnapshotBaselineMutationVersion = undefined;
|
|
2264
|
+
cancelScheduledFullSnapshot();
|
|
2265
|
+
if (!wasInitialFullSnapshot && shadowRootsController.$rCommitRecovery) {
|
|
2266
|
+
shadowRootsController.$rCommitRecovery();
|
|
2267
|
+
}
|
|
2268
|
+
previousPublishedReplayTree = undefined;
|
|
2269
|
+
suppressRecordsUntilFullSnapshot = false;
|
|
2270
|
+
drainPendingMutationAdmissions();
|
|
2271
|
+
resetPreviousReplayTreeRecords();
|
|
2272
|
+
previousReplayTreeAdmissionActive = false;
|
|
2273
|
+
captureRecordsAgainstPreviousReplayTree = false;
|
|
2274
|
+
flushDeferredRecords();
|
|
2275
|
+
if (!suppressRecordsUntilFullSnapshot && !recordStopped) {
|
|
2276
|
+
takeFullSnapshotCanvasBaseline();
|
|
2277
|
+
}
|
|
2278
|
+
return true;
|
|
2279
|
+
}
|
|
2280
|
+
function handleFullSnapshotException(reason, error) {
|
|
2281
|
+
addTelemetryDebug('Session Replay full snapshot failed.', {
|
|
2282
|
+
reason: reason,
|
|
2283
|
+
error: String(error)
|
|
2284
|
+
});
|
|
2285
|
+
failOrAbandonFullSnapshot(reason);
|
|
2286
|
+
return false;
|
|
2287
|
+
}
|
|
2288
|
+
function failPendingFullSnapshotOnTimeout() {
|
|
2289
|
+
if (pendingFullSnapshotTimestamp === undefined || pendingFullSnapshotActiveDuration <= FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS && getPerformanceTime() - pendingFullSnapshotStartedAt <= FULL_SNAPSHOT_MAX_WALL_DURATION_MS) {
|
|
2290
|
+
return false;
|
|
2291
|
+
}
|
|
2292
|
+
failOrAbandonFullSnapshot('full_snapshot_serialization_timeout');
|
|
2293
|
+
return true;
|
|
2294
|
+
}
|
|
2295
|
+
function runPendingFullSnapshotSliceSafely(allowScheduling, serializationDeadline) {
|
|
2296
|
+
try {
|
|
2297
|
+
return runPendingFullSnapshotSlice(allowScheduling, serializationDeadline);
|
|
2298
|
+
} catch (error) {
|
|
2299
|
+
return handleFullSnapshotException('full_snapshot_serialization_error', error);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
function abandonPendingFullSnapshot(skipRecoveryRestore) {
|
|
2303
|
+
var shouldDiscardTail = pendingFullSnapshotRequiresTailDiscard;
|
|
2304
|
+
var restoreError;
|
|
2305
|
+
cancelScheduledFullSnapshot();
|
|
2306
|
+
clearDeferredRecords();
|
|
2307
|
+
try {
|
|
2308
|
+
if (skipRecoveryRestore) {
|
|
2309
|
+
// Teardown immediately retires every observer and Canvas scheduler.
|
|
2310
|
+
// Rebuilding up to 64 ShadowRoot observers and rescanning canvases here
|
|
2311
|
+
// would add pure main-thread work to stop() only to destroy it again.
|
|
2312
|
+
previousPublishedReplayTree = undefined;
|
|
2313
|
+
suppressRecordsUntilFullSnapshot = false;
|
|
2314
|
+
} else {
|
|
2315
|
+
restoreRecordingAfterAbandonedFullSnapshot(function () {
|
|
2316
|
+
restorePreviousReplayTreeRecords();
|
|
2317
|
+
// The native observer callback may not have run yet in this JavaScript
|
|
2318
|
+
// turn. Now that the old publication tree is active again, serialize
|
|
2319
|
+
// the bounded main/shadow mutation tail before retiring recovery
|
|
2320
|
+
// observers, instead of silently dropping it.
|
|
2321
|
+
flushMutations(true);
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
} catch (error) {
|
|
2325
|
+
restoreError = error;
|
|
2326
|
+
} finally {
|
|
2327
|
+
if (skipRecoveryRestore) {
|
|
2328
|
+
resetPreviousReplayTreeRecords();
|
|
2329
|
+
} else {
|
|
2330
|
+
previousReplayTreeLastRecordTimestamp = undefined;
|
|
2331
|
+
}
|
|
2332
|
+
previousReplayTreeAdmissionActive = false;
|
|
2333
|
+
captureRecordsAgainstPreviousReplayTree = false;
|
|
2334
|
+
if (shouldDiscardTail && options.$rOnMandatoryFullSnapshotAbandoned) {
|
|
2335
|
+
options.$rOnMandatoryFullSnapshotAbandoned();
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
if (restoreError) {
|
|
2339
|
+
return handleFullSnapshotException('full_snapshot_abandon_restore_error', restoreError);
|
|
2340
|
+
}
|
|
2341
|
+
return true;
|
|
2342
|
+
}
|
|
2343
|
+
function failOrAbandonFullSnapshot(reason) {
|
|
2344
|
+
if (pendingFullSnapshotCanBeDiscarded) {
|
|
2345
|
+
return abandonPendingFullSnapshot();
|
|
2346
|
+
}
|
|
2347
|
+
return failFullSnapshot(reason);
|
|
2348
|
+
}
|
|
2349
|
+
function failFullSnapshot(reason) {
|
|
2350
|
+
var failureReason = pendingFullSnapshotIsInitial ? 'initial_' + reason : reason;
|
|
2351
|
+
var shouldDiscardTail = pendingFullSnapshotRequiresTailDiscard;
|
|
2352
|
+
cancelScheduledFullSnapshot();
|
|
2353
|
+
clearDeferredRecords();
|
|
2354
|
+
resetPreviousReplayTreeRecords();
|
|
2355
|
+
previousReplayTreeAdmissionActive = false;
|
|
2356
|
+
captureRecordsAgainstPreviousReplayTree = false;
|
|
2357
|
+
previousPublishedReplayTree = undefined;
|
|
2358
|
+
if (shouldDiscardTail && options.$rOnMandatoryFullSnapshotAbandoned) {
|
|
2359
|
+
options.$rOnMandatoryFullSnapshotAbandoned();
|
|
2360
|
+
}
|
|
2361
|
+
stopRecording(undefined, true);
|
|
2362
|
+
if (options.onFullSnapshotFailure) {
|
|
2363
|
+
options.onFullSnapshotFailure(failureReason);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
function takeSubsequentFullSnapshot(timestamp, canBeDiscarded) {
|
|
2367
|
+
// A public, best-effort snapshot must never replace an in-flight recovery
|
|
2368
|
+
// transaction. The recovery may already have retired stateful records or
|
|
2369
|
+
// the previous replay chain, so downgrading it would make abandon unsafe.
|
|
2370
|
+
if (canBeDiscarded && pendingFullSnapshotTimestamp !== undefined) {
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
var shouldRunAfterRestart = Boolean(pendingFullSnapshotTask);
|
|
2374
|
+
scheduleSubsequentFullSnapshot(timestamp, Boolean(canBeDiscarded));
|
|
2375
|
+
runPendingFullSnapshotSliceSafely(true);
|
|
2376
|
+
if (shouldRunAfterRestart && pendingFullSnapshotTask) {
|
|
2377
|
+
runPendingFullSnapshotSliceSafely(true);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
function flushScheduledFullSnapshot(skipRecoveryRestore, supersedeForView) {
|
|
2381
|
+
if (supersedeForView && pendingFullSnapshotTimestamp !== undefined) {
|
|
2382
|
+
// The next view starts its own baseline transaction. Discard every held
|
|
2383
|
+
// tail from the old view before ViewEnd is emitted.
|
|
2384
|
+
abandonPendingFullSnapshot(true);
|
|
2385
|
+
return true;
|
|
2386
|
+
}
|
|
2387
|
+
if (pendingFullSnapshotCanBeDiscarded && captureRecordsAgainstPreviousReplayTree) {
|
|
2388
|
+
// Detect native main/shadow mutations that have not reached their async
|
|
2389
|
+
// callbacks before deciding that an optional candidate may abandon.
|
|
2390
|
+
capturePendingMutationActivityForPreviousReplayTree(true);
|
|
2391
|
+
}
|
|
2392
|
+
if (failPendingFullSnapshotOnTimeout()) {
|
|
2393
|
+
return true;
|
|
2394
|
+
}
|
|
2395
|
+
if (pendingFullSnapshotBaselineRecords) {
|
|
2396
|
+
// Serialization already completed. Retry the exact baseline transaction
|
|
2397
|
+
// instead of treating the intentionally empty serializer task as an
|
|
2398
|
+
// incomplete snapshot. On unload this hook is invoked again after the
|
|
2399
|
+
// encoder is synchronously drained, so the same objects get one more
|
|
2400
|
+
// admission opportunity before teardown.
|
|
2401
|
+
if (runPendingFullSnapshotSliceSafely(false)) {
|
|
2402
|
+
return true;
|
|
2403
|
+
}
|
|
2404
|
+
if (!pendingFullSnapshotBaselineRecords) {
|
|
2405
|
+
return true;
|
|
2406
|
+
}
|
|
2407
|
+
if (skipRecoveryRestore || pendingFullSnapshotCanBeDiscarded) {
|
|
2408
|
+
abandonPendingFullSnapshot(skipRecoveryRestore);
|
|
2409
|
+
} else {
|
|
2410
|
+
schedulePendingFullSnapshotSlice(MUTATION_ADMISSION_RETRY_DELAY_MS);
|
|
2411
|
+
}
|
|
2412
|
+
return true;
|
|
2413
|
+
}
|
|
2414
|
+
if (!pendingFullSnapshotTask) {
|
|
2415
|
+
if (pendingFullSnapshotTimestamp === undefined) {
|
|
2416
|
+
return false;
|
|
2417
|
+
}
|
|
2418
|
+
if (skipRecoveryRestore || pendingFullSnapshotCanBeDiscarded) {
|
|
2419
|
+
abandonPendingFullSnapshot(skipRecoveryRestore);
|
|
2420
|
+
} else {
|
|
2421
|
+
failFullSnapshot('full_snapshot_incomplete_at_flush');
|
|
2422
|
+
}
|
|
2423
|
+
return true;
|
|
2424
|
+
}
|
|
2425
|
+
if (pendingFullSnapshotCanBeDiscarded) {
|
|
2426
|
+
abandonPendingFullSnapshot(skipRecoveryRestore);
|
|
2427
|
+
return true;
|
|
2428
|
+
}
|
|
2429
|
+
clearPendingFullSnapshotTimeout();
|
|
2430
|
+
if (pendingFullSnapshotRestartRequested || pendingFullSnapshotMutationVersion !== domMutationVersion) {
|
|
2431
|
+
restartPendingFullSnapshot(false);
|
|
2432
|
+
if (!pendingFullSnapshotTask || recordStopped) {
|
|
2433
|
+
return true;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
var completed = runPendingFullSnapshotSliceSafely(false);
|
|
2437
|
+
// Teardown and view-boundary flushes must remain one bounded slice. A
|
|
2438
|
+
// synchronous loop here could spend the full one-second recovery budget
|
|
2439
|
+
// on the main thread and turn stop() into a long task.
|
|
2440
|
+
if (!completed && pendingFullSnapshotTask) {
|
|
2441
|
+
if (pendingFullSnapshotCanBeDiscarded) {
|
|
2442
|
+
abandonPendingFullSnapshot(skipRecoveryRestore);
|
|
2443
|
+
} else {
|
|
2444
|
+
failFullSnapshot('full_snapshot_incomplete_at_flush');
|
|
124
2445
|
}
|
|
125
|
-
lastAutoCanvasSnapshotResult = cloneAutoCanvasSnapshotDebugResult(result, keepSessionAliveTriggered);
|
|
126
|
-
pushCanvasDebugHistoryEntry(autoCanvasSnapshotDebugHistoryForDebug, lastAutoCanvasSnapshotResult);
|
|
127
|
-
},
|
|
128
|
-
snapshotCanvas: function snapshotCanvas(canvas) {
|
|
129
|
-
return canvasObserver.snapshot(canvas, {
|
|
130
|
-
trigger: 'auto',
|
|
131
|
-
scheduler: 'continuous_snapshot'
|
|
132
|
-
});
|
|
133
2446
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return _getSerializedNodeId(canvas);
|
|
146
|
-
},
|
|
147
|
-
onDebug: function onDebug(result) {
|
|
148
|
-
var keepSessionAliveTriggered = false;
|
|
149
|
-
if (shouldKeepSessionAliveAfterAutoCanvasSnapshot(result) && options.sessionManager && options.sessionManager.keepSessionAlive) {
|
|
150
|
-
options.sessionManager.keepSessionAlive();
|
|
151
|
-
keepSessionAliveTriggered = true;
|
|
2447
|
+
return true;
|
|
2448
|
+
}
|
|
2449
|
+
function scheduleSubsequentFullSnapshot(timestamp, canBeDiscarded, requiresTailDiscard) {
|
|
2450
|
+
if (pendingFullSnapshotTimestamp !== undefined) {
|
|
2451
|
+
// Any request arriving while a replacement baseline is being built must
|
|
2452
|
+
// reuse the same bounded transaction. Re-running begin() would reset its
|
|
2453
|
+
// restart/time budget and let sustained mutation churn spin forever.
|
|
2454
|
+
var nextFullSnapshotTimestamp = typeof timestamp === 'undefined' ? timeStampNow() : timestamp;
|
|
2455
|
+
pendingFullSnapshotTimestamp = Math.max(pendingFullSnapshotTimestamp, nextFullSnapshotTimestamp, previousReplayTreeLastRecordTimestamp || 0);
|
|
2456
|
+
if (!canBeDiscarded) {
|
|
2457
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
152
2458
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
2459
|
+
if (requiresTailDiscard && !pendingFullSnapshotRequiresTailDiscard) {
|
|
2460
|
+
pendingFullSnapshotRequiresTailDiscard = true;
|
|
2461
|
+
pendingFullSnapshotCanBeDiscarded = false;
|
|
2462
|
+
previousReplayTreeAdmissionActive = false;
|
|
2463
|
+
captureRecordsAgainstPreviousReplayTree = false;
|
|
2464
|
+
resetPreviousReplayTreeRecords();
|
|
2465
|
+
if (options.$rOnMandatoryFullSnapshotStarted) {
|
|
2466
|
+
options.$rOnMandatoryFullSnapshotStarted();
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
if (pendingFullSnapshotTask) {
|
|
2470
|
+
pendingFullSnapshotRestartRequested = true;
|
|
2471
|
+
}
|
|
2472
|
+
schedulePendingFullSnapshotSlice(pendingFullSnapshotTask ? 0 : FULL_SNAPSHOT_MUTATION_QUIET_DELAY_MS);
|
|
2473
|
+
return;
|
|
159
2474
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (typeof timestamp === 'undefined') {
|
|
163
|
-
timestamp = timeStampNow();
|
|
2475
|
+
if (beginSubsequentFullSnapshot(timestamp, canBeDiscarded, requiresTailDiscard)) {
|
|
2476
|
+
schedulePendingFullSnapshotSlice();
|
|
164
2477
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
shadowRootsController: shadowRootsController
|
|
170
|
-
};
|
|
2478
|
+
}
|
|
2479
|
+
function stopRecording(_flushReason, skipPendingFlush) {
|
|
2480
|
+
if (recordStopping || recordStopped) {
|
|
2481
|
+
return;
|
|
171
2482
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
left: getScrollX(),
|
|
196
|
-
top: getScrollY()
|
|
2483
|
+
// Keep the final bounded mutation drain, but prevent an overflow found by
|
|
2484
|
+
// that drain from starting a replacement full snapshot that teardown would
|
|
2485
|
+
// immediately discard.
|
|
2486
|
+
recordStopping = true;
|
|
2487
|
+
var firstCleanupError;
|
|
2488
|
+
try {
|
|
2489
|
+
if (pendingFullSnapshotIsInitial) {
|
|
2490
|
+
// An initial snapshot has no published tail to finalize. Teardown must
|
|
2491
|
+
// cancel its timer/task instead of forcing another slice or reporting
|
|
2492
|
+
// a failure for an intentional stop.
|
|
2493
|
+
cancelScheduledFullSnapshot();
|
|
2494
|
+
} else if (!skipPendingFlush && !flushScheduledFullSnapshot(true)) {
|
|
2495
|
+
// Capture small records still queued by native MutationObservers.
|
|
2496
|
+
// Oversized subtree serialization is discarded once its synchronous
|
|
2497
|
+
// budget is exhausted.
|
|
2498
|
+
var finalMutationFlushResult = flushMutations(true);
|
|
2499
|
+
if (finalMutationFlushResult === 'pending') {
|
|
2500
|
+
// Chunked callbacks are published only when their final chunk closes,
|
|
2501
|
+
// so teardown drops the whole tail and leaves the replay at its last
|
|
2502
|
+
// consistent state. Never report the bounded drain as successful.
|
|
2503
|
+
addTelemetryDebug('Session Replay dropped a pending mutation transaction during teardown.', {
|
|
2504
|
+
reason: 'stop_mutation_tail_pending'
|
|
2505
|
+
});
|
|
197
2506
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
2507
|
+
}
|
|
2508
|
+
} catch (error) {
|
|
2509
|
+
firstCleanupError = error;
|
|
2510
|
+
}
|
|
2511
|
+
recordStopped = true;
|
|
2512
|
+
[discardPendingMutationAdmissions, cancelMutationSourceFlushContinuation, cancelScheduledFullSnapshot, invalidateFullSnapshotCanvasBaseline, function () {
|
|
2513
|
+
suppressRecordsUntilFullSnapshot = false;
|
|
2514
|
+
previousReplayTreeAdmissionActive = false;
|
|
2515
|
+
captureRecordsAgainstPreviousReplayTree = false;
|
|
2516
|
+
}, clearDeferredRecords, clearPreviousReplayTreeRecords, shadowRootsController.stop, canvasCommandCapture.stop, canvasWebGLSnapshotObserver.stop, canvasObserver.stop, function () {
|
|
2517
|
+
stopCanvasSnapshots(canvasSnapshotLoop);
|
|
2518
|
+
}, stopObservers, stopSerializedCanvasTracking].forEach(function (cleanupTask) {
|
|
2519
|
+
try {
|
|
2520
|
+
cleanupTask();
|
|
2521
|
+
} catch (error) {
|
|
2522
|
+
if (!firstCleanupError) {
|
|
2523
|
+
firstCleanupError = error;
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
201
2526
|
});
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
timestamp: timestamp
|
|
2527
|
+
if (firstCleanupError) {
|
|
2528
|
+
addTelemetryDebug('Session Replay recorder cleanup failed.', {
|
|
2529
|
+
reason: _flushReason,
|
|
2530
|
+
error: String(firstCleanupError)
|
|
207
2531
|
});
|
|
208
2532
|
}
|
|
209
|
-
};
|
|
210
|
-
takeFullSnapshot();
|
|
211
|
-
if (canvasCommandCapture.scanExistingCanvases) {
|
|
212
|
-
canvasCommandCapture.scanExistingCanvases();
|
|
213
|
-
}
|
|
214
|
-
var _initObservers = initObservers({
|
|
215
|
-
lifeCycle: options.lifeCycle,
|
|
216
|
-
configuration: options.configuration,
|
|
217
|
-
elementsScrollPositions: elementsScrollPositions,
|
|
218
|
-
inputCb: inputCb,
|
|
219
|
-
mediaInteractionCb: function mediaInteractionCb(p) {
|
|
220
|
-
emit(assembleIncrementalSnapshot(IncrementalSource.MediaInteraction, p));
|
|
221
|
-
},
|
|
222
|
-
mouseInteractionCb: function mouseInteractionCb(mouseInteractionRecord) {
|
|
223
|
-
emit(mouseInteractionRecord);
|
|
224
|
-
},
|
|
225
|
-
mousemoveCb: function mousemoveCb(positions, source) {
|
|
226
|
-
emit(assembleIncrementalSnapshot(source, {
|
|
227
|
-
positions: positions
|
|
228
|
-
}));
|
|
229
|
-
},
|
|
230
|
-
mutationCb: mutationCb,
|
|
231
|
-
mutationPerfCb: updateReplayPerformanceStats,
|
|
232
|
-
scrollCb: function scrollCb(p) {
|
|
233
|
-
emit(assembleIncrementalSnapshot(IncrementalSource.Scroll, p));
|
|
234
|
-
},
|
|
235
|
-
styleSheetCb: function styleSheetCb(r) {
|
|
236
|
-
emit(assembleIncrementalSnapshot(IncrementalSource.StyleSheetRule, r));
|
|
237
|
-
},
|
|
238
|
-
viewportResizeCb: function viewportResizeCb(d) {
|
|
239
|
-
emit(assembleIncrementalSnapshot(IncrementalSource.ViewportResize, d));
|
|
240
|
-
},
|
|
241
|
-
frustrationCb: function frustrationCb(frustrationRecord) {
|
|
242
|
-
emit(frustrationRecord);
|
|
243
|
-
},
|
|
244
|
-
focusCb: function focusCb(data) {
|
|
245
|
-
emit({
|
|
246
|
-
data: data,
|
|
247
|
-
type: RecordType.Focus,
|
|
248
|
-
timestamp: timeStampNow()
|
|
249
|
-
});
|
|
250
|
-
},
|
|
251
|
-
visualViewportResizeCb: function visualViewportResizeCb(data) {
|
|
252
|
-
emit({
|
|
253
|
-
data: data,
|
|
254
|
-
type: RecordType.VisualViewport,
|
|
255
|
-
timestamp: timeStampNow()
|
|
256
|
-
});
|
|
257
|
-
},
|
|
258
|
-
shadowRootsController: shadowRootsController
|
|
259
|
-
});
|
|
260
|
-
var stopObservers = _initObservers.stop;
|
|
261
|
-
var flushMutationsFromObservers = _initObservers.flush;
|
|
262
|
-
var resetMutationsFromObservers = _initObservers.reset || function () {};
|
|
263
|
-
function flushMutations() {
|
|
264
|
-
shadowRootsController.flush();
|
|
265
|
-
flushMutationsFromObservers();
|
|
266
|
-
flushPendingMutations();
|
|
267
2533
|
}
|
|
268
|
-
|
|
269
|
-
stop:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
2534
|
+
var recorder = {
|
|
2535
|
+
stop: stopRecording,
|
|
2536
|
+
$rFlushCanvasCommands: function $rFlushCanvasCommands() {
|
|
2537
|
+
// A previous boundary pass may have preserved the exact Canvas record
|
|
2538
|
+
// after transient segment/encoder backpressure. Retry that object before
|
|
2539
|
+
// creating a newer command batch so unload's second writable pass keeps
|
|
2540
|
+
// command ordering and can use the segment serialization cache.
|
|
2541
|
+
try {
|
|
2542
|
+
flushDeferredRecords();
|
|
2543
|
+
} catch (_) {}
|
|
2544
|
+
try {
|
|
2545
|
+
if (canvasCommandCapture.flush) {
|
|
2546
|
+
canvasCommandCapture.flush();
|
|
2547
|
+
}
|
|
2548
|
+
} catch (_) {}
|
|
276
2549
|
},
|
|
277
2550
|
snapshotCanvas: function snapshotCanvas(canvas, snapshotOptions) {
|
|
278
|
-
return
|
|
2551
|
+
return snapshotCanvasIfActive(canvas, assign({
|
|
279
2552
|
trigger: 'manual'
|
|
280
2553
|
}, snapshotOptions));
|
|
281
2554
|
},
|
|
282
2555
|
getSerializedNodeIdForDebug: function getSerializedNodeIdForDebug(node) {
|
|
283
|
-
return
|
|
284
|
-
},
|
|
285
|
-
getLastAutoCanvasSnapshotResultForDebug: function getLastAutoCanvasSnapshotResultForDebug() {
|
|
286
|
-
return cloneAutoCanvasSnapshotDebugResult(lastAutoCanvasSnapshotResult);
|
|
287
|
-
},
|
|
288
|
-
getAutoCanvasSnapshotDebugHistoryForDebug: function getAutoCanvasSnapshotDebugHistoryForDebug() {
|
|
289
|
-
return autoCanvasSnapshotDebugHistoryForDebug.map(cloneAutoCanvasSnapshotDebugResult);
|
|
290
|
-
},
|
|
291
|
-
getLastCanvasMutationForDebug: function getLastCanvasMutationForDebug() {
|
|
292
|
-
return cloneCanvasMutationDebugResult(lastCanvasMutationForDebug);
|
|
293
|
-
},
|
|
294
|
-
getCanvasMutationHistoryForDebug: function getCanvasMutationHistoryForDebug() {
|
|
295
|
-
return canvasMutationHistoryForDebug.map(cloneCanvasMutationDebugResult);
|
|
296
|
-
},
|
|
297
|
-
getLastDomMutationForDebug: function getLastDomMutationForDebug() {
|
|
298
|
-
return cloneDomMutationDebugResult(lastDomMutationForDebug);
|
|
299
|
-
},
|
|
300
|
-
getDomMutationHistoryForDebug: function getDomMutationHistoryForDebug() {
|
|
301
|
-
return domMutationHistoryForDebug.map(cloneDomMutationDebugResult);
|
|
302
|
-
},
|
|
303
|
-
getReplayPerformanceForDebug: function getReplayPerformanceForDebug() {
|
|
304
|
-
return cloneReplayPerformanceStats(replayPerformanceStats);
|
|
305
|
-
},
|
|
306
|
-
takeSubsequentFullSnapshot: function takeSubsequentFullSnapshot(timestamp) {
|
|
307
|
-
flushMutations();
|
|
308
|
-
resetMutationsFromObservers();
|
|
309
|
-
if (canvasObserver.reset) {
|
|
310
|
-
canvasObserver.reset();
|
|
311
|
-
}
|
|
312
|
-
if (canvasCommandCapture.reset) {
|
|
313
|
-
canvasCommandCapture.reset();
|
|
314
|
-
}
|
|
315
|
-
resetCanvasSnapshots(canvasSnapshotLoop);
|
|
316
|
-
takeFullSnapshot(timestamp, {
|
|
317
|
-
shadowRootsController: shadowRootsController,
|
|
318
|
-
status: SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT,
|
|
319
|
-
elementsScrollPositions: elementsScrollPositions
|
|
320
|
-
});
|
|
321
|
-
if (canvasCommandCapture.scanExistingCanvases) {
|
|
322
|
-
canvasCommandCapture.scanExistingCanvases();
|
|
323
|
-
}
|
|
2556
|
+
return getActiveSerializedNodeId(node);
|
|
324
2557
|
},
|
|
2558
|
+
takeSubsequentFullSnapshot: takeSubsequentFullSnapshot,
|
|
2559
|
+
flushScheduledFullSnapshot: flushScheduledFullSnapshot,
|
|
2560
|
+
scheduleSubsequentFullSnapshot: scheduleSubsequentFullSnapshot,
|
|
2561
|
+
prepareForViewChange: prepareForViewChange,
|
|
325
2562
|
flushMutations: flushMutations,
|
|
326
2563
|
shadowRootsController: shadowRootsController
|
|
327
2564
|
};
|
|
2565
|
+
if (false) {
|
|
2566
|
+
assign(recorder, {
|
|
2567
|
+
getLastAutoCanvasSnapshotResultForDebug: function getLastAutoCanvasSnapshotResultForDebug() {
|
|
2568
|
+
return cloneAutoCanvasSnapshotDebugResult(lastAutoCanvasSnapshotResult);
|
|
2569
|
+
},
|
|
2570
|
+
getAutoCanvasSnapshotDebugHistoryForDebug: function getAutoCanvasSnapshotDebugHistoryForDebug() {
|
|
2571
|
+
return autoCanvasSnapshotDebugHistoryForDebug.map(cloneAutoCanvasSnapshotDebugResult);
|
|
2572
|
+
},
|
|
2573
|
+
getLastCanvasMutationForDebug: function getLastCanvasMutationForDebug() {
|
|
2574
|
+
return cloneCanvasMutationDebugResult(lastCanvasMutationForDebug);
|
|
2575
|
+
},
|
|
2576
|
+
getCanvasMutationHistoryForDebug: function getCanvasMutationHistoryForDebug() {
|
|
2577
|
+
return canvasMutationHistoryForDebug.map(cloneCanvasMutationDebugResult);
|
|
2578
|
+
},
|
|
2579
|
+
getLastDomMutationForDebug: function getLastDomMutationForDebug() {
|
|
2580
|
+
return cloneDomMutationDebugResult(lastDomMutationForDebug);
|
|
2581
|
+
},
|
|
2582
|
+
getDomMutationHistoryForDebug: function getDomMutationHistoryForDebug() {
|
|
2583
|
+
return domMutationHistoryForDebug.map(cloneDomMutationDebugResult);
|
|
2584
|
+
},
|
|
2585
|
+
getReplayPerformanceForDebug: function getReplayPerformanceForDebug() {
|
|
2586
|
+
return cloneReplayPerformanceStats(replayPerformanceStats);
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
return recorder;
|
|
2591
|
+
}
|
|
2592
|
+
function createInactiveRecorder() {
|
|
2593
|
+
var noop = function noop() {};
|
|
2594
|
+
var recorder = {
|
|
2595
|
+
stop: noop,
|
|
2596
|
+
$rFlushCanvasCommands: noop,
|
|
2597
|
+
snapshotCanvas: noop,
|
|
2598
|
+
getSerializedNodeIdForDebug: noop,
|
|
2599
|
+
takeSubsequentFullSnapshot: noop,
|
|
2600
|
+
flushScheduledFullSnapshot: function flushScheduledFullSnapshot() {
|
|
2601
|
+
return false;
|
|
2602
|
+
},
|
|
2603
|
+
scheduleSubsequentFullSnapshot: noop,
|
|
2604
|
+
prepareForViewChange: noop,
|
|
2605
|
+
flushMutations: noop
|
|
2606
|
+
};
|
|
2607
|
+
if (false) {
|
|
2608
|
+
assign(recorder, {
|
|
2609
|
+
getLastAutoCanvasSnapshotResultForDebug: noop,
|
|
2610
|
+
getAutoCanvasSnapshotDebugHistoryForDebug: function getAutoCanvasSnapshotDebugHistoryForDebug() {
|
|
2611
|
+
return [];
|
|
2612
|
+
},
|
|
2613
|
+
getLastCanvasMutationForDebug: noop,
|
|
2614
|
+
getCanvasMutationHistoryForDebug: function getCanvasMutationHistoryForDebug() {
|
|
2615
|
+
return [];
|
|
2616
|
+
},
|
|
2617
|
+
getLastDomMutationForDebug: noop,
|
|
2618
|
+
getDomMutationHistoryForDebug: function getDomMutationHistoryForDebug() {
|
|
2619
|
+
return [];
|
|
2620
|
+
},
|
|
2621
|
+
getReplayPerformanceForDebug: noop
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
return recorder;
|
|
328
2625
|
}
|
|
329
2626
|
function materializeMutationPayload(pendingMutationPayload) {
|
|
330
2627
|
return {
|
|
@@ -354,67 +2651,67 @@ function createEmptyMutationPayload() {
|
|
|
354
2651
|
attributeApproxBytesById: new Map()
|
|
355
2652
|
};
|
|
356
2653
|
}
|
|
357
|
-
function mergeMutationPayloads(target, source) {
|
|
2654
|
+
function mergeMutationPayloads(target, source, measurements) {
|
|
358
2655
|
var merged = target || createEmptyMutationPayload();
|
|
359
|
-
mergeAddMutations(merged, source.adds);
|
|
360
|
-
mergeRemoveMutations(merged, source.removes);
|
|
361
|
-
mergeTextMutations(merged, source.texts);
|
|
362
|
-
mergeAttributeMutations(merged, source.attributes);
|
|
2656
|
+
mergeAddMutations(merged, source.adds, measurements.adds);
|
|
2657
|
+
mergeRemoveMutations(merged, source.removes, measurements.removes);
|
|
2658
|
+
mergeTextMutations(merged, source.texts, measurements.texts);
|
|
2659
|
+
mergeAttributeMutations(merged, source.attributes, measurements.attributes);
|
|
363
2660
|
updateMutationPayloadApproxBytes(merged);
|
|
364
2661
|
return merged;
|
|
365
2662
|
}
|
|
366
|
-
function mergeAddMutations(merged, sourceAdds) {
|
|
2663
|
+
function mergeAddMutations(merged, sourceAdds, sourceMeasurements) {
|
|
367
2664
|
if (!sourceAdds.length) {
|
|
368
2665
|
return;
|
|
369
2666
|
}
|
|
370
|
-
sourceAdds.forEach(function (add) {
|
|
371
|
-
var addApproxBytes =
|
|
2667
|
+
sourceAdds.forEach(function (add, index) {
|
|
2668
|
+
var addApproxBytes = sourceMeasurements[index];
|
|
372
2669
|
merged.adds.push(add);
|
|
373
2670
|
merged.addApproxBytes.push(addApproxBytes);
|
|
374
2671
|
merged.addsApproxBytes += addApproxBytes;
|
|
375
2672
|
});
|
|
376
2673
|
}
|
|
377
|
-
function mergeRemoveMutations(merged, sourceRemoves) {
|
|
2674
|
+
function mergeRemoveMutations(merged, sourceRemoves, sourceMeasurements) {
|
|
378
2675
|
if (!sourceRemoves.length) {
|
|
379
2676
|
return;
|
|
380
2677
|
}
|
|
381
|
-
sourceRemoves.forEach(function (remove) {
|
|
2678
|
+
sourceRemoves.forEach(function (remove, index) {
|
|
382
2679
|
var key = getRemoveMutationKey(remove);
|
|
383
2680
|
if (!merged.removesByKey.has(key)) {
|
|
384
2681
|
merged.removes.push(remove);
|
|
385
|
-
var removeApproxBytes =
|
|
2682
|
+
var removeApproxBytes = sourceMeasurements[index];
|
|
386
2683
|
merged.removeApproxBytesByKey.set(key, removeApproxBytes);
|
|
387
2684
|
merged.removesApproxBytes += removeApproxBytes;
|
|
388
2685
|
}
|
|
389
2686
|
merged.removesByKey.set(key, remove);
|
|
390
2687
|
});
|
|
391
2688
|
}
|
|
392
|
-
function mergeTextMutations(merged, sourceTexts) {
|
|
2689
|
+
function mergeTextMutations(merged, sourceTexts, sourceMeasurements) {
|
|
393
2690
|
if (!sourceTexts.length) {
|
|
394
2691
|
return;
|
|
395
2692
|
}
|
|
396
|
-
sourceTexts.forEach(function (textMutation) {
|
|
2693
|
+
sourceTexts.forEach(function (textMutation, index) {
|
|
397
2694
|
var existingTextMutation = merged.textsById.get(textMutation.id);
|
|
398
2695
|
if (existingTextMutation) {
|
|
399
2696
|
merged.textsApproxBytes -= merged.textApproxBytesById.get(textMutation.id) || 0;
|
|
400
2697
|
existingTextMutation.value = textMutation.value;
|
|
401
|
-
var nextTextApproxBytes =
|
|
2698
|
+
var nextTextApproxBytes = sourceMeasurements[index];
|
|
402
2699
|
merged.textApproxBytesById.set(textMutation.id, nextTextApproxBytes);
|
|
403
2700
|
merged.textsApproxBytes += nextTextApproxBytes;
|
|
404
2701
|
return;
|
|
405
2702
|
}
|
|
406
2703
|
merged.texts.push(textMutation);
|
|
407
2704
|
merged.textsById.set(textMutation.id, textMutation);
|
|
408
|
-
var textApproxBytes =
|
|
2705
|
+
var textApproxBytes = sourceMeasurements[index];
|
|
409
2706
|
merged.textApproxBytesById.set(textMutation.id, textApproxBytes);
|
|
410
2707
|
merged.textsApproxBytes += textApproxBytes;
|
|
411
2708
|
});
|
|
412
2709
|
}
|
|
413
|
-
function mergeAttributeMutations(merged, sourceAttributes) {
|
|
2710
|
+
function mergeAttributeMutations(merged, sourceAttributes, sourceMeasurements) {
|
|
414
2711
|
if (!sourceAttributes.length) {
|
|
415
2712
|
return;
|
|
416
2713
|
}
|
|
417
|
-
sourceAttributes.forEach(function (attributeMutation) {
|
|
2714
|
+
sourceAttributes.forEach(function (attributeMutation, index) {
|
|
418
2715
|
var existingAttributeMutation = merged.attributesById.get(attributeMutation.id);
|
|
419
2716
|
if (!existingAttributeMutation) {
|
|
420
2717
|
var nextAttributeMutation = {
|
|
@@ -423,7 +2720,7 @@ function mergeAttributeMutations(merged, sourceAttributes) {
|
|
|
423
2720
|
};
|
|
424
2721
|
merged.attributes.push(nextAttributeMutation);
|
|
425
2722
|
merged.attributesById.set(attributeMutation.id, nextAttributeMutation);
|
|
426
|
-
var attributeApproxBytes =
|
|
2723
|
+
var attributeApproxBytes = sourceMeasurements[index];
|
|
427
2724
|
merged.attributeApproxBytesById.set(attributeMutation.id, attributeApproxBytes);
|
|
428
2725
|
merged.attributesApproxBytes += attributeApproxBytes;
|
|
429
2726
|
return;
|
|
@@ -438,49 +2735,325 @@ function mergeAttributeMutations(merged, sourceAttributes) {
|
|
|
438
2735
|
function getRemoveMutationKey(remove) {
|
|
439
2736
|
return remove.parentId + ':' + remove.id;
|
|
440
2737
|
}
|
|
441
|
-
function shouldFlushPendingMutationPayloadBeforeMerge(target, source) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
2738
|
+
function shouldFlushPendingMutationPayloadBeforeMerge(target, source, sourceApproxBytes, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation) {
|
|
2739
|
+
// Structural arrays do not encode the order in which separate callbacks
|
|
2740
|
+
// happened. Keep callback boundaries around adds/removes so a short-lived
|
|
2741
|
+
// add cannot be replayed after its later remove. The exception is a move
|
|
2742
|
+
// reported by different document/ShadowRoot observers: its add and remove
|
|
2743
|
+
// share one private publication token and must reach the player atomically.
|
|
2744
|
+
if (hasStructuralMutationEntries(target) || hasStructuralMutationEntries(source)) {
|
|
2745
|
+
return !hasCrossCallbackMoveDependency(target, source, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation);
|
|
2746
|
+
}
|
|
2747
|
+
return target.approxBytes + sourceApproxBytes > MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
2748
|
+
}
|
|
2749
|
+
function hasStructuralMutationEntries(mutation) {
|
|
2750
|
+
return mutation.adds.length > 0 || mutation.removes.length > 0;
|
|
2751
|
+
}
|
|
2752
|
+
function hasCrossCallbackMoveDependency(first, second, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation) {
|
|
2753
|
+
return hasRemoveToAddDependency(first.removes, second.adds, second.removes, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation) || hasRemoveToAddDependency(second.removes, first.adds, first.removes, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation);
|
|
2754
|
+
}
|
|
2755
|
+
function hasRemoveToAddDependency(removes, adds, removesAlreadyPairedWithAdds, pendingPublicationTokenByNode, pendingNodeParentByNode, wasNodePublishedBeforePendingMutation) {
|
|
2756
|
+
if (!removes.length || !adds.length) {
|
|
2757
|
+
return false;
|
|
2758
|
+
}
|
|
2759
|
+
var addPublicationTokens = new Set();
|
|
2760
|
+
adds.forEach(function (add) {
|
|
2761
|
+
var publicationToken = getMutationAddPublicationToken(add);
|
|
2762
|
+
if (publicationToken) {
|
|
2763
|
+
addPublicationTokens.add(publicationToken);
|
|
463
2764
|
}
|
|
464
|
-
currentAdds.push(add);
|
|
465
|
-
currentAddsBytes += addBytes;
|
|
466
2765
|
});
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
2766
|
+
// A later remove is a new transition when the same node (or an ancestor in
|
|
2767
|
+
// the staged add tree) was already paired with this add. Keep sibling removes
|
|
2768
|
+
// eligible: one add token can contain nodes moved from several observers.
|
|
2769
|
+
var pairedRemovedNodesByPublicationToken = new Map();
|
|
2770
|
+
removesAlreadyPairedWithAdds.forEach(function (remove) {
|
|
2771
|
+
var removedNode = getMutationRemoveSourceNode(remove);
|
|
2772
|
+
if (removedNode && wasNodePublishedBeforePendingMutation(removedNode)) {
|
|
2773
|
+
var publicationToken = pendingPublicationTokenByNode.get(removedNode);
|
|
2774
|
+
if (addPublicationTokens.has(publicationToken)) {
|
|
2775
|
+
var pairedRemovedNodes = pairedRemovedNodesByPublicationToken.get(publicationToken);
|
|
2776
|
+
if (!pairedRemovedNodes) {
|
|
2777
|
+
pairedRemovedNodes = new Set();
|
|
2778
|
+
pairedRemovedNodesByPublicationToken.set(publicationToken, pairedRemovedNodes);
|
|
2779
|
+
}
|
|
2780
|
+
pairedRemovedNodes.add(removedNode);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
});
|
|
2784
|
+
return removes.some(function (remove) {
|
|
2785
|
+
var removedNode = getMutationRemoveSourceNode(remove);
|
|
2786
|
+
var publicationToken = removedNode && pendingPublicationTokenByNode.get(removedNode);
|
|
2787
|
+
return Boolean(removedNode && wasNodePublishedBeforePendingMutation(removedNode) && addPublicationTokens.has(publicationToken) && !isNodeCoveredByPairedRemove(removedNode, pairedRemovedNodesByPublicationToken.get(publicationToken), pendingNodeParentByNode));
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
function isNodeCoveredByPairedRemove(node, pairedRemovedNodes, pendingNodeParentByNode) {
|
|
2791
|
+
if (!pairedRemovedNodes) {
|
|
2792
|
+
return false;
|
|
2793
|
+
}
|
|
2794
|
+
var current = node;
|
|
2795
|
+
var depth = 0;
|
|
2796
|
+
while (current && depth < MAX_SERIALIZED_NODE_ANCESTOR_DEPTH) {
|
|
2797
|
+
if (pairedRemovedNodes.has(current)) {
|
|
2798
|
+
return true;
|
|
2799
|
+
}
|
|
2800
|
+
current = pendingNodeParentByNode.get(current);
|
|
2801
|
+
depth += 1;
|
|
2802
|
+
}
|
|
2803
|
+
return false;
|
|
2804
|
+
}
|
|
2805
|
+
function splitPendingMutationPayloadForEmit(pendingMutationPayload, pendingPublicationTokenByNode, wasNodePublishedBeforePendingMutation) {
|
|
2806
|
+
if (pendingMutationPayload.approxBytes <= MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
2807
|
+
return {
|
|
2808
|
+
mutationEntries: [[materializeMutationPayload(pendingMutationPayload), pendingMutationPayload.approxBytes]],
|
|
2809
|
+
hasOversizedEntry: false
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
var mutationEntries = [];
|
|
2813
|
+
var currentMutation = createEmptyMutation();
|
|
2814
|
+
var currentMutationBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES;
|
|
2815
|
+
var currentStructuralKind;
|
|
2816
|
+
var hasOversizedEntry = false;
|
|
2817
|
+
var structuralComponents = createStructuralMutationComponents(pendingMutationPayload, pendingPublicationTokenByNode, wasNodePublishedBeforePendingMutation);
|
|
2818
|
+
if (!structuralComponents || structuralComponents.some(function (component) {
|
|
2819
|
+
return BASE_MUTATION_PAYLOAD_APPROX_BYTES + component.approxBytes > MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
2820
|
+
})) {
|
|
2821
|
+
return {
|
|
2822
|
+
mutationEntries: [],
|
|
2823
|
+
hasOversizedEntry: true
|
|
2824
|
+
};
|
|
2825
|
+
}
|
|
2826
|
+
function pushCurrentMutation() {
|
|
2827
|
+
if (!hasMutationEntries(currentMutation)) {
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
mutationEntries.push([currentMutation, currentMutationBytes]);
|
|
2831
|
+
currentMutation = createEmptyMutation();
|
|
2832
|
+
currentMutationBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES;
|
|
2833
|
+
currentStructuralKind = undefined;
|
|
2834
|
+
}
|
|
2835
|
+
function appendEntry(type, entry, entryBytes) {
|
|
2836
|
+
if (BASE_MUTATION_PAYLOAD_APPROX_BYTES + entryBytes > MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
2837
|
+
hasOversizedEntry = true;
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
if (hasMutationEntries(currentMutation) && currentMutationBytes + entryBytes > MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
2841
|
+
pushCurrentMutation();
|
|
2842
|
+
}
|
|
2843
|
+
currentMutation[type].push(entry);
|
|
2844
|
+
currentMutationBytes += entryBytes;
|
|
2845
|
+
}
|
|
2846
|
+
structuralComponents.forEach(function (component) {
|
|
2847
|
+
var componentStructuralKind = component.removes.length ? 'dependent' : 'add';
|
|
2848
|
+
if (hasMutationEntries(currentMutation) && (currentStructuralKind !== componentStructuralKind || currentMutationBytes + component.approxBytes > MAX_MUTATION_EMIT_APPROX_BYTES)) {
|
|
2849
|
+
pushCurrentMutation();
|
|
2850
|
+
}
|
|
2851
|
+
component.adds.forEach(function (addEntry) {
|
|
2852
|
+
currentMutation.adds.push(addEntry.entry);
|
|
2853
|
+
});
|
|
2854
|
+
component.removes.forEach(function (removeEntry) {
|
|
2855
|
+
currentMutation.removes.push(removeEntry.entry);
|
|
473
2856
|
});
|
|
2857
|
+
currentMutationBytes += component.approxBytes;
|
|
2858
|
+
currentStructuralKind = componentStructuralKind;
|
|
2859
|
+
});
|
|
2860
|
+
pushCurrentMutation();
|
|
2861
|
+
pendingMutationPayload.texts.forEach(function (textMutation) {
|
|
2862
|
+
appendEntry('texts', textMutation, pendingMutationPayload.textApproxBytesById.get(textMutation.id) || estimateMutationEntryBytes(textMutation));
|
|
2863
|
+
});
|
|
2864
|
+
pendingMutationPayload.attributes.forEach(function (attributeMutation) {
|
|
2865
|
+
appendEntry('attributes', attributeMutation, pendingMutationPayload.attributeApproxBytesById.get(attributeMutation.id) || estimateMutationEntryBytes(attributeMutation));
|
|
2866
|
+
});
|
|
2867
|
+
pushCurrentMutation();
|
|
2868
|
+
return {
|
|
2869
|
+
mutationEntries: mutationEntries,
|
|
2870
|
+
hasOversizedEntry: hasOversizedEntry
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
function createStructuralMutationComponents(pendingMutationPayload, pendingPublicationTokenByNode, wasNodePublishedBeforePendingMutation) {
|
|
2874
|
+
var structuralEntries = [];
|
|
2875
|
+
var entriesByParentId = new Map();
|
|
2876
|
+
var addEntryIndexByPublicationToken = new Map();
|
|
2877
|
+
function appendStructuralEntry(type, entry, approxBytes) {
|
|
2878
|
+
var entryIndex = structuralEntries.length;
|
|
2879
|
+
var structuralEntry = {
|
|
2880
|
+
type: type,
|
|
2881
|
+
entry: entry,
|
|
2882
|
+
approxBytes: approxBytes,
|
|
2883
|
+
parent: entryIndex
|
|
2884
|
+
};
|
|
2885
|
+
structuralEntries.push(structuralEntry);
|
|
2886
|
+
var parentEntries = entriesByParentId.get(entry.parentId);
|
|
2887
|
+
if (!parentEntries) {
|
|
2888
|
+
parentEntries = {
|
|
2889
|
+
adds: [],
|
|
2890
|
+
removes: []
|
|
2891
|
+
};
|
|
2892
|
+
entriesByParentId.set(entry.parentId, parentEntries);
|
|
2893
|
+
}
|
|
2894
|
+
parentEntries[type].push(entryIndex);
|
|
2895
|
+
if (type === 'adds') {
|
|
2896
|
+
var publicationToken = getMutationAddPublicationToken(entry);
|
|
2897
|
+
if (publicationToken) {
|
|
2898
|
+
addEntryIndexByPublicationToken.set(publicationToken, entryIndex);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
474
2901
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
2902
|
+
pendingMutationPayload.adds.forEach(function (add, index) {
|
|
2903
|
+
appendStructuralEntry('adds', add, pendingMutationPayload.addApproxBytes[index]);
|
|
2904
|
+
});
|
|
2905
|
+
pendingMutationPayload.removes.forEach(function (remove) {
|
|
2906
|
+
appendStructuralEntry('removes', remove, pendingMutationPayload.removeApproxBytesByKey.get(getRemoveMutationKey(remove)) || estimateMutationEntryBytes(remove));
|
|
2907
|
+
});
|
|
2908
|
+
function findRoot(entryIndex) {
|
|
2909
|
+
var structuralEntry = structuralEntries[entryIndex];
|
|
2910
|
+
while (structuralEntry.parent !== entryIndex) {
|
|
2911
|
+
structuralEntry.parent = structuralEntries[structuralEntry.parent].parent;
|
|
2912
|
+
entryIndex = structuralEntry.parent;
|
|
2913
|
+
structuralEntry = structuralEntries[entryIndex];
|
|
2914
|
+
}
|
|
2915
|
+
return entryIndex;
|
|
2916
|
+
}
|
|
2917
|
+
function connectEntries(firstEntryIndex, secondEntryIndex) {
|
|
2918
|
+
var firstRoot = findRoot(firstEntryIndex);
|
|
2919
|
+
var secondRoot = findRoot(secondEntryIndex);
|
|
2920
|
+
if (firstRoot !== secondRoot) {
|
|
2921
|
+
structuralEntries[secondRoot].parent = firstRoot;
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
// A remove and its replacement additions must be replayed together. Keep
|
|
2926
|
+
// this dependency scoped to the mutated parent instead of turning every
|
|
2927
|
+
// replacement in the pending window into one global transaction.
|
|
2928
|
+
entriesByParentId.forEach(function (parentEntries) {
|
|
2929
|
+
if (!parentEntries.adds.length || !parentEntries.removes.length) {
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
var firstEntryIndex = parentEntries.adds[0];
|
|
2933
|
+
parentEntries.adds.slice(1).forEach(function (entryIndex) {
|
|
2934
|
+
connectEntries(firstEntryIndex, entryIndex);
|
|
2935
|
+
});
|
|
2936
|
+
parentEntries.removes.forEach(function (entryIndex) {
|
|
2937
|
+
connectEntries(firstEntryIndex, entryIndex);
|
|
2938
|
+
});
|
|
2939
|
+
});
|
|
2940
|
+
|
|
2941
|
+
// A published move can cross document and ShadowRoot observers. The source
|
|
2942
|
+
// node carries the destination add's private publication token, which is the
|
|
2943
|
+
// causal edge joining the source and destination parent components.
|
|
2944
|
+
structuralEntries.forEach(function (structuralEntry, entryIndex) {
|
|
2945
|
+
if (structuralEntry.type !== 'removes') {
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
var removedNode = getMutationRemoveSourceNode(structuralEntry.entry);
|
|
2949
|
+
if (!removedNode || !wasNodePublishedBeforePendingMutation(removedNode)) {
|
|
2950
|
+
return;
|
|
2951
|
+
}
|
|
2952
|
+
var addEntryIndex = addEntryIndexByPublicationToken.get(pendingPublicationTokenByNode.get(removedNode));
|
|
2953
|
+
if (typeof addEntryIndex === 'number') {
|
|
2954
|
+
connectEntries(entryIndex, addEntryIndex);
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2957
|
+
var componentsByRoot = new Map();
|
|
2958
|
+
structuralEntries.forEach(function (structuralEntry, entryIndex) {
|
|
2959
|
+
var root = findRoot(entryIndex);
|
|
2960
|
+
var component = componentsByRoot.get(root);
|
|
2961
|
+
if (!component) {
|
|
2962
|
+
component = {
|
|
2963
|
+
adds: [],
|
|
2964
|
+
removes: [],
|
|
2965
|
+
approxBytes: 0,
|
|
2966
|
+
sequence: entryIndex,
|
|
2967
|
+
dependencies: new Set()
|
|
2968
|
+
};
|
|
2969
|
+
componentsByRoot.set(root, component);
|
|
2970
|
+
}
|
|
2971
|
+
component[structuralEntry.type].push(structuralEntry);
|
|
2972
|
+
component.approxBytes += structuralEntry.approxBytes;
|
|
2973
|
+
component.sequence = Math.min(component.sequence, entryIndex);
|
|
2974
|
+
});
|
|
2975
|
+
var components = Array.from(componentsByRoot.values());
|
|
2976
|
+
var addComponentByNodeId = new Map();
|
|
2977
|
+
components.forEach(function (component) {
|
|
2978
|
+
component.adds.forEach(function (addEntry) {
|
|
2979
|
+
addComponentByNodeId.set(addEntry.entry.node.id, component);
|
|
2980
|
+
});
|
|
2981
|
+
});
|
|
2982
|
+
components.forEach(function (component) {
|
|
2983
|
+
component.adds.forEach(function (addEntry) {
|
|
2984
|
+
var dependencyNodeIds = [addEntry.entry.parentId, addEntry.entry.nextId];
|
|
2985
|
+
dependencyNodeIds.forEach(function (dependencyNodeId) {
|
|
2986
|
+
var dependencyComponent = addComponentByNodeId.get(dependencyNodeId);
|
|
2987
|
+
if (dependencyComponent && dependencyComponent !== component) {
|
|
2988
|
+
component.dependencies.add(dependencyComponent);
|
|
2989
|
+
}
|
|
2990
|
+
});
|
|
481
2991
|
});
|
|
2992
|
+
});
|
|
2993
|
+
|
|
2994
|
+
// Mutation serialization orders sibling roots so an add's nextId is already
|
|
2995
|
+
// published. Preserve that ordering across split payloads, including when a
|
|
2996
|
+
// replacement or move has joined entries that were originally separate.
|
|
2997
|
+
components.sort(function (first, second) {
|
|
2998
|
+
return first.sequence - second.sequence;
|
|
2999
|
+
});
|
|
3000
|
+
var orderedComponents = [];
|
|
3001
|
+
var visitedComponents = new Set();
|
|
3002
|
+
var visitingComponents = new Set();
|
|
3003
|
+
var hasDependencyCycle = false;
|
|
3004
|
+
function visitComponent(component) {
|
|
3005
|
+
if (visitedComponents.has(component)) {
|
|
3006
|
+
return;
|
|
3007
|
+
}
|
|
3008
|
+
if (visitingComponents.has(component)) {
|
|
3009
|
+
hasDependencyCycle = true;
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
visitingComponents.add(component);
|
|
3013
|
+
Array.from(component.dependencies).sort(function (first, second) {
|
|
3014
|
+
return first.sequence - second.sequence;
|
|
3015
|
+
}).forEach(visitComponent);
|
|
3016
|
+
visitingComponents["delete"](component);
|
|
3017
|
+
visitedComponents.add(component);
|
|
3018
|
+
orderedComponents.push(component);
|
|
482
3019
|
}
|
|
483
|
-
|
|
3020
|
+
components.forEach(visitComponent);
|
|
3021
|
+
return hasDependencyCycle ? undefined : orderedComponents;
|
|
3022
|
+
}
|
|
3023
|
+
function partitionMutationPayloadByEntrySize(mutation, measurements) {
|
|
3024
|
+
var safeMutation = createEmptyMutation();
|
|
3025
|
+
var safeMeasurements = {
|
|
3026
|
+
adds: [],
|
|
3027
|
+
removes: [],
|
|
3028
|
+
texts: [],
|
|
3029
|
+
attributes: [],
|
|
3030
|
+
approxBytes: BASE_MUTATION_PAYLOAD_APPROX_BYTES
|
|
3031
|
+
};
|
|
3032
|
+
var hasOversizedEntry = false;
|
|
3033
|
+
['adds', 'removes', 'texts', 'attributes'].forEach(function (type) {
|
|
3034
|
+
mutation[type].forEach(function (entry, index) {
|
|
3035
|
+
var entryBytes = measurements[type][index];
|
|
3036
|
+
if (BASE_MUTATION_PAYLOAD_APPROX_BYTES + entryBytes > MAX_MUTATION_EMIT_APPROX_BYTES) {
|
|
3037
|
+
hasOversizedEntry = true;
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
safeMutation[type].push(entry);
|
|
3041
|
+
safeMeasurements[type].push(entryBytes);
|
|
3042
|
+
safeMeasurements.approxBytes += entryBytes;
|
|
3043
|
+
});
|
|
3044
|
+
});
|
|
3045
|
+
return {
|
|
3046
|
+
mutation: safeMutation,
|
|
3047
|
+
measurements: safeMeasurements,
|
|
3048
|
+
hasOversizedEntry: hasOversizedEntry
|
|
3049
|
+
};
|
|
3050
|
+
}
|
|
3051
|
+
function hasOversizedMutationEntry(measurements) {
|
|
3052
|
+
return ['adds', 'removes', 'texts', 'attributes'].some(function (type) {
|
|
3053
|
+
return measurements[type].some(function (entryBytes) {
|
|
3054
|
+
return BASE_MUTATION_PAYLOAD_APPROX_BYTES + entryBytes > MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
3055
|
+
});
|
|
3056
|
+
});
|
|
484
3057
|
}
|
|
485
3058
|
function createEmptyMutation() {
|
|
486
3059
|
return {
|
|
@@ -490,17 +3063,92 @@ function createEmptyMutation() {
|
|
|
490
3063
|
attributes: []
|
|
491
3064
|
};
|
|
492
3065
|
}
|
|
3066
|
+
function hasMutationEntries(mutation) {
|
|
3067
|
+
return mutation.adds.length > 0 || mutation.removes.length > 0 || mutation.texts.length > 0 || mutation.attributes.length > 0;
|
|
3068
|
+
}
|
|
493
3069
|
var BASE_MUTATION_PAYLOAD_APPROX_BYTES = 64;
|
|
494
|
-
function
|
|
495
|
-
|
|
3070
|
+
function measureMutationPayload(mutation) {
|
|
3071
|
+
var measurements = {
|
|
3072
|
+
adds: measureMutationEntries(mutation.adds),
|
|
3073
|
+
removes: measureMutationEntries(mutation.removes),
|
|
3074
|
+
texts: measureMutationEntries(mutation.texts),
|
|
3075
|
+
attributes: measureMutationEntries(mutation.attributes)
|
|
3076
|
+
};
|
|
3077
|
+
measurements.approxBytes = BASE_MUTATION_PAYLOAD_APPROX_BYTES + sumMutationEntryMeasurements(measurements.adds) + sumMutationEntryMeasurements(measurements.removes) + sumMutationEntryMeasurements(measurements.texts) + sumMutationEntryMeasurements(measurements.attributes);
|
|
3078
|
+
return measurements;
|
|
496
3079
|
}
|
|
497
3080
|
function estimateMutationEntryBytes(entry) {
|
|
498
|
-
|
|
3081
|
+
var approxBytes = 2;
|
|
3082
|
+
Object.keys(entry).forEach(function (key) {
|
|
3083
|
+
approxBytes += estimateMutationJsonStringBytes(key) + 2;
|
|
3084
|
+
if (key === 'node') {
|
|
3085
|
+
approxBytes += getSerializedNodeApproxBytes(entry.node) || estimateJsonValueBytes(entry.node);
|
|
3086
|
+
} else {
|
|
3087
|
+
approxBytes += estimateJsonValueBytes(entry[key]);
|
|
3088
|
+
}
|
|
3089
|
+
});
|
|
3090
|
+
return approxBytes;
|
|
499
3091
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
3092
|
+
function estimateJsonValueBytes(value, maxApproxBytes) {
|
|
3093
|
+
if (typeof maxApproxBytes !== 'number') {
|
|
3094
|
+
maxApproxBytes = MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
3095
|
+
}
|
|
3096
|
+
var approxBytes = 0;
|
|
3097
|
+
var pendingValues = [value];
|
|
3098
|
+
while (pendingValues.length && approxBytes <= maxApproxBytes) {
|
|
3099
|
+
var current = pendingValues.pop();
|
|
3100
|
+
if (typeof current === 'string') {
|
|
3101
|
+
approxBytes += estimateMutationJsonStringBytes(current, maxApproxBytes);
|
|
3102
|
+
} else if (typeof current === 'number') {
|
|
3103
|
+
approxBytes += 16;
|
|
3104
|
+
} else if (typeof current === 'boolean') {
|
|
3105
|
+
approxBytes += 5;
|
|
3106
|
+
} else if (current && _typeof(current) === 'object') {
|
|
3107
|
+
if (Array.isArray(current)) {
|
|
3108
|
+
approxBytes += current.length + 2;
|
|
3109
|
+
for (var index = 0; index < current.length; index += 1) {
|
|
3110
|
+
pendingValues.push(current[index]);
|
|
3111
|
+
}
|
|
3112
|
+
} else {
|
|
3113
|
+
Object.keys(current).forEach(function (key) {
|
|
3114
|
+
approxBytes += estimateMutationJsonStringBytes(key) + 2;
|
|
3115
|
+
pendingValues.push(current[key]);
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
} else {
|
|
3119
|
+
approxBytes += 4;
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
return approxBytes;
|
|
3123
|
+
}
|
|
3124
|
+
function estimateMutationJsonStringBytes(value, maxApproxBytes) {
|
|
3125
|
+
if (typeof maxApproxBytes !== 'number') {
|
|
3126
|
+
maxApproxBytes = MAX_MUTATION_EMIT_APPROX_BYTES;
|
|
3127
|
+
}
|
|
3128
|
+
if (value.length * 2 + 4 > maxApproxBytes) {
|
|
3129
|
+
return maxApproxBytes + 1;
|
|
3130
|
+
}
|
|
3131
|
+
var bytes = 4;
|
|
3132
|
+
for (var index = 0; index < value.length; index += 1) {
|
|
3133
|
+
var characterCode = value.charCodeAt(index);
|
|
3134
|
+
bytes += characterCode <= 0x1f || characterCode === 0x22 || characterCode === 0x5c ? 12 : 2;
|
|
3135
|
+
if (bytes > maxApproxBytes) {
|
|
3136
|
+
return bytes;
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
return bytes;
|
|
3140
|
+
}
|
|
3141
|
+
function measureMutationEntries(entries) {
|
|
3142
|
+
var measurements = [];
|
|
502
3143
|
for (var i = 0; i < entries.length; i += 1) {
|
|
503
|
-
|
|
3144
|
+
measurements.push(estimateMutationEntryBytes(entries[i]));
|
|
3145
|
+
}
|
|
3146
|
+
return measurements;
|
|
3147
|
+
}
|
|
3148
|
+
function sumMutationEntryMeasurements(measurements) {
|
|
3149
|
+
var total = 0;
|
|
3150
|
+
for (var i = 0; i < measurements.length; i += 1) {
|
|
3151
|
+
total += measurements[i];
|
|
504
3152
|
}
|
|
505
3153
|
return total;
|
|
506
3154
|
}
|
|
@@ -511,12 +3159,22 @@ function createReplayPerformanceStats() {
|
|
|
511
3159
|
return {
|
|
512
3160
|
processMutationsCount: 0,
|
|
513
3161
|
processMutationsDuration: 0,
|
|
3162
|
+
mutationSerializationCount: 0,
|
|
3163
|
+
mutationSerializationDuration: 0,
|
|
3164
|
+
mutationLocalDropCount: 0,
|
|
3165
|
+
mutationLocalDropLastReason: undefined,
|
|
3166
|
+
mutationDropRecoveryCount: 0,
|
|
3167
|
+
mutationDropRecoveryLastReason: undefined,
|
|
3168
|
+
admissionGapRecoveryCount: 0,
|
|
3169
|
+
admissionGapRecoveryLastReason: undefined,
|
|
514
3170
|
mutationCallbackCount: 0,
|
|
515
3171
|
mutationRecordCount: 0,
|
|
516
3172
|
mutationAddCount: 0,
|
|
517
3173
|
mutationRemoveCount: 0,
|
|
518
3174
|
mutationTextCount: 0,
|
|
519
|
-
mutationAttributeCount: 0
|
|
3175
|
+
mutationAttributeCount: 0,
|
|
3176
|
+
fullSnapshotCount: 0,
|
|
3177
|
+
fullSnapshotDuration: 0
|
|
520
3178
|
};
|
|
521
3179
|
}
|
|
522
3180
|
function accumulateReplayPerformanceStats(stats, delta) {
|
|
@@ -525,12 +3183,28 @@ function accumulateReplayPerformanceStats(stats, delta) {
|
|
|
525
3183
|
}
|
|
526
3184
|
stats.processMutationsCount += delta.processMutationsCount || 0;
|
|
527
3185
|
stats.processMutationsDuration += delta.processMutationsDuration || 0;
|
|
3186
|
+
stats.mutationSerializationCount += delta.mutationSerializationCount || 0;
|
|
3187
|
+
stats.mutationSerializationDuration += delta.mutationSerializationDuration || 0;
|
|
3188
|
+
stats.mutationLocalDropCount += delta.mutationLocalDropCount || 0;
|
|
3189
|
+
if (delta.mutationLocalDropReason) {
|
|
3190
|
+
stats.mutationLocalDropLastReason = delta.mutationLocalDropReason;
|
|
3191
|
+
}
|
|
3192
|
+
stats.mutationDropRecoveryCount += delta.mutationDropRecoveryCount || 0;
|
|
3193
|
+
if (delta.mutationDropRecoveryLastReason) {
|
|
3194
|
+
stats.mutationDropRecoveryLastReason = delta.mutationDropRecoveryLastReason;
|
|
3195
|
+
}
|
|
3196
|
+
stats.admissionGapRecoveryCount += delta.admissionGapRecoveryCount || 0;
|
|
3197
|
+
if (delta.admissionGapRecoveryLastReason) {
|
|
3198
|
+
stats.admissionGapRecoveryLastReason = delta.admissionGapRecoveryLastReason;
|
|
3199
|
+
}
|
|
528
3200
|
stats.mutationCallbackCount += delta.mutationCallbackCount || 0;
|
|
529
3201
|
stats.mutationRecordCount += delta.mutationRecordCount || 0;
|
|
530
3202
|
stats.mutationAddCount += delta.mutationAddCount || 0;
|
|
531
3203
|
stats.mutationRemoveCount += delta.mutationRemoveCount || 0;
|
|
532
3204
|
stats.mutationTextCount += delta.mutationTextCount || 0;
|
|
533
3205
|
stats.mutationAttributeCount += delta.mutationAttributeCount || 0;
|
|
3206
|
+
stats.fullSnapshotCount += delta.fullSnapshotCount || 0;
|
|
3207
|
+
stats.fullSnapshotDuration += delta.fullSnapshotDuration || 0;
|
|
534
3208
|
}
|
|
535
3209
|
function countMutationPayloadRecords(mutation) {
|
|
536
3210
|
return mutation.adds.length + mutation.removes.length + mutation.texts.length + mutation.attributes.length;
|
|
@@ -542,20 +3216,39 @@ function cloneReplayPerformanceStats(stats) {
|
|
|
542
3216
|
return {
|
|
543
3217
|
processMutationsCount: stats.processMutationsCount,
|
|
544
3218
|
processMutationsDuration: Math.round(stats.processMutationsDuration * 10) / 10,
|
|
3219
|
+
mutationSerializationCount: stats.mutationSerializationCount,
|
|
3220
|
+
mutationSerializationDuration: Math.round(stats.mutationSerializationDuration * 10) / 10,
|
|
3221
|
+
mutationLocalDropCount: stats.mutationLocalDropCount,
|
|
3222
|
+
mutationLocalDropLastReason: stats.mutationLocalDropLastReason,
|
|
3223
|
+
mutationDropRecoveryCount: stats.mutationDropRecoveryCount,
|
|
3224
|
+
mutationDropRecoveryLastReason: stats.mutationDropRecoveryLastReason,
|
|
3225
|
+
admissionGapRecoveryCount: stats.admissionGapRecoveryCount,
|
|
3226
|
+
admissionGapRecoveryLastReason: stats.admissionGapRecoveryLastReason,
|
|
545
3227
|
mutationCallbackCount: stats.mutationCallbackCount,
|
|
546
3228
|
mutationRecordCount: stats.mutationRecordCount,
|
|
547
3229
|
mutationAddCount: stats.mutationAddCount,
|
|
548
3230
|
mutationRemoveCount: stats.mutationRemoveCount,
|
|
549
3231
|
mutationTextCount: stats.mutationTextCount,
|
|
550
|
-
mutationAttributeCount: stats.mutationAttributeCount
|
|
3232
|
+
mutationAttributeCount: stats.mutationAttributeCount,
|
|
3233
|
+
fullSnapshotCount: stats.fullSnapshotCount,
|
|
3234
|
+
fullSnapshotDuration: Math.round(stats.fullSnapshotDuration * 10) / 10
|
|
551
3235
|
};
|
|
552
3236
|
}
|
|
553
|
-
function
|
|
3237
|
+
function getPerformanceTime() {
|
|
3238
|
+
if (typeof performance !== 'undefined' && performance.now) {
|
|
3239
|
+
return performance.now();
|
|
3240
|
+
}
|
|
3241
|
+
return Date.now();
|
|
3242
|
+
}
|
|
3243
|
+
function pushCanvasDebugHistoryEntry(history, entry, limit) {
|
|
554
3244
|
if (!entry) {
|
|
555
3245
|
return;
|
|
556
3246
|
}
|
|
3247
|
+
if (typeof limit !== 'number') {
|
|
3248
|
+
limit = CANVAS_DEBUG_HISTORY_LIMIT;
|
|
3249
|
+
}
|
|
557
3250
|
history.push(entry);
|
|
558
|
-
if (history.length >
|
|
3251
|
+
if (history.length > limit) {
|
|
559
3252
|
history.shift();
|
|
560
3253
|
}
|
|
561
3254
|
}
|
|
@@ -630,32 +3323,100 @@ function cloneCanvasMutationDebugResult(result) {
|
|
|
630
3323
|
}
|
|
631
3324
|
return clonedResult;
|
|
632
3325
|
}
|
|
633
|
-
function
|
|
3326
|
+
function createDomMutationDebugSummary(result) {
|
|
634
3327
|
if (!result) {
|
|
635
3328
|
return result;
|
|
636
3329
|
}
|
|
637
3330
|
return {
|
|
638
|
-
timestamp:
|
|
639
|
-
adds: (result.adds
|
|
640
|
-
removes: (result.removes
|
|
641
|
-
texts: (result.texts
|
|
642
|
-
attributes: (result.attributes
|
|
3331
|
+
timestamp: timeStampNow(),
|
|
3332
|
+
adds: summarizeDomMutationEntries(result.adds, summarizeAddMutation),
|
|
3333
|
+
removes: summarizeDomMutationEntries(result.removes, summarizeRemoveMutation),
|
|
3334
|
+
texts: summarizeDomMutationEntries(result.texts, summarizeTextMutation),
|
|
3335
|
+
attributes: summarizeDomMutationEntries(result.attributes, summarizeAttributeMutation),
|
|
643
3336
|
addsCount: (result.adds || []).length,
|
|
644
3337
|
removesCount: (result.removes || []).length,
|
|
645
3338
|
textsCount: (result.texts || []).length,
|
|
646
3339
|
attributesCount: (result.attributes || []).length
|
|
647
3340
|
};
|
|
648
3341
|
}
|
|
649
|
-
function
|
|
650
|
-
|
|
651
|
-
|
|
3342
|
+
function summarizeDomMutationEntries(entries, summarizeEntry) {
|
|
3343
|
+
var summaries = [];
|
|
3344
|
+
var entryCount = Math.min((entries || []).length, DOM_MUTATION_DEBUG_SAMPLE_LIMIT);
|
|
3345
|
+
for (var index = 0; index < entryCount; index += 1) {
|
|
3346
|
+
summaries.push(summarizeEntry(entries[index]));
|
|
3347
|
+
}
|
|
3348
|
+
return summaries;
|
|
3349
|
+
}
|
|
3350
|
+
function summarizeAddMutation(add) {
|
|
3351
|
+
var summary = {
|
|
3352
|
+
parentId: add.parentId,
|
|
3353
|
+
nextId: add.nextId
|
|
3354
|
+
};
|
|
3355
|
+
if (add.node) {
|
|
3356
|
+
summary.node = {
|
|
3357
|
+
id: add.node.id,
|
|
3358
|
+
type: add.node.type,
|
|
3359
|
+
tagName: add.node.tagName
|
|
3360
|
+
};
|
|
3361
|
+
}
|
|
3362
|
+
return summary;
|
|
3363
|
+
}
|
|
3364
|
+
function summarizeRemoveMutation(remove) {
|
|
3365
|
+
return {
|
|
3366
|
+
parentId: remove.parentId,
|
|
3367
|
+
id: remove.id
|
|
3368
|
+
};
|
|
3369
|
+
}
|
|
3370
|
+
function summarizeTextMutation(textMutation) {
|
|
3371
|
+
return {
|
|
3372
|
+
id: textMutation.id,
|
|
3373
|
+
valueLength: typeof textMutation.value === 'string' ? textMutation.value.length : 0
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
function summarizeAttributeMutation(attributeMutation) {
|
|
3377
|
+
var attributeNames = [];
|
|
3378
|
+
var attributeNamesTruncated = false;
|
|
3379
|
+
var attributes = attributeMutation.attributes || {};
|
|
3380
|
+
for (var attributeName in attributes) {
|
|
3381
|
+
if (!Object.prototype.hasOwnProperty.call(attributes, attributeName)) {
|
|
3382
|
+
continue;
|
|
3383
|
+
}
|
|
3384
|
+
if (attributeNames.length >= DOM_MUTATION_DEBUG_SAMPLE_LIMIT) {
|
|
3385
|
+
attributeNamesTruncated = true;
|
|
3386
|
+
break;
|
|
3387
|
+
}
|
|
3388
|
+
attributeNames.push(attributeName);
|
|
3389
|
+
}
|
|
3390
|
+
return {
|
|
3391
|
+
id: attributeMutation.id,
|
|
3392
|
+
attributeNames: attributeNames,
|
|
3393
|
+
attributeNamesTruncated: attributeNamesTruncated
|
|
3394
|
+
};
|
|
3395
|
+
}
|
|
3396
|
+
function cloneDomMutationDebugResult(result) {
|
|
3397
|
+
if (!result) {
|
|
3398
|
+
return result;
|
|
3399
|
+
}
|
|
3400
|
+
return {
|
|
3401
|
+
timestamp: result.timestamp,
|
|
3402
|
+
adds: result.adds.map(cloneDomMutationDebugEntry),
|
|
3403
|
+
removes: result.removes.map(cloneDomMutationDebugEntry),
|
|
3404
|
+
texts: result.texts.map(cloneDomMutationDebugEntry),
|
|
3405
|
+
attributes: result.attributes.map(cloneDomMutationDebugEntry),
|
|
3406
|
+
addsCount: result.addsCount,
|
|
3407
|
+
removesCount: result.removesCount,
|
|
3408
|
+
textsCount: result.textsCount,
|
|
3409
|
+
attributesCount: result.attributesCount
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
function cloneDomMutationDebugEntry(entry) {
|
|
3413
|
+
var clonedEntry = assign({}, entry);
|
|
3414
|
+
if (entry.node) {
|
|
3415
|
+
clonedEntry.node = assign({}, entry.node);
|
|
652
3416
|
}
|
|
653
|
-
if (
|
|
654
|
-
|
|
3417
|
+
if (entry.attributeNames) {
|
|
3418
|
+
clonedEntry.attributeNames = entry.attributeNames.slice();
|
|
655
3419
|
}
|
|
656
|
-
return
|
|
657
|
-
accumulator[key] = cloneDebugValue(value[key]);
|
|
658
|
-
return accumulator;
|
|
659
|
-
}, {});
|
|
3420
|
+
return clonedEntry;
|
|
660
3421
|
}
|
|
661
3422
|
//# sourceMappingURL=record.js.map
|