@cloudcare/browser-rum 3.3.6 → 3.3.8
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 +1 -0
- 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 +1 -0
- 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 +1 -0
- 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 +2 -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 +1 -0
- 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 +1 -0
- 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/contexts/viewContexts.js +3 -1
- 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/resource/resourceCollection.js +1 -0
- package/src/domain/rumEventsCollection/resource/webSocketCollection.js +1 -0
- 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
|
@@ -2,7 +2,10 @@ import {
|
|
|
2
2
|
ONE_SECOND,
|
|
3
3
|
LifeCycleEventType,
|
|
4
4
|
isPageExitReason,
|
|
5
|
+
PageExitReason,
|
|
5
6
|
assign,
|
|
7
|
+
addTelemetryDebug,
|
|
8
|
+
dateNow,
|
|
6
9
|
setTimeout,
|
|
7
10
|
clearTimeout
|
|
8
11
|
} from '@cloudcare/browser-core'
|
|
@@ -16,6 +19,15 @@ export var SEGMENT_DURATION_LIMIT = 5 * ONE_SECOND
|
|
|
16
19
|
* ensure that we leave room for logs, rum and potential other users
|
|
17
20
|
*/
|
|
18
21
|
export var SEGMENT_BYTES_LIMIT = 60000
|
|
22
|
+
// buildReplayPayload() exposes the compressed segment size, but sendBeacon
|
|
23
|
+
// accounts for the multipart boundaries, headers, and metadata fields too.
|
|
24
|
+
// Reserve a conservative envelope per segment so several small unload
|
|
25
|
+
// segments cannot collectively overrun the browser's exit delivery queue.
|
|
26
|
+
var SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD = 2 * 1024
|
|
27
|
+
var SEGMENT_PENDING_RAW_BYTES_LIMIT = 4 * 1024 * 1024
|
|
28
|
+
var LOCKED_SEGMENTS_LIMIT = 12
|
|
29
|
+
var CANVAS_FLUSH_MIN_INTERVAL = 250
|
|
30
|
+
var MAX_CONSECUTIVE_FULL_SNAPSHOT_FAILURES = 3
|
|
19
31
|
|
|
20
32
|
// Segments are the main data structure for session replays. They contain context information used
|
|
21
33
|
// for indexing or UI needs, and a list of records (RRWeb 'events', renamed to avoid confusing
|
|
@@ -62,9 +74,13 @@ export function startSegmentCollection(
|
|
|
62
74
|
isLocked,
|
|
63
75
|
assign(
|
|
64
76
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
flushCanvasImmediately: configuration.replayCanvasFlushImmediately,
|
|
78
|
+
pendingRawBytesLimit: SEGMENT_PENDING_RAW_BYTES_LIMIT,
|
|
79
|
+
beforePageExitFlush: undefined,
|
|
80
|
+
onReplayResetNeeded: undefined,
|
|
81
|
+
onReplayResetExhausted: undefined,
|
|
82
|
+
onSegmentFlushed: undefined
|
|
83
|
+
},
|
|
68
84
|
additionalOptions
|
|
69
85
|
)
|
|
70
86
|
)
|
|
@@ -87,10 +103,60 @@ export function doStartSegmentCollection(
|
|
|
87
103
|
if (options === undefined) {
|
|
88
104
|
options = {}
|
|
89
105
|
}
|
|
106
|
+
var pendingRawBytesLimit =
|
|
107
|
+
typeof options.pendingRawBytesLimit === 'number'
|
|
108
|
+
? options.pendingRawBytesLimit
|
|
109
|
+
: SEGMENT_PENDING_RAW_BYTES_LIMIT
|
|
110
|
+
var lockedSegments = []
|
|
111
|
+
var lockedBufferGeneration = 0
|
|
112
|
+
var reportedDropReasons = {}
|
|
113
|
+
var lastCanvasFlushAt = -Infinity
|
|
114
|
+
var canvasFlushTimeoutId
|
|
115
|
+
var replayResetNeeded = false
|
|
116
|
+
var replayResetReason
|
|
117
|
+
var replayResetNotificationSent = false
|
|
118
|
+
var replayResetNotificationTimeoutId
|
|
119
|
+
var activeBaselineGeneration = 0
|
|
120
|
+
var nextBaselineGeneration = 0
|
|
121
|
+
var baselineGenerationStates = {}
|
|
122
|
+
var transportGenerationStates = {}
|
|
123
|
+
var baselineGenerationInFlightCounts = {}
|
|
124
|
+
var pendingSegmentResultsByGeneration = {}
|
|
125
|
+
var consecutiveFullSnapshotFailures = 0
|
|
126
|
+
var replayRecoveryExhausted = false
|
|
127
|
+
var lifecycleSubscriptionsStopped = false
|
|
128
|
+
var nextSegmentFlushSequence = 0
|
|
129
|
+
var inFlightSegmentFlushes = new Set()
|
|
130
|
+
var lastAddRecordWasBackpressured = false
|
|
131
|
+
var backpressuredSerializedRecordData = new WeakMap()
|
|
132
|
+
var unloadingTransportLatched = false
|
|
133
|
+
var unloadingDeliveryBytesRemaining
|
|
134
|
+
var unloadingDeliveryBudgetExhausted = false
|
|
135
|
+
var unloadingRetryPayloadsDrained = false
|
|
136
|
+
var mandatoryRecoveryPending = false
|
|
137
|
+
var bufferCheckoutPending = false
|
|
138
|
+
var activeBaselineTransaction
|
|
90
139
|
var state = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
140
|
+
$rStatus: SegmentCollectionStatus.WaitingForInitialRecord,
|
|
141
|
+
$rNextReason: 'init',
|
|
142
|
+
$rLocked: isLocked,
|
|
143
|
+
$rGeneration: activeBaselineGeneration
|
|
144
|
+
}
|
|
145
|
+
function prepareRecordsBeforePageExit(pageExitEvent) {
|
|
146
|
+
if (!options.beforePageExitFlush) {
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
options.beforePageExitFlush(pageExitEvent)
|
|
151
|
+
} catch (error) {
|
|
152
|
+
addTelemetryDebug(
|
|
153
|
+
'Session Replay failed to prepare records before page exit.',
|
|
154
|
+
{
|
|
155
|
+
reason: pageExitEvent && pageExitEvent.reason,
|
|
156
|
+
error: String(error)
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
}
|
|
94
160
|
}
|
|
95
161
|
var subscribeViewCreated = lifeCycle.subscribe(
|
|
96
162
|
LifeCycleEventType.VIEW_CREATED,
|
|
@@ -102,119 +168,1276 @@ export function doStartSegmentCollection(
|
|
|
102
168
|
var subscribePageExited = lifeCycle.subscribe(
|
|
103
169
|
LifeCycleEventType.PAGE_EXITED,
|
|
104
170
|
function (pageExitEvent) {
|
|
171
|
+
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
prepareRecordsBeforePageExit(pageExitEvent)
|
|
175
|
+
upgradeSegmentTransportsForPageExit(pageExitEvent.reason)
|
|
176
|
+
if (
|
|
177
|
+
state.$rLocked &&
|
|
178
|
+
pageExitEvent.reason === PageExitReason.UNLOADING
|
|
179
|
+
) {
|
|
180
|
+
lockedBufferGeneration += 1
|
|
181
|
+
lockedSegments = []
|
|
182
|
+
}
|
|
105
183
|
flushSegment(pageExitEvent.reason)
|
|
184
|
+
if (flushPendingSegmentEncodingsForUnload(pageExitEvent.reason)) {
|
|
185
|
+
// The synchronous drain releases encoder backpressure. Give staged DOM
|
|
186
|
+
// mutations one final admission pass, then flush that second segment
|
|
187
|
+
// through the same unload-safe transport.
|
|
188
|
+
prepareRecordsBeforePageExit(pageExitEvent)
|
|
189
|
+
flushSegment(pageExitEvent.reason)
|
|
190
|
+
flushPendingSegmentEncodingsForUnload(pageExitEvent.reason)
|
|
191
|
+
}
|
|
106
192
|
}
|
|
107
193
|
)
|
|
108
194
|
var unsubscribePageExited = subscribePageExited.unsubscribe
|
|
109
|
-
const lockedFlushReason = ['view_change', 'buffer_checkout']
|
|
110
|
-
function flushSegment(flushReason, callback) {
|
|
111
|
-
const isLocked = state.isLocked
|
|
112
|
-
if (state.status === SegmentCollectionStatus.SegmentPending) {
|
|
113
|
-
if (isLocked && lockedFlushReason.includes(flushReason)) {
|
|
114
|
-
state.segment.flush(() => {
|
|
115
|
-
if (callback) callback()
|
|
116
|
-
})
|
|
117
|
-
} else {
|
|
118
|
-
// if the segment is locked, we don't send it
|
|
119
|
-
if (isLocked) {
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
state.segment.flush(function (metadata, encoderResult, recordCountsByType) {
|
|
123
|
-
if (options.onSegmentFlushed) {
|
|
124
|
-
options.onSegmentFlushed({
|
|
125
|
-
creationReason: metadata.creation_reason,
|
|
126
|
-
flushReason: flushReason,
|
|
127
|
-
recordsCount: metadata.records_count,
|
|
128
|
-
recordCountsByType: recordCountsByType,
|
|
129
|
-
start: metadata.start,
|
|
130
|
-
end: metadata.end,
|
|
131
|
-
indexInView: metadata.index_in_view,
|
|
132
|
-
rawBytesCount: encoderResult.rawBytesCount
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
var payload = buildReplayPayload(
|
|
136
|
-
encoderResult.output,
|
|
137
|
-
metadata,
|
|
138
|
-
encoderResult.rawBytesCount
|
|
139
|
-
)
|
|
140
195
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
196
|
+
function reportDroppedRecord(reason, estimatedBytesCount) {
|
|
197
|
+
if (reportedDropReasons[reason]) {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
reportedDropReasons[reason] = true
|
|
201
|
+
addTelemetryDebug('Session Replay record discarded.', {
|
|
202
|
+
reason: reason,
|
|
203
|
+
estimated_bytes_count: estimatedBytesCount
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function clearReplayResetNotificationTimeout() {
|
|
208
|
+
if (replayResetNotificationTimeoutId !== undefined) {
|
|
209
|
+
clearTimeout(replayResetNotificationTimeoutId)
|
|
210
|
+
replayResetNotificationTimeoutId = undefined
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getPendingRawBytesCount() {
|
|
215
|
+
return encoder.getPendingRawBytesCount
|
|
216
|
+
? encoder.getPendingRawBytesCount()
|
|
217
|
+
: 0
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function scheduleReplayResetNotification() {
|
|
221
|
+
if (
|
|
222
|
+
!replayResetNeeded ||
|
|
223
|
+
replayResetNotificationSent ||
|
|
224
|
+
replayResetNotificationTimeoutId !== undefined ||
|
|
225
|
+
!options.onReplayResetNeeded ||
|
|
226
|
+
state.$rStatus === SegmentCollectionStatus.Stopped ||
|
|
227
|
+
getPendingRawBytesCount() > 0
|
|
228
|
+
) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
replayResetNotificationTimeoutId = setTimeout(function () {
|
|
233
|
+
replayResetNotificationTimeoutId = undefined
|
|
234
|
+
if (
|
|
235
|
+
!replayResetNeeded ||
|
|
236
|
+
replayResetNotificationSent ||
|
|
237
|
+
state.$rStatus === SegmentCollectionStatus.Stopped ||
|
|
238
|
+
getPendingRawBytesCount() > 0
|
|
239
|
+
) {
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
replayResetNotificationSent = true
|
|
243
|
+
options.onReplayResetNeeded(replayResetReason)
|
|
244
|
+
}, 0)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function markReplayResetNeeded(reason, shouldNotifyAgain) {
|
|
248
|
+
if (!replayResetNeeded || shouldNotifyAgain) {
|
|
249
|
+
replayResetReason = reason
|
|
250
|
+
replayResetNotificationSent = false
|
|
251
|
+
if (shouldNotifyAgain) {
|
|
252
|
+
clearReplayResetNotificationTimeout()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
replayResetNeeded = true
|
|
256
|
+
scheduleReplayResetNotification()
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function clearReplayResetNeeded() {
|
|
260
|
+
replayResetNeeded = false
|
|
261
|
+
replayResetReason = undefined
|
|
262
|
+
replayResetNotificationSent = false
|
|
263
|
+
clearReplayResetNotificationTimeout()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function unsubscribeLifecycle() {
|
|
267
|
+
if (lifecycleSubscriptionsStopped) {
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
lifecycleSubscriptionsStopped = true
|
|
271
|
+
unsubscribeViewCreated()
|
|
272
|
+
unsubscribePageExited()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function exhaustReplayRecovery(reason) {
|
|
276
|
+
if (replayRecoveryExhausted) {
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
replayRecoveryExhausted = true
|
|
280
|
+
clearReplayResetNeeded()
|
|
281
|
+
clearCanvasFlushTimeout()
|
|
282
|
+
lockedBufferGeneration += 1
|
|
283
|
+
lockedSegments = []
|
|
284
|
+
baselineGenerationStates = {}
|
|
285
|
+
transportGenerationStates = {}
|
|
286
|
+
baselineGenerationInFlightCounts = {}
|
|
287
|
+
pendingSegmentResultsByGeneration = {}
|
|
288
|
+
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
289
|
+
// A dependent segment can already exist when the asynchronous failure
|
|
290
|
+
// of the third replacement baseline arrives. Finalize-discard its
|
|
291
|
+
// shared deflate stream before stopping, otherwise a later explicit
|
|
292
|
+
// recorder restart can prepend these abandoned bytes to the new
|
|
293
|
+
// baseline.
|
|
294
|
+
discardCurrentSegment('recovery_exhausted')
|
|
295
|
+
}
|
|
296
|
+
state = {
|
|
297
|
+
$rStatus: SegmentCollectionStatus.Stopped,
|
|
298
|
+
$rLocked: false
|
|
299
|
+
}
|
|
300
|
+
unsubscribeLifecycle()
|
|
301
|
+
if (options.onReplayResetExhausted) {
|
|
302
|
+
options.onReplayResetExhausted(reason)
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function failBaselineGeneration(
|
|
307
|
+
baselineGeneration,
|
|
308
|
+
reason,
|
|
309
|
+
isFullSnapshotFailure
|
|
310
|
+
) {
|
|
311
|
+
if (baselineGeneration > 0) {
|
|
312
|
+
baselineGenerationStates[baselineGeneration] = 'invalid'
|
|
313
|
+
delete pendingSegmentResultsByGeneration[baselineGeneration]
|
|
314
|
+
}
|
|
315
|
+
if (baselineGeneration !== activeBaselineGeneration) {
|
|
316
|
+
tryCleanupBaselineGeneration(baselineGeneration)
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (isFullSnapshotFailure) {
|
|
321
|
+
consecutiveFullSnapshotFailures += 1
|
|
322
|
+
if (
|
|
323
|
+
consecutiveFullSnapshotFailures >=
|
|
324
|
+
MAX_CONSECUTIVE_FULL_SNAPSHOT_FAILURES
|
|
325
|
+
) {
|
|
326
|
+
exhaustReplayRecovery(reason)
|
|
327
|
+
return
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
markReplayResetNeeded(reason, true)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function retainBaselineGeneration(baselineGeneration) {
|
|
334
|
+
if (baselineGeneration <= 0) {
|
|
335
|
+
return
|
|
336
|
+
}
|
|
337
|
+
baselineGenerationInFlightCounts[baselineGeneration] =
|
|
338
|
+
(baselineGenerationInFlightCounts[baselineGeneration] || 0) + 1
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function releaseBaselineGeneration(baselineGeneration) {
|
|
342
|
+
if (
|
|
343
|
+
baselineGeneration <= 0 ||
|
|
344
|
+
!baselineGenerationInFlightCounts[baselineGeneration]
|
|
345
|
+
) {
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
baselineGenerationInFlightCounts[baselineGeneration] -= 1
|
|
349
|
+
if (!baselineGenerationInFlightCounts[baselineGeneration]) {
|
|
350
|
+
delete baselineGenerationInFlightCounts[baselineGeneration]
|
|
351
|
+
}
|
|
352
|
+
tryCleanupBaselineGeneration(baselineGeneration)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function tryCleanupBaselineGeneration(baselineGeneration) {
|
|
356
|
+
if (
|
|
357
|
+
baselineGeneration <= 0 ||
|
|
358
|
+
baselineGeneration === activeBaselineGeneration ||
|
|
359
|
+
baselineGenerationInFlightCounts[baselineGeneration] ||
|
|
360
|
+
pendingSegmentResultsByGeneration[baselineGeneration]
|
|
361
|
+
) {
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
delete baselineGenerationStates[baselineGeneration]
|
|
365
|
+
delete transportGenerationStates[baselineGeneration]
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function getTransportGenerationState(baselineGeneration) {
|
|
369
|
+
if (!transportGenerationStates[baselineGeneration]) {
|
|
370
|
+
transportGenerationStates[baselineGeneration] = { $rValid: true }
|
|
371
|
+
}
|
|
372
|
+
return transportGenerationStates[baselineGeneration]
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function clearCanvasFlushTimeout() {
|
|
376
|
+
if (canvasFlushTimeoutId !== undefined) {
|
|
377
|
+
clearTimeout(canvasFlushTimeoutId)
|
|
378
|
+
canvasFlushTimeoutId = undefined
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function upgradeSegmentTransportsForPageExit(flushReason) {
|
|
383
|
+
if (!isPageExitReason(flushReason)) {
|
|
384
|
+
return
|
|
385
|
+
}
|
|
386
|
+
if (flushReason === PageExitReason.UNLOADING) {
|
|
387
|
+
unloadingTransportLatched = true
|
|
388
|
+
if (unloadingDeliveryBytesRemaining === undefined) {
|
|
389
|
+
unloadingDeliveryBytesRemaining = SEGMENT_BYTES_LIMIT
|
|
390
|
+
}
|
|
391
|
+
drainRetryPayloadsForUnload()
|
|
392
|
+
}
|
|
393
|
+
inFlightSegmentFlushes.forEach(function (transport) {
|
|
394
|
+
transport.$rExit = true
|
|
395
|
+
})
|
|
396
|
+
// A dependent segment can finish encoding before its Full Snapshot and is
|
|
397
|
+
// then removed from inFlightSegmentFlushes while waiting for the baseline
|
|
398
|
+
// generation to be confirmed. Preserve the page-exit transport intent on
|
|
399
|
+
// those completed results as well. UNLOADING still uses the shared latch
|
|
400
|
+
// and aggregate delivery budget in sendSegment().
|
|
401
|
+
Object.keys(pendingSegmentResultsByGeneration).forEach(function (
|
|
402
|
+
baselineGeneration
|
|
403
|
+
) {
|
|
404
|
+
pendingSegmentResultsByGeneration[baselineGeneration].forEach(function (
|
|
405
|
+
segmentResult
|
|
406
|
+
) {
|
|
407
|
+
segmentResult.$rExit = true
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function flushPendingSegmentEncodingsSync() {
|
|
413
|
+
if (encoder.flushPendingActionsSync) {
|
|
414
|
+
encoder.flushPendingActionsSync(SEGMENT_BYTES_LIMIT)
|
|
415
|
+
return true
|
|
416
|
+
}
|
|
417
|
+
return false
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function drainRetryPayloadsForUnload() {
|
|
421
|
+
if (unloadingRetryPayloadsDrained) {
|
|
422
|
+
return
|
|
423
|
+
}
|
|
424
|
+
unloadingRetryPayloadsDrained = true
|
|
425
|
+
if (typeof httpRequest.$rDrainOnExit !== 'function') {
|
|
426
|
+
return
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
var deliveryResult = httpRequest.$rDrainOnExit(
|
|
430
|
+
unloadingDeliveryBytesRemaining
|
|
431
|
+
)
|
|
432
|
+
if (
|
|
433
|
+
deliveryResult &&
|
|
434
|
+
typeof deliveryResult.$rBytesCount === 'number' &&
|
|
435
|
+
isFinite(deliveryResult.$rBytesCount) &&
|
|
436
|
+
deliveryResult.$rBytesCount >= 0
|
|
437
|
+
) {
|
|
438
|
+
unloadingDeliveryBytesRemaining = Math.max(
|
|
439
|
+
unloadingDeliveryBytesRemaining - deliveryResult.$rBytesCount,
|
|
440
|
+
0
|
|
441
|
+
)
|
|
442
|
+
if (deliveryResult.$rAllPayloadsSent === false) {
|
|
443
|
+
// Replay segments are ordered. If an older queued payload does not fit,
|
|
444
|
+
// no current tail may overtake it.
|
|
445
|
+
unloadingDeliveryBudgetExhausted = true
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function flushPendingSegmentEncodingsForUnload(flushReason) {
|
|
451
|
+
return (
|
|
452
|
+
flushReason === PageExitReason.UNLOADING &&
|
|
453
|
+
flushPendingSegmentEncodingsSync()
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function removeInFlightSegmentFlush(transport) {
|
|
458
|
+
inFlightSegmentFlushes.delete(transport)
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function handlePermanentTransportDrop(segmentResult, reason) {
|
|
462
|
+
// Invalidate the transport chain even after the recorder itself stopped;
|
|
463
|
+
// older queued dependents must never be promoted past the missing segment.
|
|
464
|
+
segmentResult.$rTransportGeneration.$rValid = false
|
|
465
|
+
if (
|
|
466
|
+
state.$rStatus === SegmentCollectionStatus.Stopped ||
|
|
467
|
+
replayRecoveryExhausted
|
|
468
|
+
) {
|
|
469
|
+
return
|
|
470
|
+
}
|
|
471
|
+
var dropReason = 'transport_' + reason
|
|
472
|
+
reportDroppedRecord(dropReason, 0)
|
|
473
|
+
// Once a segment is permanently rejected, every later incremental in its
|
|
474
|
+
// generation may depend on replay state the player will never receive.
|
|
475
|
+
// Retire the generation and gate admission until a replacement Full
|
|
476
|
+
// Snapshot establishes a new chain. A transport failure is not evidence
|
|
477
|
+
// that Full Snapshot serialization itself is permanently broken.
|
|
478
|
+
failBaselineGeneration(segmentResult.$rGeneration, dropReason, false)
|
|
479
|
+
scheduleReplayResetNotification()
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function sendSegment(segmentResult) {
|
|
483
|
+
const metadata = segmentResult.$rMetadata
|
|
484
|
+
const encoderResult = segmentResult.$rEncoder
|
|
485
|
+
if (
|
|
486
|
+
__BUILD_ENV__REPLAY_DEBUG_ENABLED__ &&
|
|
487
|
+
options.onSegmentFlushed
|
|
488
|
+
) {
|
|
489
|
+
options.onSegmentFlushed({
|
|
490
|
+
creationReason: metadata.creation_reason,
|
|
491
|
+
flushReason: segmentResult.$rReason,
|
|
492
|
+
recordsCount: metadata.records_count,
|
|
493
|
+
recordCountsByType: segmentResult.$rCounts,
|
|
494
|
+
start: metadata.start,
|
|
495
|
+
end: metadata.end,
|
|
496
|
+
indexInView: metadata.index_in_view,
|
|
497
|
+
rawBytesCount: encoderResult.rawBytesCount
|
|
498
|
+
})
|
|
499
|
+
}
|
|
500
|
+
var shouldUseExitTransport =
|
|
501
|
+
!segmentResult.$rRegular &&
|
|
502
|
+
(segmentResult.$rExit ||
|
|
503
|
+
isPageExitReason(segmentResult.$rReason) ||
|
|
504
|
+
unloadingTransportLatched)
|
|
505
|
+
var estimatedDeliveryBytesCount =
|
|
506
|
+
encoderResult.outputBytesCount +
|
|
507
|
+
SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD
|
|
508
|
+
if (shouldUseExitTransport && unloadingTransportLatched) {
|
|
509
|
+
if (
|
|
510
|
+
unloadingDeliveryBudgetExhausted ||
|
|
511
|
+
estimatedDeliveryBytesCount > unloadingDeliveryBytesRemaining
|
|
512
|
+
) {
|
|
513
|
+
unloadingDeliveryBudgetExhausted = true
|
|
514
|
+
reportDroppedRecord(
|
|
515
|
+
'page_exit_delivery_budget',
|
|
516
|
+
estimatedDeliveryBytesCount
|
|
517
|
+
)
|
|
518
|
+
return
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
var payload = buildReplayPayload(
|
|
523
|
+
encoderResult.output,
|
|
524
|
+
metadata,
|
|
525
|
+
encoderResult.rawBytesCount
|
|
526
|
+
)
|
|
527
|
+
payload.$rExitBytesCount = estimatedDeliveryBytesCount
|
|
528
|
+
payload.$rEnforceOrder = true
|
|
529
|
+
payload.$rIsValid = function () {
|
|
530
|
+
return segmentResult.$rTransportGeneration.$rValid
|
|
531
|
+
}
|
|
532
|
+
payload.$rOnPermanentDrop = function (reason) {
|
|
533
|
+
handlePermanentTransportDrop(segmentResult, reason)
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (shouldUseExitTransport) {
|
|
537
|
+
var exitDeliveryResult = httpRequest.sendOnExit(
|
|
538
|
+
payload,
|
|
539
|
+
unloadingTransportLatched
|
|
540
|
+
? unloadingDeliveryBytesRemaining
|
|
541
|
+
: undefined
|
|
542
|
+
)
|
|
543
|
+
if (unloadingTransportLatched) {
|
|
544
|
+
if (
|
|
545
|
+
exitDeliveryResult &&
|
|
546
|
+
typeof exitDeliveryResult.$rBytesCount === 'number' &&
|
|
547
|
+
isFinite(exitDeliveryResult.$rBytesCount) &&
|
|
548
|
+
exitDeliveryResult.$rBytesCount >= 0
|
|
549
|
+
) {
|
|
550
|
+
unloadingDeliveryBytesRemaining = Math.max(
|
|
551
|
+
unloadingDeliveryBytesRemaining -
|
|
552
|
+
exitDeliveryResult.$rBytesCount,
|
|
553
|
+
0
|
|
554
|
+
)
|
|
555
|
+
if (!exitDeliveryResult.$rCurrentPayloadSent) {
|
|
556
|
+
unloadingDeliveryBudgetExhausted = true
|
|
557
|
+
reportDroppedRecord(
|
|
558
|
+
'page_exit_delivery_budget',
|
|
559
|
+
estimatedDeliveryBytesCount
|
|
560
|
+
)
|
|
145
561
|
}
|
|
146
|
-
}
|
|
562
|
+
} else {
|
|
563
|
+
// Preserve compatibility with injected transports that predate the
|
|
564
|
+
// aggregate-budget result contract.
|
|
565
|
+
unloadingDeliveryBytesRemaining -= estimatedDeliveryBytesCount
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
} else {
|
|
569
|
+
httpRequest.send(payload)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function retainLockedSegment(segmentResult) {
|
|
574
|
+
// A hidden-page beacon intent is only relevant while the page is hidden.
|
|
575
|
+
// If an error-session buffer is later unlocked, drain it through the
|
|
576
|
+
// regular transport instead of retaining a stale sendOnExit decision.
|
|
577
|
+
segmentResult.$rExit = false
|
|
578
|
+
segmentResult.$rRegular = true
|
|
579
|
+
if (replayResetNeeded) {
|
|
580
|
+
// A valid replacement snapshot clears the reset before delivery.
|
|
581
|
+
return
|
|
582
|
+
}
|
|
583
|
+
lockedSegments.push(segmentResult)
|
|
584
|
+
|
|
585
|
+
var latestFullSnapshotIndex = -1
|
|
586
|
+
for (var index = lockedSegments.length - 1; index >= 0; index -= 1) {
|
|
587
|
+
if (lockedSegments[index].$rMetadata.has_full_snapshot) {
|
|
588
|
+
latestFullSnapshotIndex = index
|
|
589
|
+
break
|
|
147
590
|
}
|
|
148
|
-
clearTimeout(state.expirationTimeoutId)
|
|
149
591
|
}
|
|
150
592
|
|
|
593
|
+
if (latestFullSnapshotIndex > 0) {
|
|
594
|
+
lockedSegments.splice(0, latestFullSnapshotIndex)
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (lockedSegments.length > LOCKED_SEGMENTS_LIMIT) {
|
|
598
|
+
// Incremental segments form a dependency chain. Keeping the anchor while
|
|
599
|
+
// deleting a middle segment can leave later records referencing nodes the
|
|
600
|
+
// player never received. Retire the whole lock generation and admit no
|
|
601
|
+
// more incrementals until a replacement full snapshot starts a new chain.
|
|
602
|
+
lockedBufferGeneration += 1
|
|
603
|
+
lockedSegments = []
|
|
604
|
+
markReplayResetNeeded('locked_buffer_capacity')
|
|
605
|
+
// Records already admitted to the current segment still belong to the
|
|
606
|
+
// overflowing lock epoch. Finalize that segment now so its immutable
|
|
607
|
+
// epoch can reject the result, and force the replacement Full Snapshot
|
|
608
|
+
// to start a clean segment.
|
|
609
|
+
flushSegment('locked_buffer_capacity')
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function drainLockedSegments() {
|
|
614
|
+
const segmentsToSend = lockedSegments
|
|
615
|
+
lockedSegments = []
|
|
616
|
+
if (
|
|
617
|
+
segmentsToSend.length > 0 &&
|
|
618
|
+
!segmentsToSend.some(function (segmentResult) {
|
|
619
|
+
return segmentResult.$rMetadata.has_full_snapshot
|
|
620
|
+
})
|
|
621
|
+
) {
|
|
622
|
+
markReplayResetNeeded('locked_buffer_missing_full_snapshot')
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
segmentsToSend.forEach(function (segmentResult) {
|
|
626
|
+
segmentResult.$rExit = false
|
|
627
|
+
segmentResult.$rRegular = true
|
|
628
|
+
sendSegment(segmentResult)
|
|
629
|
+
})
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function deliverSegmentResult(segmentResult) {
|
|
633
|
+
if (!segmentResult.$rLocked) {
|
|
634
|
+
sendSegment(segmentResult)
|
|
635
|
+
return
|
|
636
|
+
}
|
|
637
|
+
if (
|
|
638
|
+
segmentResult.$rLockGeneration !== lockedBufferGeneration ||
|
|
639
|
+
segmentResult.$rReason === 'buffer_checkout' ||
|
|
640
|
+
segmentResult.$rReason === 'stop' ||
|
|
641
|
+
segmentResult.$rReason === PageExitReason.UNLOADING
|
|
642
|
+
) {
|
|
643
|
+
return
|
|
644
|
+
}
|
|
645
|
+
if (state.$rLocked) {
|
|
646
|
+
retainLockedSegment(segmentResult)
|
|
647
|
+
} else {
|
|
648
|
+
segmentResult.$rExit = false
|
|
649
|
+
segmentResult.$rRegular = true
|
|
650
|
+
sendSegment(segmentResult)
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function retainPendingSegmentResult(baselineGeneration, segmentResult) {
|
|
655
|
+
if (!pendingSegmentResultsByGeneration[baselineGeneration]) {
|
|
656
|
+
pendingSegmentResultsByGeneration[baselineGeneration] = []
|
|
657
|
+
}
|
|
658
|
+
pendingSegmentResultsByGeneration[baselineGeneration].push(segmentResult)
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function confirmBaselineGeneration(baselineGeneration, segmentResult) {
|
|
662
|
+
if (
|
|
663
|
+
replayRecoveryExhausted ||
|
|
664
|
+
baselineGenerationStates[baselineGeneration] === 'invalid'
|
|
665
|
+
) {
|
|
666
|
+
return
|
|
667
|
+
}
|
|
668
|
+
baselineGenerationStates[baselineGeneration] = 'confirmed'
|
|
669
|
+
if (
|
|
670
|
+
baselineGeneration === activeBaselineGeneration &&
|
|
671
|
+
(!replayResetNeeded ||
|
|
672
|
+
!segmentResult.$rLocked ||
|
|
673
|
+
segmentResult.$rLockGeneration === lockedBufferGeneration)
|
|
674
|
+
) {
|
|
675
|
+
consecutiveFullSnapshotFailures = 0
|
|
676
|
+
clearReplayResetNeeded()
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
deliverSegmentResult(segmentResult)
|
|
680
|
+
var pendingSegmentResults =
|
|
681
|
+
pendingSegmentResultsByGeneration[baselineGeneration] || []
|
|
682
|
+
delete pendingSegmentResultsByGeneration[baselineGeneration]
|
|
683
|
+
pendingSegmentResults.sort(function (first, second) {
|
|
684
|
+
return first.$rSequence - second.$rSequence
|
|
685
|
+
})
|
|
686
|
+
pendingSegmentResults.forEach(deliverSegmentResult)
|
|
687
|
+
tryCleanupBaselineGeneration(baselineGeneration)
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function handleSuccessfulSegment(baselineGeneration, segmentResult) {
|
|
691
|
+
if (segmentResult.$rMetadata.has_full_snapshot) {
|
|
692
|
+
confirmBaselineGeneration(baselineGeneration, segmentResult)
|
|
693
|
+
return
|
|
694
|
+
}
|
|
695
|
+
if (baselineGeneration === 0) {
|
|
696
|
+
deliverSegmentResult(segmentResult)
|
|
697
|
+
return
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
var baselineState = baselineGenerationStates[baselineGeneration]
|
|
701
|
+
if (baselineState === 'confirmed') {
|
|
702
|
+
deliverSegmentResult(segmentResult)
|
|
703
|
+
} else if (baselineState === 'pending') {
|
|
704
|
+
retainPendingSegmentResult(baselineGeneration, segmentResult)
|
|
705
|
+
} else if (
|
|
706
|
+
baselineGeneration === activeBaselineGeneration &&
|
|
707
|
+
!replayRecoveryExhausted
|
|
708
|
+
) {
|
|
709
|
+
failBaselineGeneration(
|
|
710
|
+
baselineGeneration,
|
|
711
|
+
'missing_full_snapshot',
|
|
712
|
+
false
|
|
713
|
+
)
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function resetState(flushReason) {
|
|
151
718
|
if (flushReason !== 'stop') {
|
|
152
719
|
state = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
720
|
+
$rStatus: SegmentCollectionStatus.WaitingForInitialRecord,
|
|
721
|
+
$rNextReason: flushReason,
|
|
722
|
+
$rLocked: state.$rLocked,
|
|
723
|
+
$rGeneration: activeBaselineGeneration
|
|
156
724
|
}
|
|
157
725
|
} else {
|
|
158
726
|
state = {
|
|
159
|
-
|
|
160
|
-
|
|
727
|
+
$rStatus: SegmentCollectionStatus.Stopped,
|
|
728
|
+
$rLocked: false
|
|
161
729
|
}
|
|
162
730
|
}
|
|
163
731
|
}
|
|
164
732
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
733
|
+
function handleFlushedSegment(
|
|
734
|
+
flushReason,
|
|
735
|
+
wasLocked,
|
|
736
|
+
lockedGeneration,
|
|
737
|
+
baselineGeneration,
|
|
738
|
+
metadata,
|
|
739
|
+
encoderResult,
|
|
740
|
+
recordCountsByType,
|
|
741
|
+
transport
|
|
742
|
+
) {
|
|
743
|
+
if (replayRecoveryExhausted) {
|
|
744
|
+
return
|
|
745
|
+
}
|
|
746
|
+
if (encoderResult.error) {
|
|
747
|
+
reportDroppedRecord('encoder_error', 0)
|
|
748
|
+
failBaselineGeneration(
|
|
749
|
+
baselineGeneration,
|
|
750
|
+
'encoder_error',
|
|
751
|
+
metadata.has_full_snapshot
|
|
752
|
+
)
|
|
753
|
+
scheduleReplayResetNotification()
|
|
754
|
+
return
|
|
755
|
+
}
|
|
756
|
+
// SEGMENT_BYTES_LIMIT is a rolling target and a beacon budget, not a hard
|
|
757
|
+
// limit for regular fetch requests. The asynchronous deflate result can
|
|
758
|
+
// legitimately overshoot its estimate. Discarding that finalized segment
|
|
759
|
+
// would invalidate the replay chain and can force an impossible
|
|
760
|
+
// replacement snapshot on large pages. sendSegment() applies the bounded
|
|
761
|
+
// page-exit delivery budget separately.
|
|
762
|
+
const segmentResult = {
|
|
763
|
+
$rMetadata: metadata,
|
|
764
|
+
$rEncoder: encoderResult,
|
|
765
|
+
$rReason: flushReason,
|
|
766
|
+
$rExit: transport.$rExit,
|
|
767
|
+
$rLocked: wasLocked,
|
|
768
|
+
$rLockGeneration: lockedGeneration,
|
|
769
|
+
$rGeneration: baselineGeneration,
|
|
770
|
+
$rTransportGeneration: getTransportGenerationState(
|
|
771
|
+
baselineGeneration
|
|
772
|
+
),
|
|
773
|
+
$rSequence: transport.$rSequence
|
|
774
|
+
}
|
|
775
|
+
if (__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
|
|
776
|
+
segmentResult.$rCounts = recordCountsByType
|
|
777
|
+
}
|
|
778
|
+
handleSuccessfulSegment(baselineGeneration, segmentResult)
|
|
779
|
+
scheduleReplayResetNotification()
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function flushSegment(flushReason, callback, isStopping) {
|
|
783
|
+
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
784
|
+
if (callback) {
|
|
785
|
+
callback()
|
|
786
|
+
}
|
|
787
|
+
return
|
|
788
|
+
}
|
|
789
|
+
if (
|
|
790
|
+
state.$rStatus === SegmentCollectionStatus.SegmentPending &&
|
|
791
|
+
state.$rMandatoryRecoveryHold
|
|
792
|
+
) {
|
|
793
|
+
if (isStopping) {
|
|
794
|
+
mandatoryRecoveryPending = false
|
|
795
|
+
discardCurrentSegment('mandatory_recovery_incomplete')
|
|
796
|
+
// discardCurrentSegment() normally returns to Waiting so a recovery
|
|
797
|
+
// baseline can create the next stream. A terminal stop must override
|
|
798
|
+
// that reusable state even though the discard finish is asynchronous.
|
|
799
|
+
resetState('stop')
|
|
800
|
+
}
|
|
801
|
+
if (callback) {
|
|
802
|
+
callback()
|
|
803
|
+
}
|
|
804
|
+
return
|
|
805
|
+
}
|
|
806
|
+
if (flushReason !== 'canvas_snapshot') {
|
|
807
|
+
clearCanvasFlushTimeout()
|
|
808
|
+
}
|
|
809
|
+
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
810
|
+
const segmentState = state
|
|
811
|
+
const wasLocked = segmentState.$rLocked
|
|
812
|
+
const lockedGeneration = segmentState.$rLockGeneration
|
|
813
|
+
const baselineGeneration = state.$rGeneration
|
|
814
|
+
const transport = {
|
|
815
|
+
$rExit: isPageExitReason(flushReason),
|
|
816
|
+
$rSequence: ++nextSegmentFlushSequence
|
|
817
|
+
}
|
|
818
|
+
clearTimeout(state.$rExpiration)
|
|
819
|
+
resetState(isStopping ? 'stop' : flushReason)
|
|
820
|
+
if (!segmentState.$rSegment.isEmpty()) {
|
|
821
|
+
inFlightSegmentFlushes.add(transport)
|
|
822
|
+
retainBaselineGeneration(baselineGeneration)
|
|
823
|
+
segmentState.$rSegment.flush(function (
|
|
824
|
+
metadata,
|
|
825
|
+
encoderResult,
|
|
826
|
+
recordCountsByType
|
|
827
|
+
) {
|
|
828
|
+
removeInFlightSegmentFlush(transport)
|
|
829
|
+
try {
|
|
830
|
+
handleFlushedSegment(
|
|
831
|
+
flushReason,
|
|
832
|
+
wasLocked,
|
|
833
|
+
lockedGeneration,
|
|
834
|
+
baselineGeneration,
|
|
835
|
+
metadata,
|
|
836
|
+
encoderResult,
|
|
837
|
+
recordCountsByType,
|
|
838
|
+
transport
|
|
839
|
+
)
|
|
840
|
+
} finally {
|
|
841
|
+
releaseBaselineGeneration(baselineGeneration)
|
|
842
|
+
}
|
|
843
|
+
if (callback) {
|
|
844
|
+
callback()
|
|
845
|
+
}
|
|
846
|
+
})
|
|
168
847
|
return
|
|
169
848
|
}
|
|
849
|
+
}
|
|
850
|
+
resetState(isStopping ? 'stop' : flushReason)
|
|
851
|
+
if (callback) {
|
|
852
|
+
callback()
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function ensureSegment() {
|
|
857
|
+
if (state.$rStatus !== SegmentCollectionStatus.WaitingForInitialRecord) {
|
|
858
|
+
return state.$rStatus === SegmentCollectionStatus.SegmentPending
|
|
859
|
+
}
|
|
860
|
+
var context = getSegmentContext()
|
|
861
|
+
if (!context) {
|
|
862
|
+
return false
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
state = {
|
|
866
|
+
$rStatus: SegmentCollectionStatus.SegmentPending,
|
|
867
|
+
$rSegment: createSegment({
|
|
868
|
+
encoder: encoder,
|
|
869
|
+
context: context,
|
|
870
|
+
creationReason: state.$rNextReason
|
|
871
|
+
}),
|
|
872
|
+
$rLocked: state.$rLocked,
|
|
873
|
+
$rLockGeneration: lockedBufferGeneration,
|
|
874
|
+
$rGeneration: activeBaselineGeneration,
|
|
875
|
+
$rHasSnapshot: false,
|
|
876
|
+
$rMandatoryRecoveryHold: mandatoryRecoveryPending,
|
|
877
|
+
$rExpiration: setTimeout(function () {
|
|
878
|
+
flushSegment('segment_duration_limit')
|
|
879
|
+
}, SEGMENT_DURATION_LIMIT)
|
|
880
|
+
}
|
|
881
|
+
return true
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function discardEmptyCurrentSegment(reason) {
|
|
885
|
+
if (
|
|
886
|
+
state.$rStatus === SegmentCollectionStatus.SegmentPending &&
|
|
887
|
+
state.$rSegment.isEmpty()
|
|
888
|
+
) {
|
|
889
|
+
clearTimeout(state.$rExpiration)
|
|
890
|
+
resetState(reason)
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function discardCurrentSegment(reason) {
|
|
895
|
+
if (state.$rStatus !== SegmentCollectionStatus.SegmentPending) {
|
|
896
|
+
return
|
|
897
|
+
}
|
|
898
|
+
var discardedSegment = state.$rSegment
|
|
899
|
+
var isEmpty = discardedSegment.isEmpty()
|
|
900
|
+
clearTimeout(state.$rExpiration)
|
|
901
|
+
resetState(reason)
|
|
902
|
+
if (!isEmpty) {
|
|
903
|
+
// The deflate encoder is shared by consecutive segments. Merely
|
|
904
|
+
// forgetting this Segment would leave its already-written bytes in the
|
|
905
|
+
// active stream and prepend them to the replacement baseline. Finalize
|
|
906
|
+
// the stream to reset the encoder, but deliberately ignore its result.
|
|
907
|
+
discardedSegment.$rDiscard(function () {
|
|
908
|
+
// A rejected mandatory Full Snapshot may have marked recovery while
|
|
909
|
+
// encoder writes were still pending. Wake the deferred notification
|
|
910
|
+
// after finish drains that backlog, even though this segment result is
|
|
911
|
+
// intentionally not delivered.
|
|
912
|
+
scheduleReplayResetNotification()
|
|
913
|
+
})
|
|
914
|
+
}
|
|
915
|
+
}
|
|
170
916
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
917
|
+
function addRecordToCurrentSegment(
|
|
918
|
+
record,
|
|
919
|
+
serializedRecordData,
|
|
920
|
+
ignoreSegmentBytesLimit
|
|
921
|
+
) {
|
|
922
|
+
const segmentState = state
|
|
923
|
+
const segment = segmentState.$rSegment
|
|
924
|
+
var synchronousEncoderError
|
|
925
|
+
var addResult = segment.addRecord(
|
|
926
|
+
record,
|
|
927
|
+
function (encodedBytesCount, error) {
|
|
928
|
+
if (
|
|
929
|
+
state.$rStatus !== SegmentCollectionStatus.SegmentPending ||
|
|
930
|
+
state.$rSegment !== segment
|
|
931
|
+
) {
|
|
932
|
+
scheduleReplayResetNotification()
|
|
174
933
|
return
|
|
175
934
|
}
|
|
935
|
+
if (error) {
|
|
936
|
+
synchronousEncoderError = error
|
|
937
|
+
var isBaselineTransactionFailure =
|
|
938
|
+
activeBaselineTransaction &&
|
|
939
|
+
activeBaselineTransaction.$rSegment === segment
|
|
940
|
+
clearTimeout(state.$rExpiration)
|
|
941
|
+
reportDroppedRecord('encoder_error', 0)
|
|
942
|
+
resetState('encoder_error')
|
|
943
|
+
failBaselineGeneration(
|
|
944
|
+
segmentState.$rGeneration,
|
|
945
|
+
'encoder_error',
|
|
946
|
+
segmentState.$rHasSnapshot ||
|
|
947
|
+
Boolean(isBaselineTransactionFailure)
|
|
948
|
+
)
|
|
949
|
+
} else if (
|
|
950
|
+
encodedBytesCount > SEGMENT_BYTES_LIMIT &&
|
|
951
|
+
!segmentState.$rMandatoryRecoveryHold
|
|
952
|
+
) {
|
|
953
|
+
if (
|
|
954
|
+
activeBaselineTransaction &&
|
|
955
|
+
activeBaselineTransaction.$rSegment === segment
|
|
956
|
+
) {
|
|
957
|
+
// Meta + Focus + FullSnapshot is one replay baseline. An encoder
|
|
958
|
+
// callback may run synchronously while those records are being
|
|
959
|
+
// added; flushing after Meta would expose an incomplete baseline
|
|
960
|
+
// and leave the following records without a current segment.
|
|
961
|
+
activeBaselineTransaction.$rExceededSegmentBytesLimit = true
|
|
962
|
+
} else {
|
|
963
|
+
flushSegment('segment_bytes_limit')
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
scheduleReplayResetNotification()
|
|
967
|
+
},
|
|
968
|
+
ignoreSegmentBytesLimit ? undefined : SEGMENT_BYTES_LIMIT,
|
|
969
|
+
pendingRawBytesLimit,
|
|
970
|
+
serializedRecordData
|
|
971
|
+
)
|
|
972
|
+
if (synchronousEncoderError) {
|
|
973
|
+
return {
|
|
974
|
+
status: 'encoder_error',
|
|
975
|
+
error: synchronousEncoderError
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return addResult
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function flushCanvasWithRateLimit() {
|
|
982
|
+
const now = dateNow()
|
|
983
|
+
const timeUntilNextFlush =
|
|
984
|
+
CANVAS_FLUSH_MIN_INTERVAL - (now - lastCanvasFlushAt)
|
|
985
|
+
if (timeUntilNextFlush <= 0) {
|
|
986
|
+
lastCanvasFlushAt = now
|
|
987
|
+
flushSegment('canvas_snapshot')
|
|
988
|
+
return
|
|
989
|
+
}
|
|
990
|
+
if (canvasFlushTimeoutId === undefined) {
|
|
991
|
+
canvasFlushTimeoutId = setTimeout(function () {
|
|
992
|
+
canvasFlushTimeoutId = undefined
|
|
993
|
+
lastCanvasFlushAt = dateNow()
|
|
994
|
+
flushSegment('canvas_snapshot')
|
|
995
|
+
}, timeUntilNextFlush)
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
function addRecordWithBaselineGeneration(
|
|
1000
|
+
record,
|
|
1001
|
+
serializedRecordData,
|
|
1002
|
+
ignoreSegmentBytesLimit
|
|
1003
|
+
) {
|
|
1004
|
+
var segmentState = state
|
|
1005
|
+
var previousBaselineGeneration = activeBaselineGeneration
|
|
1006
|
+
var previousSegmentBaselineGeneration = segmentState.$rGeneration
|
|
1007
|
+
var previousHasFullSnapshot = segmentState.$rHasSnapshot
|
|
1008
|
+
var fullSnapshotGeneration
|
|
1009
|
+
|
|
1010
|
+
if (record.type === RecordType.FullSnapshot) {
|
|
1011
|
+
var previousActiveBaselineGeneration = activeBaselineGeneration
|
|
1012
|
+
fullSnapshotGeneration = ++nextBaselineGeneration
|
|
1013
|
+
activeBaselineGeneration = fullSnapshotGeneration
|
|
1014
|
+
baselineGenerationStates[fullSnapshotGeneration] = 'pending'
|
|
1015
|
+
segmentState.$rGeneration = fullSnapshotGeneration
|
|
1016
|
+
segmentState.$rHasSnapshot = true
|
|
1017
|
+
}
|
|
176
1018
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1019
|
+
var result = addRecordToCurrentSegment(
|
|
1020
|
+
record,
|
|
1021
|
+
serializedRecordData,
|
|
1022
|
+
ignoreSegmentBytesLimit
|
|
1023
|
+
)
|
|
1024
|
+
if (
|
|
1025
|
+
result.status === 'segment_full' &&
|
|
1026
|
+
fullSnapshotGeneration !== undefined
|
|
1027
|
+
) {
|
|
1028
|
+
delete baselineGenerationStates[fullSnapshotGeneration]
|
|
1029
|
+
activeBaselineGeneration = previousBaselineGeneration
|
|
1030
|
+
segmentState.$rGeneration = previousSegmentBaselineGeneration
|
|
1031
|
+
segmentState.$rHasSnapshot = previousHasFullSnapshot
|
|
1032
|
+
fullSnapshotGeneration = undefined
|
|
1033
|
+
} else if (fullSnapshotGeneration !== undefined) {
|
|
1034
|
+
tryCleanupBaselineGeneration(previousActiveBaselineGeneration)
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
return {
|
|
1038
|
+
$rResult: result,
|
|
1039
|
+
$rGeneration: segmentState.$rGeneration
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function rejectRecordAdmission(wasBackpressured) {
|
|
1044
|
+
lastAddRecordWasBackpressured = Boolean(wasBackpressured)
|
|
1045
|
+
return false
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
function startFreshBaselineTransactionSegment() {
|
|
1049
|
+
if (
|
|
1050
|
+
state.$rStatus === SegmentCollectionStatus.SegmentPending &&
|
|
1051
|
+
!state.$rSegment.isEmpty()
|
|
1052
|
+
) {
|
|
1053
|
+
if (state.$rMandatoryRecoveryHold) {
|
|
1054
|
+
discardCurrentSegment('mandatory_recovery_replaced')
|
|
1055
|
+
} else {
|
|
1056
|
+
flushSegment('full_snapshot')
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return ensureSegment()
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function tryAddBaselineTransaction(records, ignoreSegmentBytesLimit) {
|
|
1063
|
+
var transaction = {
|
|
1064
|
+
$rSegment: state.$rSegment,
|
|
1065
|
+
$rExceededSegmentBytesLimit: false
|
|
1066
|
+
}
|
|
1067
|
+
activeBaselineTransaction = transaction
|
|
1068
|
+
var attempt
|
|
1069
|
+
try {
|
|
1070
|
+
for (var index = 0; index < records.length; index += 1) {
|
|
1071
|
+
var record = records[index]
|
|
1072
|
+
var addResult = addRecordWithBaselineGeneration(
|
|
1073
|
+
record,
|
|
1074
|
+
backpressuredSerializedRecordData.get(record),
|
|
1075
|
+
ignoreSegmentBytesLimit
|
|
1076
|
+
)
|
|
1077
|
+
if (addResult.$rResult.status !== 'added') {
|
|
1078
|
+
attempt = {
|
|
1079
|
+
$rAddResult: addResult,
|
|
1080
|
+
$rRecord: record
|
|
1081
|
+
}
|
|
1082
|
+
break
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
if (!attempt) {
|
|
1086
|
+
attempt = {
|
|
1087
|
+
$rAddResult: addResult,
|
|
1088
|
+
$rRecord: records[records.length - 1]
|
|
188
1089
|
}
|
|
189
1090
|
}
|
|
1091
|
+
} finally {
|
|
1092
|
+
activeBaselineTransaction = undefined
|
|
1093
|
+
}
|
|
1094
|
+
attempt.$rExceededSegmentBytesLimit =
|
|
1095
|
+
transaction.$rExceededSegmentBytesLimit
|
|
1096
|
+
return attempt
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
function rejectBaselineTransaction(records, attempt) {
|
|
1100
|
+
var result = attempt.$rAddResult.$rResult
|
|
1101
|
+
var record = attempt.$rRecord
|
|
1102
|
+
records.forEach(function (baselineRecord) {
|
|
1103
|
+
backpressuredSerializedRecordData.delete(baselineRecord)
|
|
1104
|
+
})
|
|
1105
|
+
if (result.status === 'encoder_error') {
|
|
1106
|
+
mandatoryRecoveryPending = false
|
|
1107
|
+
bufferCheckoutPending = false
|
|
1108
|
+
discardCurrentSegment('baseline_transaction_encoder_error')
|
|
1109
|
+
return rejectRecordAdmission()
|
|
1110
|
+
}
|
|
1111
|
+
if (result.status === 'record_too_large') {
|
|
1112
|
+
reportDroppedRecord(
|
|
1113
|
+
record.type === RecordType.FullSnapshot
|
|
1114
|
+
? 'full_snapshot_too_large'
|
|
1115
|
+
: 'record_too_large',
|
|
1116
|
+
result.estimatedBytesCount
|
|
1117
|
+
)
|
|
1118
|
+
} else {
|
|
1119
|
+
reportDroppedRecord(
|
|
1120
|
+
record.type === RecordType.FullSnapshot
|
|
1121
|
+
? 'full_snapshot_encoder_backpressure'
|
|
1122
|
+
: 'encoder_backpressure',
|
|
1123
|
+
result.estimatedBytesCount
|
|
1124
|
+
)
|
|
1125
|
+
}
|
|
1126
|
+
if (record.type === RecordType.FullSnapshot) {
|
|
1127
|
+
failBaselineGeneration(
|
|
1128
|
+
attempt.$rAddResult.$rGeneration,
|
|
1129
|
+
result.status === 'record_too_large'
|
|
1130
|
+
? 'full_snapshot_too_large'
|
|
1131
|
+
: 'full_snapshot_encoder_backpressure',
|
|
1132
|
+
result.status === 'record_too_large'
|
|
1133
|
+
)
|
|
1134
|
+
}
|
|
1135
|
+
mandatoryRecoveryPending = false
|
|
1136
|
+
bufferCheckoutPending = false
|
|
1137
|
+
discardCurrentSegment('baseline_transaction_rejected')
|
|
1138
|
+
return rejectRecordAdmission(result.status === 'encoder_backpressure')
|
|
1139
|
+
}
|
|
190
1140
|
|
|
191
|
-
|
|
192
|
-
|
|
1141
|
+
function addBaselineRecords(records) {
|
|
1142
|
+
lastAddRecordWasBackpressured = false
|
|
1143
|
+
if (
|
|
1144
|
+
state.$rStatus === SegmentCollectionStatus.Stopped ||
|
|
1145
|
+
!records ||
|
|
1146
|
+
records.length !== 3 ||
|
|
1147
|
+
records[0].type !== RecordType.Meta ||
|
|
1148
|
+
records[1].type !== RecordType.Focus ||
|
|
1149
|
+
records[2].type !== RecordType.FullSnapshot ||
|
|
1150
|
+
!startFreshBaselineTransactionSegment()
|
|
1151
|
+
) {
|
|
1152
|
+
return rejectRecordAdmission()
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
var attempt = tryAddBaselineTransaction(records, false)
|
|
1156
|
+
if (attempt.$rAddResult.$rResult.status === 'segment_full') {
|
|
1157
|
+
if (
|
|
1158
|
+
typeof attempt.$rAddResult.$rResult.serializedRecordData ===
|
|
1159
|
+
'string'
|
|
1160
|
+
) {
|
|
1161
|
+
backpressuredSerializedRecordData.set(
|
|
1162
|
+
attempt.$rRecord,
|
|
1163
|
+
attempt.$rAddResult.$rResult.serializedRecordData
|
|
1164
|
+
)
|
|
1165
|
+
}
|
|
1166
|
+
// Meta and Focus are the prelude of the Full Snapshot, not independent
|
|
1167
|
+
// replay state. Retire this unsent attempt and replay the complete
|
|
1168
|
+
// transaction in a fresh segment. Like a Full Snapshot as the first
|
|
1169
|
+
// physical record, the retry may exceed the estimated segment target by
|
|
1170
|
+
// the small prelude; the finalized payload still goes through the hard
|
|
1171
|
+
// SEGMENT_BYTES_LIMIT delivery check.
|
|
1172
|
+
discardCurrentSegment('baseline_transaction_retry')
|
|
1173
|
+
if (!ensureSegment()) {
|
|
1174
|
+
return rejectRecordAdmission()
|
|
1175
|
+
}
|
|
1176
|
+
attempt = tryAddBaselineTransaction(records, true)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
if (attempt.$rAddResult.$rResult.status !== 'added') {
|
|
1180
|
+
return rejectBaselineTransaction(records, attempt)
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
records.forEach(function (record) {
|
|
1184
|
+
backpressuredSerializedRecordData.delete(record)
|
|
1185
|
+
})
|
|
1186
|
+
if (mandatoryRecoveryPending) {
|
|
1187
|
+
mandatoryRecoveryPending = false
|
|
1188
|
+
bufferCheckoutPending = false
|
|
1189
|
+
state.$rMandatoryRecoveryHold = false
|
|
1190
|
+
flushSegment('mandatory_full_snapshot')
|
|
1191
|
+
} else if (attempt.$rExceededSegmentBytesLimit) {
|
|
1192
|
+
flushSegment('segment_bytes_limit')
|
|
1193
|
+
}
|
|
1194
|
+
return true
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
var segmentCollection = {
|
|
1198
|
+
$rAddBaselineRecords: addBaselineRecords,
|
|
1199
|
+
addRecord: function (record) {
|
|
1200
|
+
lastAddRecordWasBackpressured = false
|
|
1201
|
+
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
1202
|
+
return rejectRecordAdmission()
|
|
1203
|
+
}
|
|
1204
|
+
if (
|
|
1205
|
+
bufferCheckoutPending &&
|
|
1206
|
+
record.type !== RecordType.FullSnapshot &&
|
|
1207
|
+
record.type !== RecordType.Meta &&
|
|
1208
|
+
record.type !== RecordType.Focus
|
|
1209
|
+
) {
|
|
1210
|
+
return rejectRecordAdmission()
|
|
1211
|
+
}
|
|
1212
|
+
if (
|
|
1213
|
+
replayResetNeeded &&
|
|
1214
|
+
record.type !== RecordType.FullSnapshot &&
|
|
1215
|
+
record.type !== RecordType.Meta &&
|
|
1216
|
+
record.type !== RecordType.Focus &&
|
|
1217
|
+
baselineGenerationStates[activeBaselineGeneration] !== 'pending'
|
|
1218
|
+
) {
|
|
1219
|
+
return rejectRecordAdmission()
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
if (!ensureSegment()) {
|
|
1223
|
+
return rejectRecordAdmission()
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
var addResult = addRecordWithBaselineGeneration(
|
|
1227
|
+
record,
|
|
1228
|
+
backpressuredSerializedRecordData.get(record)
|
|
1229
|
+
)
|
|
1230
|
+
var result = addResult.$rResult
|
|
1231
|
+
if (result.status === 'segment_full') {
|
|
1232
|
+
var serializedRecordData = result.serializedRecordData
|
|
1233
|
+
if (state.$rMandatoryRecoveryHold) {
|
|
1234
|
+
discardCurrentSegment('mandatory_recovery_replaced')
|
|
1235
|
+
} else {
|
|
193
1236
|
flushSegment('segment_bytes_limit')
|
|
194
1237
|
}
|
|
195
|
-
|
|
1238
|
+
if (!ensureSegment()) {
|
|
1239
|
+
return rejectRecordAdmission()
|
|
1240
|
+
}
|
|
1241
|
+
addResult = addRecordWithBaselineGeneration(
|
|
1242
|
+
record,
|
|
1243
|
+
serializedRecordData
|
|
1244
|
+
)
|
|
1245
|
+
result = addResult.$rResult
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
if (result.status === 'record_too_large') {
|
|
1249
|
+
backpressuredSerializedRecordData.delete(record)
|
|
1250
|
+
reportDroppedRecord(
|
|
1251
|
+
'record_too_large',
|
|
1252
|
+
result.estimatedBytesCount
|
|
1253
|
+
)
|
|
1254
|
+
discardEmptyCurrentSegment('record_too_large')
|
|
1255
|
+
// Incremental admission fails synchronously, before the recorder
|
|
1256
|
+
// publishes any DOM membership carried by the record. Returning false
|
|
1257
|
+
// lets it cancel that staged membership, so the existing baseline
|
|
1258
|
+
// remains valid and does not need a global reset.
|
|
1259
|
+
if (record.type !== RecordType.IncrementalSnapshot) {
|
|
1260
|
+
failBaselineGeneration(
|
|
1261
|
+
addResult.$rGeneration,
|
|
1262
|
+
record.type === RecordType.FullSnapshot
|
|
1263
|
+
? 'full_snapshot_too_large'
|
|
1264
|
+
: 'record_too_large',
|
|
1265
|
+
record.type === RecordType.FullSnapshot
|
|
1266
|
+
)
|
|
1267
|
+
}
|
|
1268
|
+
if (
|
|
1269
|
+
record.type === RecordType.FullSnapshot &&
|
|
1270
|
+
mandatoryRecoveryPending
|
|
1271
|
+
) {
|
|
1272
|
+
mandatoryRecoveryPending = false
|
|
1273
|
+
bufferCheckoutPending = false
|
|
1274
|
+
discardCurrentSegment('mandatory_recovery_failed')
|
|
1275
|
+
}
|
|
1276
|
+
return rejectRecordAdmission()
|
|
1277
|
+
}
|
|
1278
|
+
if (result.status === 'encoder_backpressure') {
|
|
1279
|
+
if (typeof result.serializedRecordData === 'string') {
|
|
1280
|
+
backpressuredSerializedRecordData.set(
|
|
1281
|
+
record,
|
|
1282
|
+
result.serializedRecordData
|
|
1283
|
+
)
|
|
1284
|
+
}
|
|
1285
|
+
reportDroppedRecord(
|
|
1286
|
+
'encoder_backpressure',
|
|
1287
|
+
result.estimatedBytesCount
|
|
1288
|
+
)
|
|
1289
|
+
if (state.$rSegment.isEmpty()) {
|
|
1290
|
+
discardEmptyCurrentSegment('encoder_backpressure')
|
|
1291
|
+
} else {
|
|
1292
|
+
flushSegment('encoder_backpressure')
|
|
1293
|
+
}
|
|
1294
|
+
// See the synchronous incremental rejection rationale above. Full
|
|
1295
|
+
// snapshots and non-incremental baseline records retain the existing
|
|
1296
|
+
// recovery semantics.
|
|
1297
|
+
if (record.type !== RecordType.IncrementalSnapshot) {
|
|
1298
|
+
failBaselineGeneration(
|
|
1299
|
+
addResult.$rGeneration,
|
|
1300
|
+
record.type === RecordType.FullSnapshot
|
|
1301
|
+
? 'full_snapshot_encoder_backpressure'
|
|
1302
|
+
: 'encoder_backpressure',
|
|
1303
|
+
false
|
|
1304
|
+
)
|
|
1305
|
+
}
|
|
1306
|
+
if (
|
|
1307
|
+
record.type === RecordType.FullSnapshot &&
|
|
1308
|
+
mandatoryRecoveryPending
|
|
1309
|
+
) {
|
|
1310
|
+
mandatoryRecoveryPending = false
|
|
1311
|
+
bufferCheckoutPending = false
|
|
1312
|
+
discardCurrentSegment('mandatory_recovery_failed')
|
|
1313
|
+
}
|
|
1314
|
+
return rejectRecordAdmission(true)
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
backpressuredSerializedRecordData.delete(record)
|
|
1318
|
+
if (result.status === 'encoder_error') {
|
|
1319
|
+
if (
|
|
1320
|
+
record.type === RecordType.FullSnapshot &&
|
|
1321
|
+
mandatoryRecoveryPending
|
|
1322
|
+
) {
|
|
1323
|
+
mandatoryRecoveryPending = false
|
|
1324
|
+
bufferCheckoutPending = false
|
|
1325
|
+
discardCurrentSegment('mandatory_recovery_failed')
|
|
1326
|
+
}
|
|
1327
|
+
return rejectRecordAdmission()
|
|
1328
|
+
}
|
|
1329
|
+
if (
|
|
1330
|
+
record.type === RecordType.FullSnapshot &&
|
|
1331
|
+
mandatoryRecoveryPending
|
|
1332
|
+
) {
|
|
1333
|
+
mandatoryRecoveryPending = false
|
|
1334
|
+
bufferCheckoutPending = false
|
|
1335
|
+
state.$rMandatoryRecoveryHold = false
|
|
1336
|
+
flushSegment('mandatory_full_snapshot')
|
|
1337
|
+
}
|
|
1338
|
+
|
|
196
1339
|
if (
|
|
197
1340
|
options.flushCanvasImmediately &&
|
|
198
1341
|
isCanvasMutationRecord(record) &&
|
|
199
|
-
state
|
|
1342
|
+
state.$rStatus === SegmentCollectionStatus.SegmentPending
|
|
200
1343
|
) {
|
|
201
|
-
|
|
1344
|
+
flushCanvasWithRateLimit()
|
|
202
1345
|
}
|
|
1346
|
+
return true
|
|
1347
|
+
},
|
|
1348
|
+
$rWasLastAddRecordBackpressured: function () {
|
|
1349
|
+
return lastAddRecordWasBackpressured
|
|
203
1350
|
},
|
|
204
1351
|
|
|
205
1352
|
unlockSegment: function () {
|
|
206
|
-
state
|
|
1353
|
+
state.$rLocked = false
|
|
1354
|
+
drainLockedSegments()
|
|
207
1355
|
},
|
|
208
1356
|
flushBufferSegment: function (callback) {
|
|
209
|
-
|
|
1357
|
+
if (bufferCheckoutPending) {
|
|
1358
|
+
return false
|
|
1359
|
+
}
|
|
1360
|
+
bufferCheckoutPending = true
|
|
1361
|
+
lockedBufferGeneration += 1
|
|
1362
|
+
lockedSegments = []
|
|
1363
|
+
var callbackWasInvoked = false
|
|
1364
|
+
flushSegment('buffer_checkout', function () {
|
|
1365
|
+
callbackWasInvoked = true
|
|
1366
|
+
beginMandatoryRecovery()
|
|
1367
|
+
if (callback) {
|
|
1368
|
+
callback()
|
|
1369
|
+
}
|
|
1370
|
+
})
|
|
1371
|
+
// A non-empty segment finishes asynchronously. Enter the hold before
|
|
1372
|
+
// application code can enqueue another record or unlock the error
|
|
1373
|
+
// session, so no post-checkout incrementals can be sent without the
|
|
1374
|
+
// replacement baseline.
|
|
1375
|
+
if (!callbackWasInvoked) {
|
|
1376
|
+
beginMandatoryRecovery()
|
|
1377
|
+
}
|
|
1378
|
+
return true
|
|
210
1379
|
},
|
|
211
1380
|
isLocked: function () {
|
|
212
|
-
return state
|
|
1381
|
+
return state.$rLocked
|
|
1382
|
+
},
|
|
1383
|
+
$rBeginMandatoryRecovery: function () {
|
|
1384
|
+
beginMandatoryRecovery()
|
|
1385
|
+
},
|
|
1386
|
+
$rDiscardMandatoryRecovery: function () {
|
|
1387
|
+
if (!mandatoryRecoveryPending) {
|
|
1388
|
+
return
|
|
1389
|
+
}
|
|
1390
|
+
mandatoryRecoveryPending = false
|
|
1391
|
+
bufferCheckoutPending = false
|
|
1392
|
+
if (
|
|
1393
|
+
state.$rStatus === SegmentCollectionStatus.SegmentPending &&
|
|
1394
|
+
state.$rMandatoryRecoveryHold
|
|
1395
|
+
) {
|
|
1396
|
+
discardCurrentSegment('mandatory_recovery_incomplete')
|
|
1397
|
+
}
|
|
213
1398
|
},
|
|
214
|
-
stop: function () {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
1399
|
+
stop: function (flushReason) {
|
|
1400
|
+
lockedBufferGeneration += 1
|
|
1401
|
+
lockedSegments = []
|
|
1402
|
+
bufferCheckoutPending = false
|
|
1403
|
+
clearCanvasFlushTimeout()
|
|
1404
|
+
clearReplayResetNotificationTimeout()
|
|
1405
|
+
upgradeSegmentTransportsForPageExit(flushReason)
|
|
1406
|
+
var stopEvent = isPageExitReason(flushReason)
|
|
1407
|
+
? { reason: flushReason }
|
|
1408
|
+
: undefined
|
|
1409
|
+
prepareRecordsBeforePageExit(stopEvent)
|
|
1410
|
+
if (flushReason === PageExitReason.UNLOADING) {
|
|
1411
|
+
flushSegment(flushReason || 'stop')
|
|
1412
|
+
if (flushPendingSegmentEncodingsForUnload(flushReason)) {
|
|
1413
|
+
// A synchronous encoder drain can release admission backpressure.
|
|
1414
|
+
// Ask the still-active recorder for one final mutation pass before
|
|
1415
|
+
// terminally closing the second unload-safe segment.
|
|
1416
|
+
prepareRecordsBeforePageExit(stopEvent)
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
flushSegment(flushReason || 'stop', undefined, true)
|
|
1420
|
+
// Normal stop/session renewal must not force a potentially large worker
|
|
1421
|
+
// backlog onto the main thread or apply the unload delivery budget. The
|
|
1422
|
+
// encoder queues a reset after each finish, so a restarted recorder can
|
|
1423
|
+
// append a new generation while these old results complete in order.
|
|
1424
|
+
// Only a real unload needs the bounded synchronous drain.
|
|
1425
|
+
flushPendingSegmentEncodingsForUnload(flushReason)
|
|
1426
|
+
unsubscribeLifecycle()
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
if (__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
|
|
1430
|
+
segmentCollection.getBaselineGenerationStateCountForDebug = function () {
|
|
1431
|
+
return Object.keys(baselineGenerationStates).length
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
return segmentCollection
|
|
1435
|
+
|
|
1436
|
+
function beginMandatoryRecovery() {
|
|
1437
|
+
mandatoryRecoveryPending = true
|
|
1438
|
+
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
1439
|
+
state.$rMandatoryRecoveryHold = true
|
|
1440
|
+
clearTimeout(state.$rExpiration)
|
|
218
1441
|
}
|
|
219
1442
|
}
|
|
220
1443
|
}
|