@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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createCanvasCommandObjectRefRegistry } from './canvasCommandSerializeArgs'
|
|
2
2
|
import { createCanvasMutationRecord } from './canvasMutationRecord'
|
|
3
3
|
|
|
4
4
|
var CANVAS_2D_CAPTURED_METHODS = [
|
|
@@ -9,6 +9,8 @@ var CANVAS_2D_CAPTURED_METHODS = [
|
|
|
9
9
|
'rotate',
|
|
10
10
|
'transform',
|
|
11
11
|
'setTransform',
|
|
12
|
+
'resetTransform',
|
|
13
|
+
'reset',
|
|
12
14
|
'createLinearGradient',
|
|
13
15
|
'createRadialGradient',
|
|
14
16
|
'createPattern',
|
|
@@ -22,6 +24,7 @@ var CANVAS_2D_CAPTURED_METHODS = [
|
|
|
22
24
|
'lineTo',
|
|
23
25
|
'bezierCurveTo',
|
|
24
26
|
'quadraticCurveTo',
|
|
27
|
+
'arcTo',
|
|
25
28
|
'closePath',
|
|
26
29
|
'arc',
|
|
27
30
|
'ellipse',
|
|
@@ -32,6 +35,7 @@ var CANVAS_2D_CAPTURED_METHODS = [
|
|
|
32
35
|
'fillText',
|
|
33
36
|
'strokeText',
|
|
34
37
|
'setLineDash',
|
|
38
|
+
'putImageData',
|
|
35
39
|
'drawImage'
|
|
36
40
|
]
|
|
37
41
|
|
|
@@ -42,22 +46,64 @@ var CANVAS_2D_CAPTURED_PROPERTIES = [
|
|
|
42
46
|
'lineCap',
|
|
43
47
|
'lineJoin',
|
|
44
48
|
'miterLimit',
|
|
49
|
+
'lineDashOffset',
|
|
45
50
|
'font',
|
|
46
51
|
'globalAlpha',
|
|
52
|
+
'globalCompositeOperation',
|
|
53
|
+
'imageSmoothingEnabled',
|
|
54
|
+
'imageSmoothingQuality',
|
|
47
55
|
'shadowColor',
|
|
48
56
|
'shadowBlur',
|
|
49
57
|
'shadowOffsetX',
|
|
50
58
|
'shadowOffsetY',
|
|
51
59
|
'textAlign',
|
|
52
60
|
'textBaseline',
|
|
61
|
+
'direction',
|
|
62
|
+
'fontKerning',
|
|
63
|
+
'fontStretch',
|
|
64
|
+
'fontVariantCaps',
|
|
65
|
+
'letterSpacing',
|
|
66
|
+
'textRendering',
|
|
67
|
+
'wordSpacing',
|
|
53
68
|
'filter'
|
|
54
69
|
]
|
|
55
70
|
|
|
71
|
+
var CANVAS_2D_NON_MUTATING_METHODS = {
|
|
72
|
+
createImageData: true,
|
|
73
|
+
getContextAttributes: true,
|
|
74
|
+
getImageData: true,
|
|
75
|
+
getLineDash: true,
|
|
76
|
+
getTransform: true,
|
|
77
|
+
isContextLost: true,
|
|
78
|
+
isPointInPath: true,
|
|
79
|
+
isPointInStroke: true,
|
|
80
|
+
measureText: true
|
|
81
|
+
}
|
|
82
|
+
var CANVAS_2D_CAPTURED_METHOD_NAMES = {}
|
|
83
|
+
var CANVAS_2D_CAPTURED_PROPERTY_NAMES = {}
|
|
84
|
+
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
85
|
+
CANVAS_2D_CAPTURED_METHOD_NAMES[methodName] = true
|
|
86
|
+
})
|
|
87
|
+
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
88
|
+
CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] = true
|
|
89
|
+
})
|
|
90
|
+
|
|
56
91
|
var UNSUPPORTED_REPLAY_OBJECT_NAMES = {
|
|
57
92
|
CanvasGradient: true,
|
|
58
93
|
CanvasPattern: true,
|
|
59
94
|
Path2D: true
|
|
60
95
|
}
|
|
96
|
+
export var MAX_CANVAS_COMMANDS_PER_BATCH = 1000
|
|
97
|
+
export var MAX_CANVAS_COMMAND_BATCH_BYTES = 128 * 1024
|
|
98
|
+
export var MAX_PENDING_CANVAS_COMMAND_CONTEXTS = 64
|
|
99
|
+
export var MAX_PENDING_CANVAS_COMMAND_BYTES = 512 * 1024
|
|
100
|
+
export var MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS = 1000
|
|
101
|
+
export var MAX_STRONG_CANVAS_CONTEXT_RESTORE_RECORDS = 64
|
|
102
|
+
export var MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS = 256
|
|
103
|
+
var MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS = 16
|
|
104
|
+
|
|
105
|
+
var CANVAS_COMMAND_BASE_APPROX_BYTES = 32
|
|
106
|
+
var CANVAS_COMMAND_SETTER_APPROX_BYTES = 14
|
|
61
107
|
var ORIGINAL_ADD_COLOR_STOP_KEY = '__dd_original_addColorStop__'
|
|
62
108
|
var PATCHED_ADD_COLOR_STOP_KEY = '__dd_patched_addColorStop__'
|
|
63
109
|
|
|
@@ -84,20 +130,7 @@ function getCanvasObjectConstructorName(value) {
|
|
|
84
130
|
return value.constructor.name || 'Object'
|
|
85
131
|
}
|
|
86
132
|
|
|
87
|
-
function
|
|
88
|
-
if (Array.isArray(value)) {
|
|
89
|
-
for (var index = 0; index < value.length; index += 1) {
|
|
90
|
-
var nestedReason = getFallbackReasonForValue(value[index])
|
|
91
|
-
if (nestedReason) {
|
|
92
|
-
return nestedReason
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
var constructorName = getCanvasObjectConstructorName(value)
|
|
98
|
-
if (!constructorName || !UNSUPPORTED_REPLAY_OBJECT_NAMES[constructorName]) {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
133
|
+
function getFallbackReasonForConstructorName(constructorName) {
|
|
101
134
|
if (constructorName === 'CanvasGradient') {
|
|
102
135
|
return 'gradient_style_assignment'
|
|
103
136
|
}
|
|
@@ -110,6 +143,294 @@ function getFallbackReasonForValue(value) {
|
|
|
110
143
|
return 'unsupported_canvas_object'
|
|
111
144
|
}
|
|
112
145
|
|
|
146
|
+
function addApproxBytes(state, bytes) {
|
|
147
|
+
if (
|
|
148
|
+
!isFinite(bytes) ||
|
|
149
|
+
bytes < 0 ||
|
|
150
|
+
bytes > state.limit - state.bytes
|
|
151
|
+
) {
|
|
152
|
+
state.overflow = true
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
state.bytes += bytes
|
|
156
|
+
return true
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function addStringApproxBytes(state, value) {
|
|
160
|
+
if (!addApproxBytes(state, 2)) {
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
for (var index = 0; index < value.length && !state.overflow; index += 1) {
|
|
164
|
+
var code = value.charCodeAt(index)
|
|
165
|
+
if (code === 0x22 || code === 0x5c) {
|
|
166
|
+
addApproxBytes(state, 2)
|
|
167
|
+
} else if (code <= 0x1f) {
|
|
168
|
+
addApproxBytes(state, 6)
|
|
169
|
+
} else if (code <= 0x7f) {
|
|
170
|
+
addApproxBytes(state, 1)
|
|
171
|
+
} else if (code <= 0x7ff) {
|
|
172
|
+
addApproxBytes(state, 2)
|
|
173
|
+
} else if (code >= 0xd800 && code <= 0xdbff) {
|
|
174
|
+
var nextCode = value.charCodeAt(index + 1)
|
|
175
|
+
if (nextCode >= 0xdc00 && nextCode <= 0xdfff) {
|
|
176
|
+
index += 1
|
|
177
|
+
addApproxBytes(state, 4)
|
|
178
|
+
} else {
|
|
179
|
+
addApproxBytes(state, 6)
|
|
180
|
+
}
|
|
181
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
182
|
+
addApproxBytes(state, 6)
|
|
183
|
+
} else {
|
|
184
|
+
addApproxBytes(state, 3)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function addPrimitiveApproxBytes(state, value) {
|
|
190
|
+
if (value === null || value === undefined) {
|
|
191
|
+
addApproxBytes(state, 4)
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
194
|
+
if (typeof value === 'string') {
|
|
195
|
+
addStringApproxBytes(state, value)
|
|
196
|
+
return true
|
|
197
|
+
}
|
|
198
|
+
if (typeof value === 'number') {
|
|
199
|
+
addApproxBytes(
|
|
200
|
+
state,
|
|
201
|
+
isFinite(value) ? String(value).length : 4
|
|
202
|
+
)
|
|
203
|
+
return true
|
|
204
|
+
}
|
|
205
|
+
if (typeof value === 'boolean') {
|
|
206
|
+
addApproxBytes(state, value ? 4 : 5)
|
|
207
|
+
return true
|
|
208
|
+
}
|
|
209
|
+
if (typeof value === 'function' || typeof value === 'symbol') {
|
|
210
|
+
addApproxBytes(state, 4)
|
|
211
|
+
return true
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === 'bigint') {
|
|
214
|
+
throw new Error('Unsupported canvas command bigint argument')
|
|
215
|
+
}
|
|
216
|
+
return false
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getTypedArrayElementApproxBytes(value) {
|
|
220
|
+
var constructorName = getCanvasObjectConstructorName(value)
|
|
221
|
+
if (
|
|
222
|
+
constructorName === 'Uint8Array' ||
|
|
223
|
+
constructorName === 'Uint8ClampedArray'
|
|
224
|
+
) {
|
|
225
|
+
return 4
|
|
226
|
+
}
|
|
227
|
+
if (constructorName === 'Int8Array') {
|
|
228
|
+
return 5
|
|
229
|
+
}
|
|
230
|
+
if (constructorName === 'Uint16Array') {
|
|
231
|
+
return 6
|
|
232
|
+
}
|
|
233
|
+
if (constructorName === 'Int16Array') {
|
|
234
|
+
return 7
|
|
235
|
+
}
|
|
236
|
+
if (constructorName === 'Uint32Array') {
|
|
237
|
+
return 11
|
|
238
|
+
}
|
|
239
|
+
if (constructorName === 'Int32Array') {
|
|
240
|
+
return 12
|
|
241
|
+
}
|
|
242
|
+
return 25
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function isSerializedTypedArray(value) {
|
|
246
|
+
return (
|
|
247
|
+
value instanceof Float32Array ||
|
|
248
|
+
value instanceof Float64Array ||
|
|
249
|
+
value instanceof Int32Array ||
|
|
250
|
+
value instanceof Uint32Array ||
|
|
251
|
+
value instanceof Uint8Array ||
|
|
252
|
+
value instanceof Uint16Array ||
|
|
253
|
+
value instanceof Int16Array ||
|
|
254
|
+
value instanceof Int8Array ||
|
|
255
|
+
value instanceof Uint8ClampedArray
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function addTypedArrayApproxBytes(state, value) {
|
|
260
|
+
var elementCount = value.length
|
|
261
|
+
var perElementBytes = getTypedArrayElementApproxBytes(value)
|
|
262
|
+
addApproxBytes(
|
|
263
|
+
state,
|
|
264
|
+
32 +
|
|
265
|
+
(elementCount ? elementCount * perElementBytes + elementCount - 1 : 0)
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function addArrayBufferApproxBytes(state, buffer) {
|
|
270
|
+
addApproxBytes(state, 36 + Math.ceil(buffer.byteLength / 3) * 4)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function estimateCanvasCommand(property, args, setter, limit) {
|
|
274
|
+
var state = {
|
|
275
|
+
bytes: 0,
|
|
276
|
+
fallbackReason: undefined,
|
|
277
|
+
limit: limit,
|
|
278
|
+
overflow: false
|
|
279
|
+
}
|
|
280
|
+
addApproxBytes(
|
|
281
|
+
state,
|
|
282
|
+
CANVAS_COMMAND_BASE_APPROX_BYTES +
|
|
283
|
+
(setter ? CANVAS_COMMAND_SETTER_APPROX_BYTES : 0)
|
|
284
|
+
)
|
|
285
|
+
addStringApproxBytes(state, property)
|
|
286
|
+
if (state.overflow) {
|
|
287
|
+
return state
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var argCount = args.length
|
|
291
|
+
var minimumArgsBytes =
|
|
292
|
+
2 + (argCount ? argCount - 1 + argCount : 0)
|
|
293
|
+
if (minimumArgsBytes > state.limit - state.bytes) {
|
|
294
|
+
state.overflow = true
|
|
295
|
+
return state
|
|
296
|
+
}
|
|
297
|
+
addApproxBytes(state, 2 + (argCount ? argCount - 1 : 0))
|
|
298
|
+
|
|
299
|
+
var firstComplexArgIndex = argCount
|
|
300
|
+
for (
|
|
301
|
+
var primitiveArgIndex = 0;
|
|
302
|
+
primitiveArgIndex < argCount && !state.overflow;
|
|
303
|
+
primitiveArgIndex += 1
|
|
304
|
+
) {
|
|
305
|
+
if (!addPrimitiveApproxBytes(state, args[primitiveArgIndex])) {
|
|
306
|
+
firstComplexArgIndex = primitiveArgIndex
|
|
307
|
+
break
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (
|
|
311
|
+
state.overflow ||
|
|
312
|
+
firstComplexArgIndex === argCount
|
|
313
|
+
) {
|
|
314
|
+
return state
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
var seenArrays
|
|
318
|
+
var stack = []
|
|
319
|
+
for (
|
|
320
|
+
var argIndex = argCount - 1;
|
|
321
|
+
argIndex >= firstComplexArgIndex;
|
|
322
|
+
argIndex -= 1
|
|
323
|
+
) {
|
|
324
|
+
stack.push({ type: 'value', value: args[argIndex] })
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
while (stack.length && !state.overflow && !state.fallbackReason) {
|
|
328
|
+
var task = stack.pop()
|
|
329
|
+
if (task.type === 'array') {
|
|
330
|
+
if (task.index >= task.value.length) {
|
|
331
|
+
if (seenArrays) {
|
|
332
|
+
seenArrays.delete(task.value)
|
|
333
|
+
}
|
|
334
|
+
continue
|
|
335
|
+
}
|
|
336
|
+
var arrayIndex = task.index
|
|
337
|
+
task.index += 1
|
|
338
|
+
stack.push(task)
|
|
339
|
+
stack.push({
|
|
340
|
+
type: 'value',
|
|
341
|
+
value:
|
|
342
|
+
arrayIndex in task.value
|
|
343
|
+
? task.value[arrayIndex]
|
|
344
|
+
: undefined
|
|
345
|
+
})
|
|
346
|
+
continue
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
var value = task.value
|
|
350
|
+
if (addPrimitiveApproxBytes(state, value)) {
|
|
351
|
+
continue
|
|
352
|
+
}
|
|
353
|
+
if (Array.isArray(value)) {
|
|
354
|
+
if (seenArrays && seenArrays.has(value)) {
|
|
355
|
+
throw new Error('Circular canvas command argument')
|
|
356
|
+
}
|
|
357
|
+
var arrayLength = value.length
|
|
358
|
+
var minimumArrayBytes =
|
|
359
|
+
2 + (arrayLength ? arrayLength - 1 + arrayLength : 0)
|
|
360
|
+
if (minimumArrayBytes > state.limit - state.bytes) {
|
|
361
|
+
state.overflow = true
|
|
362
|
+
break
|
|
363
|
+
}
|
|
364
|
+
addApproxBytes(
|
|
365
|
+
state,
|
|
366
|
+
2 + (arrayLength ? arrayLength - 1 : 0)
|
|
367
|
+
)
|
|
368
|
+
if (!seenArrays) {
|
|
369
|
+
seenArrays = new WeakSet()
|
|
370
|
+
}
|
|
371
|
+
seenArrays.add(value)
|
|
372
|
+
stack.push({ type: 'array', value: value, index: 0 })
|
|
373
|
+
continue
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (
|
|
377
|
+
typeof HTMLCanvasElement !== 'undefined' &&
|
|
378
|
+
value instanceof HTMLCanvasElement
|
|
379
|
+
) {
|
|
380
|
+
state.fallbackReason = 'canvas_element_argument'
|
|
381
|
+
break
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
var constructorName = getCanvasObjectConstructorName(value)
|
|
385
|
+
if (
|
|
386
|
+
constructorName &&
|
|
387
|
+
UNSUPPORTED_REPLAY_OBJECT_NAMES[constructorName]
|
|
388
|
+
) {
|
|
389
|
+
state.fallbackReason =
|
|
390
|
+
getFallbackReasonForConstructorName(constructorName)
|
|
391
|
+
break
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (isSerializedTypedArray(value)) {
|
|
395
|
+
addTypedArrayApproxBytes(state, value)
|
|
396
|
+
continue
|
|
397
|
+
}
|
|
398
|
+
if (value instanceof ArrayBuffer) {
|
|
399
|
+
addArrayBufferApproxBytes(state, value)
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
if (value instanceof DataView) {
|
|
403
|
+
addArrayBufferApproxBytes(state, value.buffer)
|
|
404
|
+
addApproxBytes(state, 32)
|
|
405
|
+
continue
|
|
406
|
+
}
|
|
407
|
+
if (
|
|
408
|
+
typeof ImageData !== 'undefined' &&
|
|
409
|
+
value instanceof ImageData
|
|
410
|
+
) {
|
|
411
|
+
addTypedArrayApproxBytes(state, value.data)
|
|
412
|
+
addApproxBytes(state, 32)
|
|
413
|
+
continue
|
|
414
|
+
}
|
|
415
|
+
if (
|
|
416
|
+
typeof HTMLImageElement !== 'undefined' &&
|
|
417
|
+
value instanceof HTMLImageElement
|
|
418
|
+
) {
|
|
419
|
+
addApproxBytes(state, 36)
|
|
420
|
+
addStringApproxBytes(state, value.currentSrc || value.src || '')
|
|
421
|
+
continue
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// rrweb can only resolve object references that were produced by a
|
|
425
|
+
// previous replayed canvas command. Arbitrary platform objects such as
|
|
426
|
+
// DOMMatrix, ImageBitmap or VideoFrame would otherwise become dangling
|
|
427
|
+
// { rr_type, index } references and change the replayed draw semantics.
|
|
428
|
+
state.fallbackReason = 'unsupported_canvas_object'
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return state
|
|
432
|
+
}
|
|
433
|
+
|
|
113
434
|
function isCrossOriginImageElement(value) {
|
|
114
435
|
if (typeof HTMLImageElement === 'undefined' || !(value instanceof HTMLImageElement)) {
|
|
115
436
|
return false
|
|
@@ -129,45 +450,85 @@ function isCrossOriginImageElement(value) {
|
|
|
129
450
|
}
|
|
130
451
|
|
|
131
452
|
function isUnsupportedDrawImageSource(value) {
|
|
453
|
+
if (
|
|
454
|
+
typeof HTMLImageElement !== 'undefined' &&
|
|
455
|
+
value instanceof HTMLImageElement
|
|
456
|
+
) {
|
|
457
|
+
var imageSource = value.currentSrc || value.src || ''
|
|
458
|
+
if (
|
|
459
|
+
imageSource.indexOf('blob:') === 0 ||
|
|
460
|
+
imageSource.indexOf('filesystem:') === 0
|
|
461
|
+
) {
|
|
462
|
+
return 'draw_image_unsupported_source'
|
|
463
|
+
}
|
|
464
|
+
return isCrossOriginImageElement(value)
|
|
465
|
+
? 'draw_image_cross_origin'
|
|
466
|
+
: undefined
|
|
467
|
+
}
|
|
132
468
|
if (typeof HTMLCanvasElement !== 'undefined' && value instanceof HTMLCanvasElement) {
|
|
133
469
|
return 'draw_image_canvas'
|
|
134
470
|
}
|
|
135
471
|
if (typeof HTMLVideoElement !== 'undefined' && value instanceof HTMLVideoElement) {
|
|
136
472
|
return 'draw_image_video'
|
|
137
473
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
474
|
+
// HTMLImageElement is the only CanvasImageSource that the replay player can
|
|
475
|
+
// recreate independently. ImageBitmap, OffscreenCanvas, VideoFrame and SVG
|
|
476
|
+
// image sources would otherwise be serialized as object references without
|
|
477
|
+
// a matching producer command and replay as drawImage(undefined, ...).
|
|
478
|
+
return 'draw_image_unsupported_source'
|
|
141
479
|
}
|
|
142
480
|
|
|
143
481
|
export function createCanvas2DCommandRecorder(options) {
|
|
144
482
|
options = options || {}
|
|
145
483
|
var emit = options.emit || function () {}
|
|
146
|
-
var now =
|
|
484
|
+
var now = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
|
|
485
|
+
? options.now || Date.now
|
|
486
|
+
: Date.now
|
|
147
487
|
var requestAnimationFrameImpl =
|
|
148
|
-
|
|
488
|
+
(__BUILD_ENV__REPLAY_DEBUG_ENABLED__ &&
|
|
489
|
+
options.requestAnimationFrameImpl) ||
|
|
149
490
|
function (callback) {
|
|
150
491
|
return window.requestAnimationFrame(callback)
|
|
151
492
|
}
|
|
152
493
|
var cancelAnimationFrameImpl =
|
|
153
|
-
|
|
494
|
+
(__BUILD_ENV__REPLAY_DEBUG_ENABLED__ &&
|
|
495
|
+
options.cancelAnimationFrameImpl) ||
|
|
154
496
|
function (rafId) {
|
|
155
497
|
return window.cancelAnimationFrame(rafId)
|
|
156
498
|
}
|
|
499
|
+
var setTimeoutImpl =
|
|
500
|
+
(__BUILD_ENV__REPLAY_DEBUG_ENABLED__ && options.setTimeoutImpl) ||
|
|
501
|
+
function (callback, delay) {
|
|
502
|
+
return setTimeout(callback, delay)
|
|
503
|
+
}
|
|
504
|
+
var clearTimeoutImpl =
|
|
505
|
+
(__BUILD_ENV__REPLAY_DEBUG_ENABLED__ && options.clearTimeoutImpl) ||
|
|
506
|
+
function (timeoutId) {
|
|
507
|
+
return clearTimeout(timeoutId)
|
|
508
|
+
}
|
|
157
509
|
|
|
158
510
|
var trackedContexts = []
|
|
159
|
-
var trackedContextSet = new
|
|
511
|
+
var trackedContextSet = new WeakSet()
|
|
512
|
+
var captureGenerationByContext = new WeakMap()
|
|
513
|
+
var captureGeneration = 0
|
|
514
|
+
var rejectedContextSet = new WeakSet()
|
|
160
515
|
var patchedPrototypeRecords = []
|
|
516
|
+
var snapshotFallbackPatchTargets = new WeakSet()
|
|
161
517
|
var pendingCommandsByContext = new Map()
|
|
518
|
+
var pendingCommandApproxBytes = 0
|
|
162
519
|
var fallbackModeContexts = new WeakSet()
|
|
520
|
+
var persistentFallbackModeContexts = new WeakSet()
|
|
163
521
|
var fallbackReasonByContext = new WeakMap()
|
|
522
|
+
var persistentFallbackReasonByContext = new WeakMap()
|
|
523
|
+
var expiredUnpublishedContexts = new WeakSet()
|
|
164
524
|
var patchedOpaqueObjects = new WeakSet()
|
|
165
525
|
var patchedOpaqueObjectRefs = []
|
|
526
|
+
var patchedOpaqueObjectRefAddCount = 0
|
|
527
|
+
var patchedOpaqueObjectRefLastCompactionCount = 0
|
|
166
528
|
var opaqueObjectContextMap = new WeakMap()
|
|
167
|
-
var weakRefFactory =
|
|
168
|
-
|
|
169
|
-
'weakRefFactory'
|
|
170
|
-
)
|
|
529
|
+
var weakRefFactory =
|
|
530
|
+
__BUILD_ENV__REPLAY_DEBUG_ENABLED__ &&
|
|
531
|
+
Object.prototype.hasOwnProperty.call(options, 'weakRefFactory')
|
|
171
532
|
? typeof options.weakRefFactory === 'function'
|
|
172
533
|
? options.weakRefFactory
|
|
173
534
|
: undefined
|
|
@@ -177,8 +538,16 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
177
538
|
}
|
|
178
539
|
: undefined
|
|
179
540
|
var scheduledFlushId
|
|
541
|
+
var unpublishedCleanupTimeoutId
|
|
542
|
+
var unpublishedCleanupDeadline
|
|
180
543
|
var stopped = false
|
|
181
544
|
var paused = false
|
|
545
|
+
var objectRefRegistry =
|
|
546
|
+
(__BUILD_ENV__REPLAY_DEBUG_ENABLED__ && options.objectRefRegistry) ||
|
|
547
|
+
createCanvasCommandObjectRefRegistry()
|
|
548
|
+
var onCommandOverflow = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
|
|
549
|
+
? options.onCommandOverflow || function () {}
|
|
550
|
+
: undefined
|
|
182
551
|
var getCanvasId =
|
|
183
552
|
options.getCanvasId ||
|
|
184
553
|
function (context) {
|
|
@@ -191,6 +560,10 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
191
560
|
}
|
|
192
561
|
var requestSnapshotFallback =
|
|
193
562
|
options.requestSnapshotFallback || function () {}
|
|
563
|
+
var onContextDiscovered =
|
|
564
|
+
options.onContextDiscovered || function () {}
|
|
565
|
+
var onContextMutation =
|
|
566
|
+
options.onContextMutation || function () {}
|
|
194
567
|
var shouldRecordContext =
|
|
195
568
|
options.shouldRecordContext ||
|
|
196
569
|
function () {
|
|
@@ -207,57 +580,472 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
207
580
|
})
|
|
208
581
|
}
|
|
209
582
|
|
|
210
|
-
function
|
|
211
|
-
|
|
583
|
+
function getOrCreatePendingBatch(context) {
|
|
584
|
+
var batch = pendingCommandsByContext.get(context)
|
|
585
|
+
if (!batch) {
|
|
586
|
+
if (
|
|
587
|
+
pendingCommandsByContext.size >=
|
|
588
|
+
MAX_PENDING_CANVAS_COMMAND_CONTEXTS
|
|
589
|
+
) {
|
|
590
|
+
return
|
|
591
|
+
}
|
|
592
|
+
var startedAt = now()
|
|
593
|
+
var canvasId = getCanvasId(context)
|
|
594
|
+
batch = {
|
|
595
|
+
commands: [],
|
|
596
|
+
approxBytesCount: 0,
|
|
597
|
+
startedAt: startedAt,
|
|
598
|
+
fallbackDirty: false,
|
|
599
|
+
fallbackSnapshotRequested: false,
|
|
600
|
+
unpublishedDeadline:
|
|
601
|
+
canvasId === undefined ||
|
|
602
|
+
canvasId === null ||
|
|
603
|
+
canvasId === -1
|
|
604
|
+
? startedAt +
|
|
605
|
+
MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS
|
|
606
|
+
: undefined
|
|
607
|
+
}
|
|
608
|
+
pendingCommandsByContext.set(context, batch)
|
|
609
|
+
if (batch.unpublishedDeadline !== undefined) {
|
|
610
|
+
refreshUnpublishedCleanupTimer()
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return batch
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function isSnapshotFallbackContext(context) {
|
|
617
|
+
return (
|
|
618
|
+
fallbackModeContexts.has(context) ||
|
|
619
|
+
persistentFallbackModeContexts.has(context)
|
|
620
|
+
)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function getSnapshotFallbackReason(context) {
|
|
624
|
+
return (
|
|
625
|
+
persistentFallbackReasonByContext.get(context) ||
|
|
626
|
+
fallbackReasonByContext.get(context)
|
|
627
|
+
)
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function deletePendingBatch(context) {
|
|
631
|
+
var batch = pendingCommandsByContext.get(context)
|
|
632
|
+
if (!batch) {
|
|
212
633
|
return
|
|
213
634
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
635
|
+
pendingCommandApproxBytes = Math.max(
|
|
636
|
+
0,
|
|
637
|
+
pendingCommandApproxBytes - batch.approxBytesCount
|
|
638
|
+
)
|
|
639
|
+
pendingCommandsByContext.delete(context)
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function clearUnpublishedCleanupTimer() {
|
|
643
|
+
if (unpublishedCleanupTimeoutId !== undefined) {
|
|
644
|
+
clearTimeoutImpl(unpublishedCleanupTimeoutId)
|
|
645
|
+
unpublishedCleanupTimeoutId = undefined
|
|
646
|
+
}
|
|
647
|
+
unpublishedCleanupDeadline = undefined
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function clearPendingBatches() {
|
|
651
|
+
pendingCommandsByContext.clear()
|
|
652
|
+
pendingCommandApproxBytes = 0
|
|
653
|
+
clearUnpublishedCleanupTimer()
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function expireUnpublishedBatch(context) {
|
|
657
|
+
deletePendingBatch(context)
|
|
658
|
+
persistentFallbackModeContexts.add(context)
|
|
659
|
+
expiredUnpublishedContexts.add(context)
|
|
660
|
+
if (!persistentFallbackReasonByContext.has(context)) {
|
|
661
|
+
persistentFallbackReasonByContext.set(
|
|
662
|
+
context,
|
|
663
|
+
'canvas_publication_timeout'
|
|
664
|
+
)
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function expireOverdueUnpublishedBatches() {
|
|
669
|
+
if (unpublishedCleanupDeadline === undefined) {
|
|
670
|
+
return
|
|
671
|
+
}
|
|
672
|
+
var currentTime = now()
|
|
673
|
+
if (currentTime < unpublishedCleanupDeadline) {
|
|
674
|
+
return
|
|
675
|
+
}
|
|
676
|
+
pendingCommandsByContext.forEach(function (batch, context) {
|
|
677
|
+
if (
|
|
678
|
+
batch.unpublishedDeadline !== undefined &&
|
|
679
|
+
currentTime >= batch.unpublishedDeadline
|
|
680
|
+
) {
|
|
681
|
+
expireUnpublishedBatch(context)
|
|
682
|
+
}
|
|
683
|
+
})
|
|
684
|
+
refreshUnpublishedCleanupTimer()
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function refreshUnpublishedCleanupTimer() {
|
|
688
|
+
var earliestDeadline
|
|
689
|
+
pendingCommandsByContext.forEach(function (batch) {
|
|
690
|
+
if (
|
|
691
|
+
batch.unpublishedDeadline !== undefined &&
|
|
692
|
+
(earliestDeadline === undefined ||
|
|
693
|
+
batch.unpublishedDeadline < earliestDeadline)
|
|
694
|
+
) {
|
|
695
|
+
earliestDeadline = batch.unpublishedDeadline
|
|
696
|
+
}
|
|
697
|
+
})
|
|
698
|
+
|
|
699
|
+
if (earliestDeadline === undefined) {
|
|
700
|
+
clearUnpublishedCleanupTimer()
|
|
701
|
+
return
|
|
702
|
+
}
|
|
703
|
+
if (
|
|
704
|
+
unpublishedCleanupTimeoutId !== undefined &&
|
|
705
|
+
unpublishedCleanupDeadline === earliestDeadline
|
|
706
|
+
) {
|
|
707
|
+
return
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
clearUnpublishedCleanupTimer()
|
|
711
|
+
unpublishedCleanupDeadline = earliestDeadline
|
|
712
|
+
unpublishedCleanupTimeoutId = setTimeoutImpl(function () {
|
|
713
|
+
unpublishedCleanupTimeoutId = undefined
|
|
714
|
+
unpublishedCleanupDeadline = undefined
|
|
715
|
+
flush()
|
|
716
|
+
}, Math.max(earliestDeadline - now(), 0))
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function reportCommandOverflow(reason, context) {
|
|
720
|
+
if (__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
|
|
721
|
+
onCommandOverflow({
|
|
722
|
+
reason: reason,
|
|
723
|
+
context: context,
|
|
724
|
+
pendingContextCount: pendingCommandsByContext.size,
|
|
725
|
+
pendingApproxBytes: pendingCommandApproxBytes
|
|
218
726
|
})
|
|
219
727
|
}
|
|
220
|
-
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function enqueueCommand(context, command, approxBytesCount) {
|
|
731
|
+
if (paused) {
|
|
732
|
+
return false
|
|
733
|
+
}
|
|
734
|
+
if (isSnapshotFallbackContext(context)) {
|
|
735
|
+
markSnapshotFallbackDirty(context)
|
|
736
|
+
return false
|
|
737
|
+
}
|
|
738
|
+
var batch = getOrCreatePendingBatch(context)
|
|
739
|
+
if (!batch) {
|
|
740
|
+
enableSnapshotFallbackForContext(
|
|
741
|
+
context,
|
|
742
|
+
'command_global_context_watermark',
|
|
743
|
+
true
|
|
744
|
+
)
|
|
745
|
+
return false
|
|
746
|
+
}
|
|
747
|
+
if (
|
|
748
|
+
batch.commands.length >= MAX_CANVAS_COMMANDS_PER_BATCH ||
|
|
749
|
+
approxBytesCount >
|
|
750
|
+
MAX_CANVAS_COMMAND_BATCH_BYTES - batch.approxBytesCount
|
|
751
|
+
) {
|
|
752
|
+
enableSnapshotFallbackForContext(
|
|
753
|
+
context,
|
|
754
|
+
'command_batch_overflow'
|
|
755
|
+
)
|
|
756
|
+
return false
|
|
757
|
+
}
|
|
758
|
+
if (
|
|
759
|
+
approxBytesCount >
|
|
760
|
+
MAX_PENDING_CANVAS_COMMAND_BYTES - pendingCommandApproxBytes
|
|
761
|
+
) {
|
|
762
|
+
enableSnapshotFallbackForContext(
|
|
763
|
+
context,
|
|
764
|
+
'command_global_bytes_watermark',
|
|
765
|
+
true
|
|
766
|
+
)
|
|
767
|
+
return false
|
|
768
|
+
}
|
|
769
|
+
batch.commands.push(command)
|
|
770
|
+
batch.approxBytesCount += approxBytesCount
|
|
771
|
+
pendingCommandApproxBytes += approxBytesCount
|
|
221
772
|
scheduleFlush()
|
|
773
|
+
return true
|
|
222
774
|
}
|
|
223
775
|
|
|
224
|
-
function
|
|
225
|
-
if (
|
|
776
|
+
function captureCommand(context, property, args, setter) {
|
|
777
|
+
if (paused) {
|
|
778
|
+
return
|
|
779
|
+
}
|
|
780
|
+
expireOverdueUnpublishedBatches()
|
|
781
|
+
if (isSnapshotFallbackContext(context)) {
|
|
782
|
+
markSnapshotFallbackDirty(context)
|
|
783
|
+
return
|
|
784
|
+
}
|
|
785
|
+
var batch = getOrCreatePendingBatch(context)
|
|
786
|
+
if (!batch) {
|
|
787
|
+
enableSnapshotFallbackForContext(
|
|
788
|
+
context,
|
|
789
|
+
'command_global_context_watermark',
|
|
790
|
+
true
|
|
791
|
+
)
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
if (batch.commands.length >= MAX_CANVAS_COMMANDS_PER_BATCH) {
|
|
795
|
+
enableSnapshotFallbackForContext(
|
|
796
|
+
context,
|
|
797
|
+
'command_batch_overflow'
|
|
798
|
+
)
|
|
226
799
|
return
|
|
227
800
|
}
|
|
228
801
|
|
|
229
|
-
|
|
230
|
-
|
|
802
|
+
var estimate
|
|
803
|
+
try {
|
|
804
|
+
estimate = estimateCanvasCommand(
|
|
805
|
+
property,
|
|
806
|
+
args,
|
|
807
|
+
setter,
|
|
808
|
+
MAX_CANVAS_COMMAND_BATCH_BYTES - batch.approxBytesCount
|
|
809
|
+
)
|
|
810
|
+
} catch (_) {
|
|
811
|
+
enableSnapshotFallbackForContext(
|
|
812
|
+
context,
|
|
813
|
+
'command_serialization_error'
|
|
814
|
+
)
|
|
815
|
+
return
|
|
816
|
+
}
|
|
817
|
+
if (estimate.fallbackReason) {
|
|
818
|
+
enableSnapshotFallbackForContext(
|
|
819
|
+
context,
|
|
820
|
+
estimate.fallbackReason
|
|
821
|
+
)
|
|
822
|
+
return
|
|
823
|
+
}
|
|
824
|
+
if (estimate.overflow) {
|
|
825
|
+
enableSnapshotFallbackForContext(
|
|
826
|
+
context,
|
|
827
|
+
'command_batch_overflow'
|
|
828
|
+
)
|
|
829
|
+
return
|
|
830
|
+
}
|
|
831
|
+
if (
|
|
832
|
+
estimate.bytes >
|
|
833
|
+
MAX_PENDING_CANVAS_COMMAND_BYTES - pendingCommandApproxBytes
|
|
834
|
+
) {
|
|
835
|
+
enableSnapshotFallbackForContext(
|
|
836
|
+
context,
|
|
837
|
+
'command_global_bytes_watermark',
|
|
838
|
+
true
|
|
839
|
+
)
|
|
840
|
+
return
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
var serializedArgs
|
|
844
|
+
try {
|
|
845
|
+
serializedArgs = objectRefRegistry.serializeArgs(args, context)
|
|
846
|
+
} catch (_) {
|
|
847
|
+
enableSnapshotFallbackForContext(
|
|
848
|
+
context,
|
|
849
|
+
'command_serialization_error'
|
|
850
|
+
)
|
|
851
|
+
return
|
|
852
|
+
}
|
|
853
|
+
var command = {
|
|
854
|
+
property: property,
|
|
855
|
+
args: serializedArgs
|
|
856
|
+
}
|
|
857
|
+
if (setter === true) {
|
|
858
|
+
command.setter = true
|
|
859
|
+
}
|
|
860
|
+
enqueueCommand(context, command, estimate.bytes)
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function markSnapshotFallbackDirty(context, requestImmediately) {
|
|
864
|
+
if (paused || expiredUnpublishedContexts.has(context)) {
|
|
865
|
+
return
|
|
866
|
+
}
|
|
867
|
+
var batch = pendingCommandsByContext.get(context)
|
|
868
|
+
if (!batch) {
|
|
869
|
+
if (
|
|
870
|
+
pendingCommandsByContext.size >=
|
|
871
|
+
MAX_PENDING_CANVAS_COMMAND_CONTEXTS
|
|
872
|
+
) {
|
|
873
|
+
requestSnapshotFallback(
|
|
874
|
+
context,
|
|
875
|
+
getSnapshotFallbackReason(context) ||
|
|
876
|
+
'unsupported_canvas_object'
|
|
877
|
+
)
|
|
231
878
|
return
|
|
232
879
|
}
|
|
233
|
-
|
|
880
|
+
var startedAt = now()
|
|
881
|
+
var canvasId = getCanvasId(context)
|
|
882
|
+
batch = {
|
|
883
|
+
commands: [],
|
|
884
|
+
approxBytesCount: 0,
|
|
885
|
+
startedAt: startedAt,
|
|
886
|
+
fallbackDirty: true,
|
|
887
|
+
fallbackSnapshotRequested: false,
|
|
888
|
+
unpublishedDeadline:
|
|
889
|
+
canvasId === undefined ||
|
|
890
|
+
canvasId === null ||
|
|
891
|
+
canvasId === -1
|
|
892
|
+
? startedAt +
|
|
893
|
+
MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS
|
|
894
|
+
: undefined
|
|
895
|
+
}
|
|
896
|
+
pendingCommandsByContext.set(context, batch)
|
|
897
|
+
if (batch.unpublishedDeadline !== undefined) {
|
|
898
|
+
refreshUnpublishedCleanupTimer()
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
pendingCommandApproxBytes = Math.max(
|
|
902
|
+
0,
|
|
903
|
+
pendingCommandApproxBytes - batch.approxBytesCount
|
|
904
|
+
)
|
|
905
|
+
batch.commands = []
|
|
906
|
+
batch.approxBytesCount = 0
|
|
907
|
+
batch.fallbackDirty = true
|
|
908
|
+
}
|
|
909
|
+
if (requestImmediately && !batch.fallbackSnapshotRequested) {
|
|
910
|
+
batch.fallbackSnapshotRequested = true
|
|
911
|
+
requestSnapshotFallback(
|
|
912
|
+
context,
|
|
913
|
+
getSnapshotFallbackReason(context) || 'unsupported_canvas_object'
|
|
914
|
+
)
|
|
915
|
+
}
|
|
916
|
+
scheduleFlush()
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function flushPendingContext(context, flushedAt) {
|
|
920
|
+
var batch = pendingCommandsByContext.get(context)
|
|
921
|
+
if (!batch) {
|
|
922
|
+
return
|
|
923
|
+
}
|
|
924
|
+
if (isSnapshotFallbackContext(context)) {
|
|
925
|
+
if (batch.fallbackDirty && !batch.fallbackSnapshotRequested) {
|
|
234
926
|
requestSnapshotFallback(
|
|
235
927
|
context,
|
|
236
|
-
|
|
928
|
+
getSnapshotFallbackReason(context) || 'unsupported_canvas_object'
|
|
237
929
|
)
|
|
238
|
-
return
|
|
239
930
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
931
|
+
deletePendingBatch(context)
|
|
932
|
+
return
|
|
933
|
+
}
|
|
934
|
+
if (!batch.commands.length) {
|
|
935
|
+
deletePendingBatch(context)
|
|
936
|
+
return
|
|
937
|
+
}
|
|
938
|
+
var id = getCanvasId(context)
|
|
939
|
+
if (id === undefined || id === null || id === -1) {
|
|
940
|
+
// A freshly inserted canvas can be drawn before its delayed DOM add is
|
|
941
|
+
// admitted. Retain it for a bounded publication grace period, then
|
|
942
|
+
// release the strong Map key and require an authoritative bitmap if
|
|
943
|
+
// the canvas is ever published later.
|
|
944
|
+
if (batch.unpublishedDeadline === undefined) {
|
|
945
|
+
batch.unpublishedDeadline =
|
|
946
|
+
flushedAt + MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS
|
|
947
|
+
}
|
|
948
|
+
if (flushedAt >= batch.unpublishedDeadline) {
|
|
949
|
+
expireUnpublishedBatch(context)
|
|
950
|
+
}
|
|
951
|
+
return
|
|
952
|
+
}
|
|
953
|
+
var completedAt = flushedAt
|
|
954
|
+
var commands = batch.commands
|
|
955
|
+
var recordAccepted = emit(
|
|
956
|
+
createCanvasMutationRecord({
|
|
957
|
+
id: id,
|
|
958
|
+
contextType: getCanvasType(context),
|
|
959
|
+
commands: commands,
|
|
960
|
+
timestamp: completedAt,
|
|
961
|
+
startedAt: batch.startedAt,
|
|
962
|
+
completedAt: completedAt
|
|
963
|
+
}),
|
|
964
|
+
{
|
|
965
|
+
approxBytesCount: batch.approxBytesCount,
|
|
966
|
+
commandCount: commands.length
|
|
243
967
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
completedAt: completedAt
|
|
253
|
-
})
|
|
968
|
+
)
|
|
969
|
+
if (recordAccepted === false) {
|
|
970
|
+
// The command batch never entered the replay segment. Its following
|
|
971
|
+
// commands can depend on state from this batch, so switch this context
|
|
972
|
+
// to bitmap snapshots and request an immediate visual rebaseline.
|
|
973
|
+
enableSnapshotFallbackForContext(
|
|
974
|
+
context,
|
|
975
|
+
'command_record_rejected'
|
|
254
976
|
)
|
|
977
|
+
}
|
|
978
|
+
deletePendingBatch(context)
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function flushContext(context) {
|
|
982
|
+
if (stopped || paused || !context) {
|
|
983
|
+
return
|
|
984
|
+
}
|
|
985
|
+
flushPendingContext(context, now())
|
|
986
|
+
refreshUnpublishedCleanupTimer()
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function flush() {
|
|
990
|
+
if (stopped || paused) {
|
|
991
|
+
return
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
var flushedAt = now()
|
|
995
|
+
pendingCommandsByContext.forEach(function (_, context) {
|
|
996
|
+
flushPendingContext(context, flushedAt)
|
|
255
997
|
})
|
|
256
|
-
|
|
998
|
+
refreshUnpublishedCleanupTimer()
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
function retryPublishedContext(context) {
|
|
1002
|
+
if (
|
|
1003
|
+
stopped ||
|
|
1004
|
+
paused ||
|
|
1005
|
+
!context ||
|
|
1006
|
+
!trackedContextSet.has(context)
|
|
1007
|
+
) {
|
|
1008
|
+
return false
|
|
1009
|
+
}
|
|
1010
|
+
expireOverdueUnpublishedBatches()
|
|
1011
|
+
var id = getCanvasId(context)
|
|
1012
|
+
if (id === undefined || id === null || id === -1) {
|
|
1013
|
+
return false
|
|
1014
|
+
}
|
|
1015
|
+
if (!pendingCommandsByContext.has(context)) {
|
|
1016
|
+
if (!expiredUnpublishedContexts.has(context)) {
|
|
1017
|
+
return false
|
|
1018
|
+
}
|
|
1019
|
+
expiredUnpublishedContexts.delete(context)
|
|
1020
|
+
// A canvas published after its command grace period no longer has a
|
|
1021
|
+
// complete command history. Rebaseline it once instead of retaining the
|
|
1022
|
+
// detached context strongly or replaying an incomplete command stream.
|
|
1023
|
+
markSnapshotFallbackDirty(context, true)
|
|
1024
|
+
}
|
|
1025
|
+
// Publication belongs to one exact DOM admission boundary. Flushing every
|
|
1026
|
+
// context here could move commands from another, already-published canvas
|
|
1027
|
+
// ahead of DOM mutations that happened before its scheduled frame.
|
|
1028
|
+
flushContext(context)
|
|
1029
|
+
return true
|
|
257
1030
|
}
|
|
258
1031
|
|
|
259
1032
|
function shouldCaptureContext(context) {
|
|
260
|
-
|
|
1033
|
+
if (!trackedContextSet.has(context)) {
|
|
1034
|
+
return false
|
|
1035
|
+
}
|
|
1036
|
+
if (captureGenerationByContext.get(context) !== captureGeneration) {
|
|
1037
|
+
captureGenerationByContext.set(context, captureGeneration)
|
|
1038
|
+
// reset() accompanies a new replay/full-snapshot canvas baseline, but
|
|
1039
|
+
// it cannot reset the live application's transform, clip, path or style
|
|
1040
|
+
// state. Existing contexts therefore cannot safely resume command mode.
|
|
1041
|
+
enableSnapshotFallbackForContext(
|
|
1042
|
+
context,
|
|
1043
|
+
'canvas_state_reset',
|
|
1044
|
+
false,
|
|
1045
|
+
true
|
|
1046
|
+
)
|
|
1047
|
+
}
|
|
1048
|
+
return true
|
|
261
1049
|
}
|
|
262
1050
|
|
|
263
1051
|
function registerTrackedContext(context, restoreFns) {
|
|
@@ -266,55 +1054,123 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
266
1054
|
}
|
|
267
1055
|
restoreFns = restoreFns || []
|
|
268
1056
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
})
|
|
1057
|
+
if (
|
|
1058
|
+
restoreFns.length &&
|
|
1059
|
+
trackedContexts.length >=
|
|
1060
|
+
MAX_STRONG_CANVAS_CONTEXT_RESTORE_RECORDS
|
|
1061
|
+
) {
|
|
1062
|
+
return false
|
|
1063
|
+
}
|
|
277
1064
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
1065
|
+
if (restoreFns.length) {
|
|
1066
|
+
trackedContexts.push({
|
|
1067
|
+
context: context,
|
|
1068
|
+
restore: function () {
|
|
1069
|
+
trackedContextSet.delete(context)
|
|
1070
|
+
deletePendingBatch(context)
|
|
1071
|
+
expiredUnpublishedContexts.delete(context)
|
|
1072
|
+
fallbackModeContexts.delete(context)
|
|
1073
|
+
persistentFallbackModeContexts.delete(context)
|
|
1074
|
+
fallbackReasonByContext.delete(context)
|
|
1075
|
+
persistentFallbackReasonByContext.delete(context)
|
|
1076
|
+
while (restoreFns.length) {
|
|
1077
|
+
restoreFns.pop()()
|
|
1078
|
+
}
|
|
286
1079
|
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
1080
|
+
})
|
|
1081
|
+
}
|
|
289
1082
|
trackedContextSet.add(context)
|
|
1083
|
+
captureGenerationByContext.set(context, captureGeneration)
|
|
290
1084
|
return true
|
|
291
1085
|
}
|
|
292
1086
|
|
|
293
1087
|
function maybeTrackContext(context) {
|
|
294
1088
|
if (
|
|
1089
|
+
stopped ||
|
|
295
1090
|
!context ||
|
|
296
1091
|
trackedContextSet.has(context) ||
|
|
297
|
-
|
|
298
|
-
|
|
1092
|
+
rejectedContextSet.has(context) ||
|
|
1093
|
+
!context.canvas
|
|
299
1094
|
) {
|
|
300
1095
|
return false
|
|
301
1096
|
}
|
|
302
|
-
|
|
1097
|
+
if (shouldRecordContext(context) === false) {
|
|
1098
|
+
rejectedContextSet.add(context)
|
|
1099
|
+
return false
|
|
1100
|
+
}
|
|
1101
|
+
if (!registerTrackedContext(context, [])) {
|
|
1102
|
+
return false
|
|
1103
|
+
}
|
|
1104
|
+
var hasAuthoritativeBitmapBaseline = false
|
|
1105
|
+
try {
|
|
1106
|
+
hasAuthoritativeBitmapBaseline =
|
|
1107
|
+
onContextDiscovered(context) === true
|
|
1108
|
+
} catch (_) {}
|
|
1109
|
+
|
|
1110
|
+
// A context discovered through the already-patched shared prototype was
|
|
1111
|
+
// created before this recorder observed getContext(). Its current drawing
|
|
1112
|
+
// state (transform, clip/path and styles) cannot be reconstructed safely
|
|
1113
|
+
// from later commands, so keep this context on the snapshot path.
|
|
1114
|
+
if (hasAuthoritativeBitmapBaseline) {
|
|
1115
|
+
markPersistentSnapshotFallback(
|
|
1116
|
+
context,
|
|
1117
|
+
'existing_bitmap_state'
|
|
1118
|
+
)
|
|
1119
|
+
} else {
|
|
1120
|
+
enableSnapshotFallbackForContext(
|
|
1121
|
+
context,
|
|
1122
|
+
'existing_canvas_context',
|
|
1123
|
+
false,
|
|
1124
|
+
true
|
|
1125
|
+
)
|
|
1126
|
+
}
|
|
1127
|
+
return true
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function notifyContextMutation(context) {
|
|
1131
|
+
try {
|
|
1132
|
+
onContextMutation(context)
|
|
1133
|
+
} catch (_) {}
|
|
303
1134
|
}
|
|
304
1135
|
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
1136
|
+
function rejectContext(context) {
|
|
1137
|
+
if (!context) {
|
|
1138
|
+
return
|
|
1139
|
+
}
|
|
1140
|
+
rejectedContextSet.add(context)
|
|
1141
|
+
trackedContextSet.delete(context)
|
|
1142
|
+
deletePendingBatch(context)
|
|
1143
|
+
expiredUnpublishedContexts.delete(context)
|
|
1144
|
+
fallbackModeContexts.delete(context)
|
|
1145
|
+
persistentFallbackModeContexts.delete(context)
|
|
1146
|
+
fallbackReasonByContext.delete(context)
|
|
1147
|
+
persistentFallbackReasonByContext.delete(context)
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function enableSnapshotFallbackForContext(
|
|
1151
|
+
context,
|
|
1152
|
+
reason,
|
|
1153
|
+
isGlobalOverflow,
|
|
1154
|
+
persistent
|
|
1155
|
+
) {
|
|
1156
|
+
var fallbackContexts = persistent
|
|
1157
|
+
? persistentFallbackModeContexts
|
|
1158
|
+
: fallbackModeContexts
|
|
1159
|
+
var fallbackReasons = persistent
|
|
1160
|
+
? persistentFallbackReasonByContext
|
|
1161
|
+
: fallbackReasonByContext
|
|
1162
|
+
fallbackContexts.add(context)
|
|
1163
|
+
if (!fallbackReasons.has(context)) {
|
|
1164
|
+
fallbackReasons.set(
|
|
309
1165
|
context,
|
|
310
1166
|
reason || 'unsupported_canvas_object'
|
|
311
1167
|
)
|
|
312
1168
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
)
|
|
1169
|
+
if (isGlobalOverflow) {
|
|
1170
|
+
reportCommandOverflow(reason, context)
|
|
1171
|
+
}
|
|
1172
|
+
deletePendingBatch(context)
|
|
1173
|
+
markSnapshotFallbackDirty(context, true)
|
|
318
1174
|
}
|
|
319
1175
|
|
|
320
1176
|
function patchGradientObjectMethods(value, context) {
|
|
@@ -331,89 +1187,195 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
331
1187
|
if (patchedOpaqueObjects.has(value)) {
|
|
332
1188
|
return
|
|
333
1189
|
}
|
|
1190
|
+
if (
|
|
1191
|
+
!weakRefFactory &&
|
|
1192
|
+
patchedOpaqueObjectRefs.length >=
|
|
1193
|
+
MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS
|
|
1194
|
+
) {
|
|
1195
|
+
return
|
|
1196
|
+
}
|
|
334
1197
|
|
|
335
|
-
var
|
|
1198
|
+
var objectRef
|
|
336
1199
|
try {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
1200
|
+
objectRef = weakRefFactory
|
|
1201
|
+
? weakRefFactory(value)
|
|
1202
|
+
: { value: value }
|
|
1203
|
+
} catch (_) {
|
|
1204
|
+
return
|
|
1205
|
+
}
|
|
1206
|
+
if (!addPatchedOpaqueObjectRef(objectRef)) {
|
|
1207
|
+
return
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
var originalAddColorStop = value.addColorStop
|
|
1211
|
+
var wrappedAddColorStop = function () {
|
|
1212
|
+
if (
|
|
1213
|
+
stopped ||
|
|
1214
|
+
this[PATCHED_ADD_COLOR_STOP_KEY] !== wrappedAddColorStop
|
|
1215
|
+
) {
|
|
1216
|
+
var restoredOriginal = this[ORIGINAL_ADD_COLOR_STOP_KEY]
|
|
1217
|
+
if (typeof restoredOriginal === 'function') {
|
|
1218
|
+
if (this.addColorStop === wrappedAddColorStop) {
|
|
343
1219
|
this.addColorStop = restoredOriginal
|
|
344
|
-
delete this[ORIGINAL_ADD_COLOR_STOP_KEY]
|
|
345
|
-
delete this[PATCHED_ADD_COLOR_STOP_KEY]
|
|
346
|
-
return restoredOriginal.apply(this, arguments)
|
|
347
1220
|
}
|
|
1221
|
+
delete this[ORIGINAL_ADD_COLOR_STOP_KEY]
|
|
1222
|
+
delete this[PATCHED_ADD_COLOR_STOP_KEY]
|
|
1223
|
+
return restoredOriginal.apply(this, arguments)
|
|
348
1224
|
}
|
|
349
|
-
var fallbackContext = opaqueObjectContextMap.get(this)
|
|
350
|
-
if (fallbackContext && shouldCaptureContext(fallbackContext)) {
|
|
351
|
-
enableSnapshotFallbackForContext(fallbackContext, 'gradient_color_stop')
|
|
352
|
-
}
|
|
353
|
-
return originalAddColorStop.apply(this, arguments)
|
|
354
1225
|
}
|
|
1226
|
+
var result = originalAddColorStop.apply(this, arguments)
|
|
1227
|
+
var fallbackContext = opaqueObjectContextMap.get(this)
|
|
1228
|
+
if (fallbackContext && shouldCaptureContext(fallbackContext)) {
|
|
1229
|
+
notifyContextMutation(fallbackContext)
|
|
1230
|
+
enableSnapshotFallbackForContext(
|
|
1231
|
+
fallbackContext,
|
|
1232
|
+
'gradient_color_stop'
|
|
1233
|
+
)
|
|
1234
|
+
}
|
|
1235
|
+
return result
|
|
1236
|
+
}
|
|
1237
|
+
try {
|
|
1238
|
+
value[ORIGINAL_ADD_COLOR_STOP_KEY] = originalAddColorStop
|
|
1239
|
+
value[PATCHED_ADD_COLOR_STOP_KEY] = wrappedAddColorStop
|
|
1240
|
+
value.addColorStop = wrappedAddColorStop
|
|
355
1241
|
patchedOpaqueObjects.add(value)
|
|
356
|
-
patchedOpaqueObjectRefs.push(
|
|
357
|
-
weakRefFactory ? weakRefFactory(value) : { value: value }
|
|
358
|
-
)
|
|
359
1242
|
} catch (_) {}
|
|
360
1243
|
}
|
|
361
1244
|
|
|
1245
|
+
function dereferencePatchedOpaqueObject(objectRef) {
|
|
1246
|
+
return objectRef && typeof objectRef.deref === 'function'
|
|
1247
|
+
? objectRef.deref()
|
|
1248
|
+
: objectRef && objectRef.value
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function compactPatchedOpaqueObjectRefs() {
|
|
1252
|
+
var retainedRefs = []
|
|
1253
|
+
for (var index = 0; index < patchedOpaqueObjectRefs.length; index += 1) {
|
|
1254
|
+
var objectRef = patchedOpaqueObjectRefs[index]
|
|
1255
|
+
if (dereferencePatchedOpaqueObject(objectRef)) {
|
|
1256
|
+
retainedRefs.push(objectRef)
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
patchedOpaqueObjectRefs = retainedRefs
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
function addPatchedOpaqueObjectRef(objectRef) {
|
|
1263
|
+
patchedOpaqueObjectRefAddCount += 1
|
|
1264
|
+
if (
|
|
1265
|
+
weakRefFactory &&
|
|
1266
|
+
patchedOpaqueObjectRefs.length >=
|
|
1267
|
+
MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS &&
|
|
1268
|
+
(patchedOpaqueObjectRefLastCompactionCount === 0 ||
|
|
1269
|
+
patchedOpaqueObjectRefAddCount -
|
|
1270
|
+
patchedOpaqueObjectRefLastCompactionCount >=
|
|
1271
|
+
Math.max(
|
|
1272
|
+
Math.floor(
|
|
1273
|
+
MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS / 4
|
|
1274
|
+
),
|
|
1275
|
+
1
|
|
1276
|
+
))
|
|
1277
|
+
) {
|
|
1278
|
+
compactPatchedOpaqueObjectRefs()
|
|
1279
|
+
patchedOpaqueObjectRefLastCompactionCount =
|
|
1280
|
+
patchedOpaqueObjectRefAddCount
|
|
1281
|
+
}
|
|
1282
|
+
if (
|
|
1283
|
+
patchedOpaqueObjectRefs.length <
|
|
1284
|
+
MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS
|
|
1285
|
+
) {
|
|
1286
|
+
patchedOpaqueObjectRefs.push(objectRef)
|
|
1287
|
+
return true
|
|
1288
|
+
}
|
|
1289
|
+
// Never evict a live restore record: doing so would leave an SDK wrapper
|
|
1290
|
+
// (and its recorder closure) installed after stop(). A gradient that
|
|
1291
|
+
// cannot get a bounded restore record remains native; assigning it to a
|
|
1292
|
+
// style still switches the owning context to snapshot fallback.
|
|
1293
|
+
return false
|
|
1294
|
+
}
|
|
1295
|
+
|
|
362
1296
|
function restorePatchedOpaqueObjects() {
|
|
363
1297
|
while (patchedOpaqueObjectRefs.length) {
|
|
364
1298
|
var objectRef = patchedOpaqueObjectRefs.pop()
|
|
365
|
-
var object = objectRef
|
|
366
|
-
? objectRef.deref()
|
|
367
|
-
: objectRef && objectRef.value
|
|
1299
|
+
var object = dereferencePatchedOpaqueObject(objectRef)
|
|
368
1300
|
if (
|
|
369
1301
|
object &&
|
|
370
1302
|
object[PATCHED_ADD_COLOR_STOP_KEY] &&
|
|
371
1303
|
typeof object[ORIGINAL_ADD_COLOR_STOP_KEY] === 'function'
|
|
372
1304
|
) {
|
|
373
|
-
|
|
1305
|
+
if (
|
|
1306
|
+
object.addColorStop === object[PATCHED_ADD_COLOR_STOP_KEY]
|
|
1307
|
+
) {
|
|
1308
|
+
object.addColorStop = object[ORIGINAL_ADD_COLOR_STOP_KEY]
|
|
1309
|
+
}
|
|
374
1310
|
delete object[ORIGINAL_ADD_COLOR_STOP_KEY]
|
|
375
1311
|
delete object[PATCHED_ADD_COLOR_STOP_KEY]
|
|
376
1312
|
}
|
|
377
1313
|
}
|
|
378
1314
|
}
|
|
379
1315
|
|
|
380
|
-
function patchMethodOnTarget(
|
|
1316
|
+
function patchMethodOnTarget(
|
|
1317
|
+
target,
|
|
1318
|
+
methodName,
|
|
1319
|
+
restoreFns,
|
|
1320
|
+
alwaysSnapshotFallback
|
|
1321
|
+
) {
|
|
381
1322
|
if (typeof target[methodName] !== 'function') {
|
|
382
|
-
return
|
|
1323
|
+
return false
|
|
383
1324
|
}
|
|
384
1325
|
var originalMethod = target[methodName]
|
|
385
|
-
|
|
1326
|
+
var wrappedMethod = function () {
|
|
386
1327
|
maybeTrackContext(this)
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1328
|
+
var shouldCapture = shouldCaptureContext(this)
|
|
1329
|
+
var result = originalMethod.apply(this, arguments)
|
|
1330
|
+
if (shouldCapture) {
|
|
1331
|
+
notifyContextMutation(this)
|
|
1332
|
+
}
|
|
1333
|
+
if (shouldCapture && alwaysSnapshotFallback) {
|
|
1334
|
+
try {
|
|
1335
|
+
if (isSnapshotFallbackContext(this)) {
|
|
1336
|
+
markSnapshotFallbackDirty(this)
|
|
1337
|
+
} else {
|
|
1338
|
+
enableSnapshotFallbackForContext(
|
|
1339
|
+
this,
|
|
1340
|
+
'unsupported_canvas_method',
|
|
1341
|
+
false,
|
|
1342
|
+
true
|
|
1343
|
+
)
|
|
1344
|
+
}
|
|
1345
|
+
} catch (_) {}
|
|
1346
|
+
return result
|
|
1347
|
+
}
|
|
1348
|
+
if (shouldCapture && isSnapshotFallbackContext(this)) {
|
|
1349
|
+
try {
|
|
1350
|
+
markSnapshotFallbackDirty(this)
|
|
1351
|
+
} catch (_) {}
|
|
1352
|
+
return result
|
|
1353
|
+
}
|
|
1354
|
+
if (shouldCapture) {
|
|
404
1355
|
try {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
1356
|
+
var drawImageFallbackReason =
|
|
1357
|
+
methodName === 'drawImage'
|
|
1358
|
+
? isUnsupportedDrawImageSource(arguments[0])
|
|
1359
|
+
: undefined
|
|
1360
|
+
if (drawImageFallbackReason) {
|
|
1361
|
+
enableSnapshotFallbackForContext(
|
|
1362
|
+
this,
|
|
1363
|
+
drawImageFallbackReason
|
|
1364
|
+
)
|
|
1365
|
+
} else {
|
|
1366
|
+
captureCommand(this, methodName, arguments, false)
|
|
1367
|
+
}
|
|
1368
|
+
} catch (_) {
|
|
1369
|
+
try {
|
|
1370
|
+
enableSnapshotFallbackForContext(
|
|
1371
|
+
this,
|
|
1372
|
+
'command_serialization_error'
|
|
1373
|
+
)
|
|
1374
|
+
} catch (_) {}
|
|
408
1375
|
}
|
|
409
|
-
enqueueCommand(this, {
|
|
410
|
-
property: methodName,
|
|
411
|
-
args: serializedArgs
|
|
412
|
-
})
|
|
413
1376
|
}
|
|
414
|
-
var result = originalMethod.apply(this, arguments)
|
|
415
1377
|
if (
|
|
416
|
-
|
|
1378
|
+
shouldCapture &&
|
|
417
1379
|
(methodName === 'createLinearGradient' ||
|
|
418
1380
|
methodName === 'createRadialGradient' ||
|
|
419
1381
|
methodName === 'createConicGradient')
|
|
@@ -422,74 +1384,203 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
422
1384
|
}
|
|
423
1385
|
return result
|
|
424
1386
|
}
|
|
1387
|
+
try {
|
|
1388
|
+
target[methodName] = wrappedMethod
|
|
1389
|
+
} catch (_) {
|
|
1390
|
+
return false
|
|
1391
|
+
}
|
|
1392
|
+
if (target[methodName] !== wrappedMethod) {
|
|
1393
|
+
return false
|
|
1394
|
+
}
|
|
425
1395
|
restoreFns.push(function () {
|
|
426
|
-
target[methodName]
|
|
1396
|
+
if (target[methodName] === wrappedMethod) {
|
|
1397
|
+
target[methodName] = originalMethod
|
|
1398
|
+
}
|
|
427
1399
|
})
|
|
1400
|
+
return true
|
|
428
1401
|
}
|
|
429
1402
|
|
|
430
|
-
function patchPropertyOnTarget(
|
|
1403
|
+
function patchPropertyOnTarget(
|
|
1404
|
+
target,
|
|
1405
|
+
propertyName,
|
|
1406
|
+
restoreFns,
|
|
1407
|
+
alwaysSnapshotFallback
|
|
1408
|
+
) {
|
|
431
1409
|
if (!canPatchProperty(target, propertyName)) {
|
|
432
|
-
return
|
|
1410
|
+
return false
|
|
433
1411
|
}
|
|
434
1412
|
var originalDescriptor = getPropertyDescriptor(target, propertyName)
|
|
435
1413
|
var fallbackValues = new WeakMap()
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
1414
|
+
var wrappedGetter = function () {
|
|
1415
|
+
if (originalDescriptor && originalDescriptor.get) {
|
|
1416
|
+
return originalDescriptor.get.call(this)
|
|
1417
|
+
}
|
|
1418
|
+
return fallbackValues.get(this)
|
|
1419
|
+
}
|
|
1420
|
+
var wrappedSetter = function (value) {
|
|
1421
|
+
maybeTrackContext(this)
|
|
1422
|
+
fallbackValues.set(this, value)
|
|
1423
|
+
if (originalDescriptor && originalDescriptor.set) {
|
|
1424
|
+
originalDescriptor.set.call(this, value)
|
|
1425
|
+
}
|
|
1426
|
+
var shouldCapture = shouldCaptureContext(this)
|
|
1427
|
+
if (shouldCapture) {
|
|
1428
|
+
notifyContextMutation(this)
|
|
1429
|
+
if (alwaysSnapshotFallback) {
|
|
1430
|
+
try {
|
|
1431
|
+
if (isSnapshotFallbackContext(this)) {
|
|
1432
|
+
markSnapshotFallbackDirty(this)
|
|
1433
|
+
} else {
|
|
1434
|
+
enableSnapshotFallbackForContext(
|
|
1435
|
+
this,
|
|
1436
|
+
'unsupported_canvas_property',
|
|
1437
|
+
false,
|
|
1438
|
+
true
|
|
1439
|
+
)
|
|
1440
|
+
}
|
|
1441
|
+
} catch (_) {}
|
|
1442
|
+
return
|
|
442
1443
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (originalDescriptor && originalDescriptor.set) {
|
|
449
|
-
originalDescriptor.set.call(this, value)
|
|
1444
|
+
if (isSnapshotFallbackContext(this)) {
|
|
1445
|
+
try {
|
|
1446
|
+
markSnapshotFallbackDirty(this)
|
|
1447
|
+
} catch (_) {}
|
|
1448
|
+
return
|
|
450
1449
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
setter: true
|
|
461
|
-
})
|
|
1450
|
+
try {
|
|
1451
|
+
captureCommand(this, propertyName, [value], true)
|
|
1452
|
+
} catch (_) {
|
|
1453
|
+
try {
|
|
1454
|
+
enableSnapshotFallbackForContext(
|
|
1455
|
+
this,
|
|
1456
|
+
'command_serialization_error'
|
|
1457
|
+
)
|
|
1458
|
+
} catch (_) {}
|
|
462
1459
|
}
|
|
463
1460
|
}
|
|
464
|
-
}
|
|
1461
|
+
}
|
|
1462
|
+
try {
|
|
1463
|
+
Object.defineProperty(target, propertyName, {
|
|
1464
|
+
configurable: true,
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
get: wrappedGetter,
|
|
1467
|
+
set: wrappedSetter
|
|
1468
|
+
})
|
|
1469
|
+
} catch (_) {
|
|
1470
|
+
return false
|
|
1471
|
+
}
|
|
465
1472
|
restoreFns.push(function () {
|
|
1473
|
+
var currentDescriptor = Object.getOwnPropertyDescriptor(
|
|
1474
|
+
target,
|
|
1475
|
+
propertyName
|
|
1476
|
+
)
|
|
1477
|
+
if (
|
|
1478
|
+
!currentDescriptor ||
|
|
1479
|
+
currentDescriptor.get !== wrappedGetter ||
|
|
1480
|
+
currentDescriptor.set !== wrappedSetter
|
|
1481
|
+
) {
|
|
1482
|
+
return
|
|
1483
|
+
}
|
|
466
1484
|
if (originalDescriptor) {
|
|
467
1485
|
Object.defineProperty(target, propertyName, originalDescriptor)
|
|
468
1486
|
} else {
|
|
469
1487
|
delete target[propertyName]
|
|
470
1488
|
}
|
|
471
1489
|
})
|
|
1490
|
+
return true
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function patchUnknownMutationsOnTarget(target, restoreFns) {
|
|
1494
|
+
var propertyNames
|
|
1495
|
+
try {
|
|
1496
|
+
propertyNames = Object.getOwnPropertyNames(target)
|
|
1497
|
+
} catch (_) {
|
|
1498
|
+
snapshotFallbackPatchTargets.add(target)
|
|
1499
|
+
return
|
|
1500
|
+
}
|
|
1501
|
+
propertyNames.forEach(function (propertyName) {
|
|
1502
|
+
if (
|
|
1503
|
+
propertyName === 'constructor' ||
|
|
1504
|
+
CANVAS_2D_CAPTURED_METHOD_NAMES[propertyName] ||
|
|
1505
|
+
CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] ||
|
|
1506
|
+
CANVAS_2D_NON_MUTATING_METHODS[propertyName]
|
|
1507
|
+
) {
|
|
1508
|
+
return
|
|
1509
|
+
}
|
|
1510
|
+
var descriptor
|
|
1511
|
+
try {
|
|
1512
|
+
descriptor = Object.getOwnPropertyDescriptor(
|
|
1513
|
+
target,
|
|
1514
|
+
propertyName
|
|
1515
|
+
)
|
|
1516
|
+
} catch (_) {
|
|
1517
|
+
snapshotFallbackPatchTargets.add(target)
|
|
1518
|
+
return
|
|
1519
|
+
}
|
|
1520
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
1521
|
+
if (
|
|
1522
|
+
!patchMethodOnTarget(
|
|
1523
|
+
target,
|
|
1524
|
+
propertyName,
|
|
1525
|
+
restoreFns,
|
|
1526
|
+
true
|
|
1527
|
+
)
|
|
1528
|
+
) {
|
|
1529
|
+
snapshotFallbackPatchTargets.add(target)
|
|
1530
|
+
}
|
|
1531
|
+
return
|
|
1532
|
+
}
|
|
1533
|
+
if (
|
|
1534
|
+
descriptor &&
|
|
1535
|
+
typeof descriptor.set === 'function' &&
|
|
1536
|
+
!patchPropertyOnTarget(
|
|
1537
|
+
target,
|
|
1538
|
+
propertyName,
|
|
1539
|
+
restoreFns,
|
|
1540
|
+
true
|
|
1541
|
+
)
|
|
1542
|
+
) {
|
|
1543
|
+
snapshotFallbackPatchTargets.add(target)
|
|
1544
|
+
}
|
|
1545
|
+
})
|
|
472
1546
|
}
|
|
473
1547
|
|
|
474
1548
|
function patchPrototype(context) {
|
|
475
1549
|
var prototype = Object.getPrototypeOf(context)
|
|
476
1550
|
if (!prototype || prototype === Object.prototype) {
|
|
477
|
-
return
|
|
1551
|
+
return false
|
|
478
1552
|
}
|
|
479
1553
|
var existingRecord = patchedPrototypeRecords.find(function (record) {
|
|
480
1554
|
return record.prototype === prototype
|
|
481
1555
|
})
|
|
482
1556
|
if (existingRecord) {
|
|
483
|
-
return
|
|
1557
|
+
return true
|
|
1558
|
+
}
|
|
1559
|
+
if (
|
|
1560
|
+
patchedPrototypeRecords.length >=
|
|
1561
|
+
MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS
|
|
1562
|
+
) {
|
|
1563
|
+
return false
|
|
484
1564
|
}
|
|
485
1565
|
|
|
486
1566
|
var restoreFns = []
|
|
487
1567
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
488
|
-
|
|
1568
|
+
if (
|
|
1569
|
+
typeof prototype[methodName] === 'function' &&
|
|
1570
|
+
!patchMethodOnTarget(prototype, methodName, restoreFns)
|
|
1571
|
+
) {
|
|
1572
|
+
snapshotFallbackPatchTargets.add(prototype)
|
|
1573
|
+
}
|
|
489
1574
|
})
|
|
490
1575
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
491
|
-
|
|
1576
|
+
if (
|
|
1577
|
+
getPropertyDescriptor(prototype, propertyName) &&
|
|
1578
|
+
!patchPropertyOnTarget(prototype, propertyName, restoreFns)
|
|
1579
|
+
) {
|
|
1580
|
+
snapshotFallbackPatchTargets.add(prototype)
|
|
1581
|
+
}
|
|
492
1582
|
})
|
|
1583
|
+
patchUnknownMutationsOnTarget(prototype, restoreFns)
|
|
493
1584
|
|
|
494
1585
|
patchedPrototypeRecords.push({
|
|
495
1586
|
prototype: prototype,
|
|
@@ -499,26 +1590,44 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
499
1590
|
}
|
|
500
1591
|
}
|
|
501
1592
|
})
|
|
1593
|
+
return true
|
|
502
1594
|
}
|
|
503
1595
|
|
|
504
1596
|
function patchSharedPrototype(prototype) {
|
|
505
1597
|
if (!prototype || prototype === Object.prototype) {
|
|
506
|
-
return
|
|
1598
|
+
return false
|
|
507
1599
|
}
|
|
508
1600
|
var existingRecord = patchedPrototypeRecords.find(function (record) {
|
|
509
1601
|
return record.prototype === prototype
|
|
510
1602
|
})
|
|
511
1603
|
if (existingRecord) {
|
|
512
|
-
return
|
|
1604
|
+
return true
|
|
1605
|
+
}
|
|
1606
|
+
if (
|
|
1607
|
+
patchedPrototypeRecords.length >=
|
|
1608
|
+
MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS
|
|
1609
|
+
) {
|
|
1610
|
+
return false
|
|
513
1611
|
}
|
|
514
1612
|
|
|
515
1613
|
var restoreFns = []
|
|
516
1614
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
517
|
-
|
|
1615
|
+
if (
|
|
1616
|
+
typeof prototype[methodName] === 'function' &&
|
|
1617
|
+
!patchMethodOnTarget(prototype, methodName, restoreFns)
|
|
1618
|
+
) {
|
|
1619
|
+
snapshotFallbackPatchTargets.add(prototype)
|
|
1620
|
+
}
|
|
518
1621
|
})
|
|
519
1622
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
520
|
-
|
|
1623
|
+
if (
|
|
1624
|
+
getPropertyDescriptor(prototype, propertyName) &&
|
|
1625
|
+
!patchPropertyOnTarget(prototype, propertyName, restoreFns)
|
|
1626
|
+
) {
|
|
1627
|
+
snapshotFallbackPatchTargets.add(prototype)
|
|
1628
|
+
}
|
|
521
1629
|
})
|
|
1630
|
+
patchUnknownMutationsOnTarget(prototype, restoreFns)
|
|
522
1631
|
|
|
523
1632
|
patchedPrototypeRecords.push({
|
|
524
1633
|
prototype: prototype,
|
|
@@ -528,34 +1637,68 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
528
1637
|
}
|
|
529
1638
|
}
|
|
530
1639
|
})
|
|
1640
|
+
return true
|
|
531
1641
|
}
|
|
532
1642
|
|
|
533
1643
|
function patchContextInstance(context, restoreFns) {
|
|
534
1644
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
535
|
-
|
|
1645
|
+
if (
|
|
1646
|
+
typeof context[methodName] === 'function' &&
|
|
1647
|
+
!patchMethodOnTarget(context, methodName, restoreFns)
|
|
1648
|
+
) {
|
|
1649
|
+
snapshotFallbackPatchTargets.add(context)
|
|
1650
|
+
}
|
|
536
1651
|
})
|
|
537
1652
|
|
|
538
1653
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
539
|
-
patchPropertyOnTarget(context, propertyName, restoreFns)
|
|
1654
|
+
if (!patchPropertyOnTarget(context, propertyName, restoreFns)) {
|
|
1655
|
+
snapshotFallbackPatchTargets.add(context)
|
|
1656
|
+
}
|
|
540
1657
|
})
|
|
1658
|
+
patchUnknownMutationsOnTarget(context, restoreFns)
|
|
541
1659
|
}
|
|
542
1660
|
|
|
543
1661
|
function patchContext(context) {
|
|
544
|
-
if (!context || context
|
|
1662
|
+
if (stopped || !context || trackedContextSet.has(context)) {
|
|
545
1663
|
return function () {}
|
|
546
1664
|
}
|
|
547
1665
|
|
|
548
1666
|
var restoreFns = []
|
|
549
1667
|
var prototype = Object.getPrototypeOf(context)
|
|
550
1668
|
if (prototype && prototype !== Object.prototype) {
|
|
551
|
-
patchPrototype(context)
|
|
1669
|
+
if (!patchPrototype(context)) {
|
|
1670
|
+
return function () {}
|
|
1671
|
+
}
|
|
552
1672
|
} else {
|
|
553
1673
|
patchContextInstance(context, restoreFns)
|
|
554
1674
|
}
|
|
555
1675
|
|
|
556
|
-
registerTrackedContext(context, restoreFns)
|
|
1676
|
+
if (!registerTrackedContext(context, restoreFns)) {
|
|
1677
|
+
while (restoreFns.length) {
|
|
1678
|
+
restoreFns.pop()()
|
|
1679
|
+
}
|
|
1680
|
+
return function () {}
|
|
1681
|
+
}
|
|
1682
|
+
if (
|
|
1683
|
+
snapshotFallbackPatchTargets.has(context) ||
|
|
1684
|
+
(prototype && snapshotFallbackPatchTargets.has(prototype))
|
|
1685
|
+
) {
|
|
1686
|
+
enableSnapshotFallbackForContext(
|
|
1687
|
+
context,
|
|
1688
|
+
'unpatchable_canvas_api',
|
|
1689
|
+
false,
|
|
1690
|
+
true
|
|
1691
|
+
)
|
|
1692
|
+
}
|
|
557
1693
|
|
|
558
1694
|
return function () {
|
|
1695
|
+
trackedContextSet.delete(context)
|
|
1696
|
+
deletePendingBatch(context)
|
|
1697
|
+
expiredUnpublishedContexts.delete(context)
|
|
1698
|
+
fallbackModeContexts.delete(context)
|
|
1699
|
+
persistentFallbackModeContexts.delete(context)
|
|
1700
|
+
fallbackReasonByContext.delete(context)
|
|
1701
|
+
persistentFallbackReasonByContext.delete(context)
|
|
559
1702
|
var trackedIndex = trackedContexts.findIndex(function (tracked) {
|
|
560
1703
|
return tracked.context === context
|
|
561
1704
|
})
|
|
@@ -571,9 +1714,13 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
571
1714
|
cancelAnimationFrameImpl(scheduledFlushId)
|
|
572
1715
|
scheduledFlushId = undefined
|
|
573
1716
|
}
|
|
574
|
-
|
|
1717
|
+
clearPendingBatches()
|
|
575
1718
|
fallbackModeContexts = new WeakSet()
|
|
1719
|
+
persistentFallbackModeContexts = new WeakSet()
|
|
576
1720
|
fallbackReasonByContext = new WeakMap()
|
|
1721
|
+
persistentFallbackReasonByContext = new WeakMap()
|
|
1722
|
+
expiredUnpublishedContexts = new WeakSet()
|
|
1723
|
+
rejectedContextSet = new WeakSet()
|
|
577
1724
|
opaqueObjectContextMap = new WeakMap()
|
|
578
1725
|
restorePatchedOpaqueObjects()
|
|
579
1726
|
while (trackedContexts.length) {
|
|
@@ -582,6 +1729,9 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
582
1729
|
while (patchedPrototypeRecords.length) {
|
|
583
1730
|
patchedPrototypeRecords.pop().restore()
|
|
584
1731
|
}
|
|
1732
|
+
trackedContextSet = new WeakSet()
|
|
1733
|
+
captureGenerationByContext = new WeakMap()
|
|
1734
|
+
objectRefRegistry.reset()
|
|
585
1735
|
}
|
|
586
1736
|
|
|
587
1737
|
function pause() {
|
|
@@ -590,9 +1740,11 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
590
1740
|
cancelAnimationFrameImpl(scheduledFlushId)
|
|
591
1741
|
scheduledFlushId = undefined
|
|
592
1742
|
}
|
|
593
|
-
|
|
1743
|
+
clearPendingBatches()
|
|
594
1744
|
fallbackModeContexts = new WeakSet()
|
|
595
1745
|
fallbackReasonByContext = new WeakMap()
|
|
1746
|
+
rejectedContextSet = new WeakSet()
|
|
1747
|
+
objectRefRegistry.reset()
|
|
596
1748
|
}
|
|
597
1749
|
|
|
598
1750
|
function resume() {
|
|
@@ -600,19 +1752,61 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
600
1752
|
}
|
|
601
1753
|
|
|
602
1754
|
function reset() {
|
|
1755
|
+
captureGeneration += 1
|
|
603
1756
|
if (scheduledFlushId !== undefined) {
|
|
604
1757
|
cancelAnimationFrameImpl(scheduledFlushId)
|
|
605
1758
|
scheduledFlushId = undefined
|
|
606
1759
|
}
|
|
607
|
-
|
|
1760
|
+
clearPendingBatches()
|
|
608
1761
|
fallbackModeContexts = new WeakSet()
|
|
609
1762
|
fallbackReasonByContext = new WeakMap()
|
|
1763
|
+
rejectedContextSet = new WeakSet()
|
|
1764
|
+
objectRefRegistry.reset()
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
function forceSnapshotFallback(context, reason) {
|
|
1768
|
+
if (stopped || !trackedContextSet.has(context)) {
|
|
1769
|
+
return
|
|
1770
|
+
}
|
|
1771
|
+
// An explicit authoritative rebaseline supersedes the implicit
|
|
1772
|
+
// canvas_state_reset transition for this generation.
|
|
1773
|
+
captureGenerationByContext.set(context, captureGeneration)
|
|
1774
|
+
expiredUnpublishedContexts.delete(context)
|
|
1775
|
+
enableSnapshotFallbackForContext(
|
|
1776
|
+
context,
|
|
1777
|
+
reason || 'forced_snapshot_rebaseline',
|
|
1778
|
+
false,
|
|
1779
|
+
true
|
|
1780
|
+
)
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function markPersistentSnapshotFallback(context, reason) {
|
|
1784
|
+
if (stopped || !trackedContextSet.has(context)) {
|
|
1785
|
+
return
|
|
1786
|
+
}
|
|
1787
|
+
expiredUnpublishedContexts.delete(context)
|
|
1788
|
+
persistentFallbackModeContexts.add(context)
|
|
1789
|
+
if (!persistentFallbackReasonByContext.has(context)) {
|
|
1790
|
+
persistentFallbackReasonByContext.set(
|
|
1791
|
+
context,
|
|
1792
|
+
reason || 'persistent_snapshot_fallback'
|
|
1793
|
+
)
|
|
1794
|
+
}
|
|
1795
|
+
// The authoritative bitmap was already admitted by the caller. Only
|
|
1796
|
+
// retire command state here; requesting another snapshot would duplicate
|
|
1797
|
+
// the initial encode and increase startup work for every canvas.
|
|
1798
|
+
deletePendingBatch(context)
|
|
610
1799
|
}
|
|
611
1800
|
|
|
612
1801
|
return {
|
|
613
1802
|
patchContext: patchContext,
|
|
614
1803
|
patchSharedPrototype: patchSharedPrototype,
|
|
1804
|
+
rejectContext: rejectContext,
|
|
1805
|
+
forceSnapshotFallback: forceSnapshotFallback,
|
|
1806
|
+
markPersistentSnapshotFallback: markPersistentSnapshotFallback,
|
|
615
1807
|
flush: flush,
|
|
1808
|
+
flushContext: flushContext,
|
|
1809
|
+
retryPublishedContext: retryPublishedContext,
|
|
616
1810
|
pause: pause,
|
|
617
1811
|
resume: resume,
|
|
618
1812
|
reset: reset,
|