@cloudcare/browser-rum 3.3.5 → 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 +42 -6
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +190 -195
- 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 +8 -0
- 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 +36 -3
- 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 +38 -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 +20 -2
- package/cjs/domain/contexts/urlContexts.js.map +1 -1
- package/cjs/domain/contexts/viewContexts.js +2 -2
- 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 +67 -0
- package/cjs/domain/plugins.js.map +1 -0
- 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 +56 -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 +196 -0
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- 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 +8 -3
- 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 +31 -12
- 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 +23 -3
- 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 +42 -6
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +192 -197
- 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 +8 -0
- 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 +36 -3
- 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 +39 -44
- 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 +21 -3
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -2
- 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 +59 -0
- package/esm/domain/plugins.js.map +1 -0
- 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 +55 -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 +189 -0
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- 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 +8 -3
- 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 +32 -13
- 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 +24 -4
- 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/perStartRum.js +47 -7
- package/src/boot/recorderApi.js +271 -220
- package/src/boot/recorderApiStub.js +3 -29
- package/src/boot/rum.js +11 -0
- package/src/boot/rumPublicApi.js +38 -3
- 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 +76 -101
- package/src/domain/contexts/urlContexts.js +29 -3
- package/src/domain/contexts/viewContexts.js +2 -2
- package/src/domain/deflate/deflateEncoder.js +699 -43
- package/src/domain/deflate/deflateWorker.js +237 -136
- package/src/domain/plugins.js +94 -0
- 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 +70 -0
- package/src/domain/rumEventsCollection/resource/webSocketCollection.js +271 -0
- package/src/domain/rumEventsCollection/view/trackLoadingTime.js +12 -3
- package/src/domain/rumEventsCollection/view/trackViews.js +38 -13
- package/src/domain/rumSessionManager.js +33 -2
- package/src/domain/tracing/tracer.js +4 -5
- package/src/transport/startRumBatch.js +6 -1
- package/types/index.d.ts +100 -8
- 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,13 +1,42 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import {
|
|
2
|
+
import { createCanvasCommandObjectRefRegistry } from './canvasCommandSerializeArgs';
|
|
3
3
|
import { createCanvasMutationRecord } from './canvasMutationRecord';
|
|
4
|
-
var CANVAS_2D_CAPTURED_METHODS = ['save', 'restore', 'translate', 'scale', 'rotate', 'transform', 'setTransform', 'createLinearGradient', 'createRadialGradient', 'createPattern', 'createConicGradient', 'clearRect', 'fillRect', 'strokeRect', 'rect', 'beginPath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'closePath', 'arc', 'ellipse', 'roundRect', 'clip', 'fill', 'stroke', 'fillText', 'strokeText', 'setLineDash', 'drawImage'];
|
|
5
|
-
var CANVAS_2D_CAPTURED_PROPERTIES = ['fillStyle', 'strokeStyle', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'font', 'globalAlpha', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textAlign', 'textBaseline', 'filter'];
|
|
4
|
+
var CANVAS_2D_CAPTURED_METHODS = ['save', 'restore', 'translate', 'scale', 'rotate', 'transform', 'setTransform', 'resetTransform', 'reset', 'createLinearGradient', 'createRadialGradient', 'createPattern', 'createConicGradient', 'clearRect', 'fillRect', 'strokeRect', 'rect', 'beginPath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'arcTo', 'closePath', 'arc', 'ellipse', 'roundRect', 'clip', 'fill', 'stroke', 'fillText', 'strokeText', 'setLineDash', 'putImageData', 'drawImage'];
|
|
5
|
+
var CANVAS_2D_CAPTURED_PROPERTIES = ['fillStyle', 'strokeStyle', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'lineDashOffset', 'font', 'globalAlpha', 'globalCompositeOperation', 'imageSmoothingEnabled', 'imageSmoothingQuality', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textAlign', 'textBaseline', 'direction', 'fontKerning', 'fontStretch', 'fontVariantCaps', 'letterSpacing', 'textRendering', 'wordSpacing', 'filter'];
|
|
6
|
+
var CANVAS_2D_NON_MUTATING_METHODS = {
|
|
7
|
+
createImageData: true,
|
|
8
|
+
getContextAttributes: true,
|
|
9
|
+
getImageData: true,
|
|
10
|
+
getLineDash: true,
|
|
11
|
+
getTransform: true,
|
|
12
|
+
isContextLost: true,
|
|
13
|
+
isPointInPath: true,
|
|
14
|
+
isPointInStroke: true,
|
|
15
|
+
measureText: true
|
|
16
|
+
};
|
|
17
|
+
var CANVAS_2D_CAPTURED_METHOD_NAMES = {};
|
|
18
|
+
var CANVAS_2D_CAPTURED_PROPERTY_NAMES = {};
|
|
19
|
+
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
20
|
+
CANVAS_2D_CAPTURED_METHOD_NAMES[methodName] = true;
|
|
21
|
+
});
|
|
22
|
+
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
23
|
+
CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] = true;
|
|
24
|
+
});
|
|
6
25
|
var UNSUPPORTED_REPLAY_OBJECT_NAMES = {
|
|
7
26
|
CanvasGradient: true,
|
|
8
27
|
CanvasPattern: true,
|
|
9
28
|
Path2D: true
|
|
10
29
|
};
|
|
30
|
+
export var MAX_CANVAS_COMMANDS_PER_BATCH = 1000;
|
|
31
|
+
export var MAX_CANVAS_COMMAND_BATCH_BYTES = 128 * 1024;
|
|
32
|
+
export var MAX_PENDING_CANVAS_COMMAND_CONTEXTS = 64;
|
|
33
|
+
export var MAX_PENDING_CANVAS_COMMAND_BYTES = 512 * 1024;
|
|
34
|
+
export var MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS = 1000;
|
|
35
|
+
export var MAX_STRONG_CANVAS_CONTEXT_RESTORE_RECORDS = 64;
|
|
36
|
+
export var MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS = 256;
|
|
37
|
+
var MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS = 16;
|
|
38
|
+
var CANVAS_COMMAND_BASE_APPROX_BYTES = 32;
|
|
39
|
+
var CANVAS_COMMAND_SETTER_APPROX_BYTES = 14;
|
|
11
40
|
var ORIGINAL_ADD_COLOR_STOP_KEY = '__dd_original_addColorStop__';
|
|
12
41
|
var PATCHED_ADD_COLOR_STOP_KEY = '__dd_patched_addColorStop__';
|
|
13
42
|
function canPatchProperty(target, property) {
|
|
@@ -30,20 +59,7 @@ function getCanvasObjectConstructorName(value) {
|
|
|
30
59
|
}
|
|
31
60
|
return value.constructor.name || 'Object';
|
|
32
61
|
}
|
|
33
|
-
function
|
|
34
|
-
if (Array.isArray(value)) {
|
|
35
|
-
for (var index = 0; index < value.length; index += 1) {
|
|
36
|
-
var nestedReason = getFallbackReasonForValue(value[index]);
|
|
37
|
-
if (nestedReason) {
|
|
38
|
-
return nestedReason;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var constructorName = getCanvasObjectConstructorName(value);
|
|
44
|
-
if (!constructorName || !UNSUPPORTED_REPLAY_OBJECT_NAMES[constructorName]) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
62
|
+
function getFallbackReasonForConstructorName(constructorName) {
|
|
47
63
|
if (constructorName === 'CanvasGradient') {
|
|
48
64
|
return 'gradient_style_assignment';
|
|
49
65
|
}
|
|
@@ -55,6 +71,224 @@ function getFallbackReasonForValue(value) {
|
|
|
55
71
|
}
|
|
56
72
|
return 'unsupported_canvas_object';
|
|
57
73
|
}
|
|
74
|
+
function addApproxBytes(state, bytes) {
|
|
75
|
+
if (!isFinite(bytes) || bytes < 0 || bytes > state.limit - state.bytes) {
|
|
76
|
+
state.overflow = true;
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
state.bytes += bytes;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
function addStringApproxBytes(state, value) {
|
|
83
|
+
if (!addApproxBytes(state, 2)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (var index = 0; index < value.length && !state.overflow; index += 1) {
|
|
87
|
+
var code = value.charCodeAt(index);
|
|
88
|
+
if (code === 0x22 || code === 0x5c) {
|
|
89
|
+
addApproxBytes(state, 2);
|
|
90
|
+
} else if (code <= 0x1f) {
|
|
91
|
+
addApproxBytes(state, 6);
|
|
92
|
+
} else if (code <= 0x7f) {
|
|
93
|
+
addApproxBytes(state, 1);
|
|
94
|
+
} else if (code <= 0x7ff) {
|
|
95
|
+
addApproxBytes(state, 2);
|
|
96
|
+
} else if (code >= 0xd800 && code <= 0xdbff) {
|
|
97
|
+
var nextCode = value.charCodeAt(index + 1);
|
|
98
|
+
if (nextCode >= 0xdc00 && nextCode <= 0xdfff) {
|
|
99
|
+
index += 1;
|
|
100
|
+
addApproxBytes(state, 4);
|
|
101
|
+
} else {
|
|
102
|
+
addApproxBytes(state, 6);
|
|
103
|
+
}
|
|
104
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
105
|
+
addApproxBytes(state, 6);
|
|
106
|
+
} else {
|
|
107
|
+
addApproxBytes(state, 3);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function addPrimitiveApproxBytes(state, value) {
|
|
112
|
+
if (value === null || value === undefined) {
|
|
113
|
+
addApproxBytes(state, 4);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (typeof value === 'string') {
|
|
117
|
+
addStringApproxBytes(state, value);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
if (typeof value === 'number') {
|
|
121
|
+
addApproxBytes(state, isFinite(value) ? String(value).length : 4);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === 'boolean') {
|
|
125
|
+
addApproxBytes(state, value ? 4 : 5);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (typeof value === 'function' || _typeof(value) === 'symbol') {
|
|
129
|
+
addApproxBytes(state, 4);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (typeof value === 'bigint') {
|
|
133
|
+
throw new Error('Unsupported canvas command bigint argument');
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
function getTypedArrayElementApproxBytes(value) {
|
|
138
|
+
var constructorName = getCanvasObjectConstructorName(value);
|
|
139
|
+
if (constructorName === 'Uint8Array' || constructorName === 'Uint8ClampedArray') {
|
|
140
|
+
return 4;
|
|
141
|
+
}
|
|
142
|
+
if (constructorName === 'Int8Array') {
|
|
143
|
+
return 5;
|
|
144
|
+
}
|
|
145
|
+
if (constructorName === 'Uint16Array') {
|
|
146
|
+
return 6;
|
|
147
|
+
}
|
|
148
|
+
if (constructorName === 'Int16Array') {
|
|
149
|
+
return 7;
|
|
150
|
+
}
|
|
151
|
+
if (constructorName === 'Uint32Array') {
|
|
152
|
+
return 11;
|
|
153
|
+
}
|
|
154
|
+
if (constructorName === 'Int32Array') {
|
|
155
|
+
return 12;
|
|
156
|
+
}
|
|
157
|
+
return 25;
|
|
158
|
+
}
|
|
159
|
+
function isSerializedTypedArray(value) {
|
|
160
|
+
return value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Uint8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Int8Array || value instanceof Uint8ClampedArray;
|
|
161
|
+
}
|
|
162
|
+
function addTypedArrayApproxBytes(state, value) {
|
|
163
|
+
var elementCount = value.length;
|
|
164
|
+
var perElementBytes = getTypedArrayElementApproxBytes(value);
|
|
165
|
+
addApproxBytes(state, 32 + (elementCount ? elementCount * perElementBytes + elementCount - 1 : 0));
|
|
166
|
+
}
|
|
167
|
+
function addArrayBufferApproxBytes(state, buffer) {
|
|
168
|
+
addApproxBytes(state, 36 + Math.ceil(buffer.byteLength / 3) * 4);
|
|
169
|
+
}
|
|
170
|
+
function estimateCanvasCommand(property, args, setter, limit) {
|
|
171
|
+
var state = {
|
|
172
|
+
bytes: 0,
|
|
173
|
+
fallbackReason: undefined,
|
|
174
|
+
limit: limit,
|
|
175
|
+
overflow: false
|
|
176
|
+
};
|
|
177
|
+
addApproxBytes(state, CANVAS_COMMAND_BASE_APPROX_BYTES + (setter ? CANVAS_COMMAND_SETTER_APPROX_BYTES : 0));
|
|
178
|
+
addStringApproxBytes(state, property);
|
|
179
|
+
if (state.overflow) {
|
|
180
|
+
return state;
|
|
181
|
+
}
|
|
182
|
+
var argCount = args.length;
|
|
183
|
+
var minimumArgsBytes = 2 + (argCount ? argCount - 1 + argCount : 0);
|
|
184
|
+
if (minimumArgsBytes > state.limit - state.bytes) {
|
|
185
|
+
state.overflow = true;
|
|
186
|
+
return state;
|
|
187
|
+
}
|
|
188
|
+
addApproxBytes(state, 2 + (argCount ? argCount - 1 : 0));
|
|
189
|
+
var firstComplexArgIndex = argCount;
|
|
190
|
+
for (var primitiveArgIndex = 0; primitiveArgIndex < argCount && !state.overflow; primitiveArgIndex += 1) {
|
|
191
|
+
if (!addPrimitiveApproxBytes(state, args[primitiveArgIndex])) {
|
|
192
|
+
firstComplexArgIndex = primitiveArgIndex;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (state.overflow || firstComplexArgIndex === argCount) {
|
|
197
|
+
return state;
|
|
198
|
+
}
|
|
199
|
+
var seenArrays;
|
|
200
|
+
var stack = [];
|
|
201
|
+
for (var argIndex = argCount - 1; argIndex >= firstComplexArgIndex; argIndex -= 1) {
|
|
202
|
+
stack.push({
|
|
203
|
+
type: 'value',
|
|
204
|
+
value: args[argIndex]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
while (stack.length && !state.overflow && !state.fallbackReason) {
|
|
208
|
+
var task = stack.pop();
|
|
209
|
+
if (task.type === 'array') {
|
|
210
|
+
if (task.index >= task.value.length) {
|
|
211
|
+
if (seenArrays) {
|
|
212
|
+
seenArrays["delete"](task.value);
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
var arrayIndex = task.index;
|
|
217
|
+
task.index += 1;
|
|
218
|
+
stack.push(task);
|
|
219
|
+
stack.push({
|
|
220
|
+
type: 'value',
|
|
221
|
+
value: arrayIndex in task.value ? task.value[arrayIndex] : undefined
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
var value = task.value;
|
|
226
|
+
if (addPrimitiveApproxBytes(state, value)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (Array.isArray(value)) {
|
|
230
|
+
if (seenArrays && seenArrays.has(value)) {
|
|
231
|
+
throw new Error('Circular canvas command argument');
|
|
232
|
+
}
|
|
233
|
+
var arrayLength = value.length;
|
|
234
|
+
var minimumArrayBytes = 2 + (arrayLength ? arrayLength - 1 + arrayLength : 0);
|
|
235
|
+
if (minimumArrayBytes > state.limit - state.bytes) {
|
|
236
|
+
state.overflow = true;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
addApproxBytes(state, 2 + (arrayLength ? arrayLength - 1 : 0));
|
|
240
|
+
if (!seenArrays) {
|
|
241
|
+
seenArrays = new WeakSet();
|
|
242
|
+
}
|
|
243
|
+
seenArrays.add(value);
|
|
244
|
+
stack.push({
|
|
245
|
+
type: 'array',
|
|
246
|
+
value: value,
|
|
247
|
+
index: 0
|
|
248
|
+
});
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (typeof HTMLCanvasElement !== 'undefined' && value instanceof HTMLCanvasElement) {
|
|
252
|
+
state.fallbackReason = 'canvas_element_argument';
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
var constructorName = getCanvasObjectConstructorName(value);
|
|
256
|
+
if (constructorName && UNSUPPORTED_REPLAY_OBJECT_NAMES[constructorName]) {
|
|
257
|
+
state.fallbackReason = getFallbackReasonForConstructorName(constructorName);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
if (isSerializedTypedArray(value)) {
|
|
261
|
+
addTypedArrayApproxBytes(state, value);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (value instanceof ArrayBuffer) {
|
|
265
|
+
addArrayBufferApproxBytes(state, value);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (value instanceof DataView) {
|
|
269
|
+
addArrayBufferApproxBytes(state, value.buffer);
|
|
270
|
+
addApproxBytes(state, 32);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (typeof ImageData !== 'undefined' && value instanceof ImageData) {
|
|
274
|
+
addTypedArrayApproxBytes(state, value.data);
|
|
275
|
+
addApproxBytes(state, 32);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (typeof HTMLImageElement !== 'undefined' && value instanceof HTMLImageElement) {
|
|
279
|
+
addApproxBytes(state, 36);
|
|
280
|
+
addStringApproxBytes(state, value.currentSrc || value.src || '');
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// rrweb can only resolve object references that were produced by a
|
|
285
|
+
// previous replayed canvas command. Arbitrary platform objects such as
|
|
286
|
+
// DOMMatrix, ImageBitmap or VideoFrame would otherwise become dangling
|
|
287
|
+
// { rr_type, index } references and change the replayed draw semantics.
|
|
288
|
+
state.fallbackReason = 'unsupported_canvas_object';
|
|
289
|
+
}
|
|
290
|
+
return state;
|
|
291
|
+
}
|
|
58
292
|
function isCrossOriginImageElement(value) {
|
|
59
293
|
if (typeof HTMLImageElement === 'undefined' || !(value instanceof HTMLImageElement)) {
|
|
60
294
|
return false;
|
|
@@ -73,41 +307,70 @@ function isCrossOriginImageElement(value) {
|
|
|
73
307
|
}
|
|
74
308
|
}
|
|
75
309
|
function isUnsupportedDrawImageSource(value) {
|
|
310
|
+
if (typeof HTMLImageElement !== 'undefined' && value instanceof HTMLImageElement) {
|
|
311
|
+
var imageSource = value.currentSrc || value.src || '';
|
|
312
|
+
if (imageSource.indexOf('blob:') === 0 || imageSource.indexOf('filesystem:') === 0) {
|
|
313
|
+
return 'draw_image_unsupported_source';
|
|
314
|
+
}
|
|
315
|
+
return isCrossOriginImageElement(value) ? 'draw_image_cross_origin' : undefined;
|
|
316
|
+
}
|
|
76
317
|
if (typeof HTMLCanvasElement !== 'undefined' && value instanceof HTMLCanvasElement) {
|
|
77
318
|
return 'draw_image_canvas';
|
|
78
319
|
}
|
|
79
320
|
if (typeof HTMLVideoElement !== 'undefined' && value instanceof HTMLVideoElement) {
|
|
80
321
|
return 'draw_image_video';
|
|
81
322
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
323
|
+
// HTMLImageElement is the only CanvasImageSource that the replay player can
|
|
324
|
+
// recreate independently. ImageBitmap, OffscreenCanvas, VideoFrame and SVG
|
|
325
|
+
// image sources would otherwise be serialized as object references without
|
|
326
|
+
// a matching producer command and replay as drawImage(undefined, ...).
|
|
327
|
+
return 'draw_image_unsupported_source';
|
|
85
328
|
}
|
|
86
329
|
export function createCanvas2DCommandRecorder(options) {
|
|
87
330
|
options = options || {};
|
|
88
331
|
var emit = options.emit || function () {};
|
|
89
|
-
var now = options.now || Date.now;
|
|
90
|
-
var requestAnimationFrameImpl = options.requestAnimationFrameImpl || function (callback) {
|
|
332
|
+
var now = false ? options.now || Date.now : Date.now;
|
|
333
|
+
var requestAnimationFrameImpl = false && options.requestAnimationFrameImpl || function (callback) {
|
|
91
334
|
return window.requestAnimationFrame(callback);
|
|
92
335
|
};
|
|
93
|
-
var cancelAnimationFrameImpl = options.cancelAnimationFrameImpl || function (rafId) {
|
|
336
|
+
var cancelAnimationFrameImpl = false && options.cancelAnimationFrameImpl || function (rafId) {
|
|
94
337
|
return window.cancelAnimationFrame(rafId);
|
|
95
338
|
};
|
|
339
|
+
var setTimeoutImpl = false && options.setTimeoutImpl || function (callback, delay) {
|
|
340
|
+
return setTimeout(callback, delay);
|
|
341
|
+
};
|
|
342
|
+
var clearTimeoutImpl = false && options.clearTimeoutImpl || function (timeoutId) {
|
|
343
|
+
return clearTimeout(timeoutId);
|
|
344
|
+
};
|
|
96
345
|
var trackedContexts = [];
|
|
97
|
-
var trackedContextSet = new
|
|
346
|
+
var trackedContextSet = new WeakSet();
|
|
347
|
+
var captureGenerationByContext = new WeakMap();
|
|
348
|
+
var captureGeneration = 0;
|
|
349
|
+
var rejectedContextSet = new WeakSet();
|
|
98
350
|
var patchedPrototypeRecords = [];
|
|
351
|
+
var snapshotFallbackPatchTargets = new WeakSet();
|
|
99
352
|
var pendingCommandsByContext = new Map();
|
|
353
|
+
var pendingCommandApproxBytes = 0;
|
|
100
354
|
var fallbackModeContexts = new WeakSet();
|
|
355
|
+
var persistentFallbackModeContexts = new WeakSet();
|
|
101
356
|
var fallbackReasonByContext = new WeakMap();
|
|
357
|
+
var persistentFallbackReasonByContext = new WeakMap();
|
|
358
|
+
var expiredUnpublishedContexts = new WeakSet();
|
|
102
359
|
var patchedOpaqueObjects = new WeakSet();
|
|
103
360
|
var patchedOpaqueObjectRefs = [];
|
|
361
|
+
var patchedOpaqueObjectRefAddCount = 0;
|
|
362
|
+
var patchedOpaqueObjectRefLastCompactionCount = 0;
|
|
104
363
|
var opaqueObjectContextMap = new WeakMap();
|
|
105
|
-
var weakRefFactory = Object.prototype.hasOwnProperty.call(options, 'weakRefFactory') ? typeof options.weakRefFactory === 'function' ? options.weakRefFactory : undefined : typeof WeakRef === 'function' ? function (value) {
|
|
364
|
+
var weakRefFactory = false && Object.prototype.hasOwnProperty.call(options, 'weakRefFactory') ? typeof options.weakRefFactory === 'function' ? options.weakRefFactory : undefined : typeof WeakRef === 'function' ? function (value) {
|
|
106
365
|
return new WeakRef(value);
|
|
107
366
|
} : undefined;
|
|
108
367
|
var scheduledFlushId;
|
|
368
|
+
var unpublishedCleanupTimeoutId;
|
|
369
|
+
var unpublishedCleanupDeadline;
|
|
109
370
|
var stopped = false;
|
|
110
371
|
var paused = false;
|
|
372
|
+
var objectRefRegistry = false && options.objectRefRegistry || createCanvasCommandObjectRefRegistry();
|
|
373
|
+
var onCommandOverflow = false ? options.onCommandOverflow || function () {} : undefined;
|
|
111
374
|
var getCanvasId = options.getCanvasId || function (context) {
|
|
112
375
|
return context && context.canvas && context.canvas.__sn && context.canvas.__sn.id;
|
|
113
376
|
};
|
|
@@ -115,6 +378,8 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
115
378
|
return '2D';
|
|
116
379
|
};
|
|
117
380
|
var requestSnapshotFallback = options.requestSnapshotFallback || function () {};
|
|
381
|
+
var onContextDiscovered = options.onContextDiscovered || function () {};
|
|
382
|
+
var onContextMutation = options.onContextMutation || function () {};
|
|
118
383
|
var shouldRecordContext = options.shouldRecordContext || function () {
|
|
119
384
|
return true;
|
|
120
385
|
};
|
|
@@ -127,90 +392,418 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
127
392
|
flush();
|
|
128
393
|
});
|
|
129
394
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
395
|
+
function getOrCreatePendingBatch(context) {
|
|
396
|
+
var batch = pendingCommandsByContext.get(context);
|
|
397
|
+
if (!batch) {
|
|
398
|
+
if (pendingCommandsByContext.size >= MAX_PENDING_CANVAS_COMMAND_CONTEXTS) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
var startedAt = now();
|
|
402
|
+
var canvasId = getCanvasId(context);
|
|
403
|
+
batch = {
|
|
404
|
+
commands: [],
|
|
405
|
+
approxBytesCount: 0,
|
|
406
|
+
startedAt: startedAt,
|
|
407
|
+
fallbackDirty: false,
|
|
408
|
+
fallbackSnapshotRequested: false,
|
|
409
|
+
unpublishedDeadline: canvasId === undefined || canvasId === null || canvasId === -1 ? startedAt + MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS : undefined
|
|
410
|
+
};
|
|
411
|
+
pendingCommandsByContext.set(context, batch);
|
|
412
|
+
if (batch.unpublishedDeadline !== undefined) {
|
|
413
|
+
refreshUnpublishedCleanupTimer();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return batch;
|
|
417
|
+
}
|
|
418
|
+
function isSnapshotFallbackContext(context) {
|
|
419
|
+
return fallbackModeContexts.has(context) || persistentFallbackModeContexts.has(context);
|
|
420
|
+
}
|
|
421
|
+
function getSnapshotFallbackReason(context) {
|
|
422
|
+
return persistentFallbackReasonByContext.get(context) || fallbackReasonByContext.get(context);
|
|
423
|
+
}
|
|
424
|
+
function deletePendingBatch(context) {
|
|
425
|
+
var batch = pendingCommandsByContext.get(context);
|
|
426
|
+
if (!batch) {
|
|
132
427
|
return;
|
|
133
428
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
429
|
+
pendingCommandApproxBytes = Math.max(0, pendingCommandApproxBytes - batch.approxBytesCount);
|
|
430
|
+
pendingCommandsByContext["delete"](context);
|
|
431
|
+
}
|
|
432
|
+
function clearUnpublishedCleanupTimer() {
|
|
433
|
+
if (unpublishedCleanupTimeoutId !== undefined) {
|
|
434
|
+
clearTimeoutImpl(unpublishedCleanupTimeoutId);
|
|
435
|
+
unpublishedCleanupTimeoutId = undefined;
|
|
436
|
+
}
|
|
437
|
+
unpublishedCleanupDeadline = undefined;
|
|
438
|
+
}
|
|
439
|
+
function clearPendingBatches() {
|
|
440
|
+
pendingCommandsByContext.clear();
|
|
441
|
+
pendingCommandApproxBytes = 0;
|
|
442
|
+
clearUnpublishedCleanupTimer();
|
|
443
|
+
}
|
|
444
|
+
function expireUnpublishedBatch(context) {
|
|
445
|
+
deletePendingBatch(context);
|
|
446
|
+
persistentFallbackModeContexts.add(context);
|
|
447
|
+
expiredUnpublishedContexts.add(context);
|
|
448
|
+
if (!persistentFallbackReasonByContext.has(context)) {
|
|
449
|
+
persistentFallbackReasonByContext.set(context, 'canvas_publication_timeout');
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function expireOverdueUnpublishedBatches() {
|
|
453
|
+
if (unpublishedCleanupDeadline === undefined) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
var currentTime = now();
|
|
457
|
+
if (currentTime < unpublishedCleanupDeadline) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
pendingCommandsByContext.forEach(function (batch, context) {
|
|
461
|
+
if (batch.unpublishedDeadline !== undefined && currentTime >= batch.unpublishedDeadline) {
|
|
462
|
+
expireUnpublishedBatch(context);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
refreshUnpublishedCleanupTimer();
|
|
466
|
+
}
|
|
467
|
+
function refreshUnpublishedCleanupTimer() {
|
|
468
|
+
var earliestDeadline;
|
|
469
|
+
pendingCommandsByContext.forEach(function (batch) {
|
|
470
|
+
if (batch.unpublishedDeadline !== undefined && (earliestDeadline === undefined || batch.unpublishedDeadline < earliestDeadline)) {
|
|
471
|
+
earliestDeadline = batch.unpublishedDeadline;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
if (earliestDeadline === undefined) {
|
|
475
|
+
clearUnpublishedCleanupTimer();
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (unpublishedCleanupTimeoutId !== undefined && unpublishedCleanupDeadline === earliestDeadline) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
clearUnpublishedCleanupTimer();
|
|
482
|
+
unpublishedCleanupDeadline = earliestDeadline;
|
|
483
|
+
unpublishedCleanupTimeoutId = setTimeoutImpl(function () {
|
|
484
|
+
unpublishedCleanupTimeoutId = undefined;
|
|
485
|
+
unpublishedCleanupDeadline = undefined;
|
|
486
|
+
flush();
|
|
487
|
+
}, Math.max(earliestDeadline - now(), 0));
|
|
488
|
+
}
|
|
489
|
+
function reportCommandOverflow(reason, context) {
|
|
490
|
+
if (false) {
|
|
491
|
+
onCommandOverflow({
|
|
492
|
+
reason: reason,
|
|
493
|
+
context: context,
|
|
494
|
+
pendingContextCount: pendingCommandsByContext.size,
|
|
495
|
+
pendingApproxBytes: pendingCommandApproxBytes
|
|
138
496
|
});
|
|
139
497
|
}
|
|
140
|
-
|
|
498
|
+
}
|
|
499
|
+
function enqueueCommand(context, command, approxBytesCount) {
|
|
500
|
+
if (paused) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
if (isSnapshotFallbackContext(context)) {
|
|
504
|
+
markSnapshotFallbackDirty(context);
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
var batch = getOrCreatePendingBatch(context);
|
|
508
|
+
if (!batch) {
|
|
509
|
+
enableSnapshotFallbackForContext(context, 'command_global_context_watermark', true);
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (batch.commands.length >= MAX_CANVAS_COMMANDS_PER_BATCH || approxBytesCount > MAX_CANVAS_COMMAND_BATCH_BYTES - batch.approxBytesCount) {
|
|
513
|
+
enableSnapshotFallbackForContext(context, 'command_batch_overflow');
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
if (approxBytesCount > MAX_PENDING_CANVAS_COMMAND_BYTES - pendingCommandApproxBytes) {
|
|
517
|
+
enableSnapshotFallbackForContext(context, 'command_global_bytes_watermark', true);
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
batch.commands.push(command);
|
|
521
|
+
batch.approxBytesCount += approxBytesCount;
|
|
522
|
+
pendingCommandApproxBytes += approxBytesCount;
|
|
141
523
|
scheduleFlush();
|
|
524
|
+
return true;
|
|
142
525
|
}
|
|
143
|
-
function
|
|
144
|
-
if (
|
|
526
|
+
function captureCommand(context, property, args, setter) {
|
|
527
|
+
if (paused) {
|
|
145
528
|
return;
|
|
146
529
|
}
|
|
147
|
-
|
|
148
|
-
|
|
530
|
+
expireOverdueUnpublishedBatches();
|
|
531
|
+
if (isSnapshotFallbackContext(context)) {
|
|
532
|
+
markSnapshotFallbackDirty(context);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
var batch = getOrCreatePendingBatch(context);
|
|
536
|
+
if (!batch) {
|
|
537
|
+
enableSnapshotFallbackForContext(context, 'command_global_context_watermark', true);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (batch.commands.length >= MAX_CANVAS_COMMANDS_PER_BATCH) {
|
|
541
|
+
enableSnapshotFallbackForContext(context, 'command_batch_overflow');
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
var estimate;
|
|
545
|
+
try {
|
|
546
|
+
estimate = estimateCanvasCommand(property, args, setter, MAX_CANVAS_COMMAND_BATCH_BYTES - batch.approxBytesCount);
|
|
547
|
+
} catch (_) {
|
|
548
|
+
enableSnapshotFallbackForContext(context, 'command_serialization_error');
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (estimate.fallbackReason) {
|
|
552
|
+
enableSnapshotFallbackForContext(context, estimate.fallbackReason);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (estimate.overflow) {
|
|
556
|
+
enableSnapshotFallbackForContext(context, 'command_batch_overflow');
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (estimate.bytes > MAX_PENDING_CANVAS_COMMAND_BYTES - pendingCommandApproxBytes) {
|
|
560
|
+
enableSnapshotFallbackForContext(context, 'command_global_bytes_watermark', true);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
var serializedArgs;
|
|
564
|
+
try {
|
|
565
|
+
serializedArgs = objectRefRegistry.serializeArgs(args, context);
|
|
566
|
+
} catch (_) {
|
|
567
|
+
enableSnapshotFallbackForContext(context, 'command_serialization_error');
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
var command = {
|
|
571
|
+
property: property,
|
|
572
|
+
args: serializedArgs
|
|
573
|
+
};
|
|
574
|
+
if (setter === true) {
|
|
575
|
+
command.setter = true;
|
|
576
|
+
}
|
|
577
|
+
enqueueCommand(context, command, estimate.bytes);
|
|
578
|
+
}
|
|
579
|
+
function markSnapshotFallbackDirty(context, requestImmediately) {
|
|
580
|
+
if (paused || expiredUnpublishedContexts.has(context)) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
var batch = pendingCommandsByContext.get(context);
|
|
584
|
+
if (!batch) {
|
|
585
|
+
if (pendingCommandsByContext.size >= MAX_PENDING_CANVAS_COMMAND_CONTEXTS) {
|
|
586
|
+
requestSnapshotFallback(context, getSnapshotFallbackReason(context) || 'unsupported_canvas_object');
|
|
149
587
|
return;
|
|
150
588
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
589
|
+
var startedAt = now();
|
|
590
|
+
var canvasId = getCanvasId(context);
|
|
591
|
+
batch = {
|
|
592
|
+
commands: [],
|
|
593
|
+
approxBytesCount: 0,
|
|
594
|
+
startedAt: startedAt,
|
|
595
|
+
fallbackDirty: true,
|
|
596
|
+
fallbackSnapshotRequested: false,
|
|
597
|
+
unpublishedDeadline: canvasId === undefined || canvasId === null || canvasId === -1 ? startedAt + MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS : undefined
|
|
598
|
+
};
|
|
599
|
+
pendingCommandsByContext.set(context, batch);
|
|
600
|
+
if (batch.unpublishedDeadline !== undefined) {
|
|
601
|
+
refreshUnpublishedCleanupTimer();
|
|
154
602
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
603
|
+
} else {
|
|
604
|
+
pendingCommandApproxBytes = Math.max(0, pendingCommandApproxBytes - batch.approxBytesCount);
|
|
605
|
+
batch.commands = [];
|
|
606
|
+
batch.approxBytesCount = 0;
|
|
607
|
+
batch.fallbackDirty = true;
|
|
608
|
+
}
|
|
609
|
+
if (requestImmediately && !batch.fallbackSnapshotRequested) {
|
|
610
|
+
batch.fallbackSnapshotRequested = true;
|
|
611
|
+
requestSnapshotFallback(context, getSnapshotFallbackReason(context) || 'unsupported_canvas_object');
|
|
612
|
+
}
|
|
613
|
+
scheduleFlush();
|
|
614
|
+
}
|
|
615
|
+
function flushPendingContext(context, flushedAt) {
|
|
616
|
+
var batch = pendingCommandsByContext.get(context);
|
|
617
|
+
if (!batch) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (isSnapshotFallbackContext(context)) {
|
|
621
|
+
if (batch.fallbackDirty && !batch.fallbackSnapshotRequested) {
|
|
622
|
+
requestSnapshotFallback(context, getSnapshotFallbackReason(context) || 'unsupported_canvas_object');
|
|
623
|
+
}
|
|
624
|
+
deletePendingBatch(context);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (!batch.commands.length) {
|
|
628
|
+
deletePendingBatch(context);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
var id = getCanvasId(context);
|
|
632
|
+
if (id === undefined || id === null || id === -1) {
|
|
633
|
+
// A freshly inserted canvas can be drawn before its delayed DOM add is
|
|
634
|
+
// admitted. Retain it for a bounded publication grace period, then
|
|
635
|
+
// release the strong Map key and require an authoritative bitmap if
|
|
636
|
+
// the canvas is ever published later.
|
|
637
|
+
if (batch.unpublishedDeadline === undefined) {
|
|
638
|
+
batch.unpublishedDeadline = flushedAt + MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS;
|
|
639
|
+
}
|
|
640
|
+
if (flushedAt >= batch.unpublishedDeadline) {
|
|
641
|
+
expireUnpublishedBatch(context);
|
|
158
642
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
var completedAt = flushedAt;
|
|
646
|
+
var commands = batch.commands;
|
|
647
|
+
var recordAccepted = emit(createCanvasMutationRecord({
|
|
648
|
+
id: id,
|
|
649
|
+
contextType: getCanvasType(context),
|
|
650
|
+
commands: commands,
|
|
651
|
+
timestamp: completedAt,
|
|
652
|
+
startedAt: batch.startedAt,
|
|
653
|
+
completedAt: completedAt
|
|
654
|
+
}), {
|
|
655
|
+
approxBytesCount: batch.approxBytesCount,
|
|
656
|
+
commandCount: commands.length
|
|
168
657
|
});
|
|
169
|
-
|
|
658
|
+
if (recordAccepted === false) {
|
|
659
|
+
// The command batch never entered the replay segment. Its following
|
|
660
|
+
// commands can depend on state from this batch, so switch this context
|
|
661
|
+
// to bitmap snapshots and request an immediate visual rebaseline.
|
|
662
|
+
enableSnapshotFallbackForContext(context, 'command_record_rejected');
|
|
663
|
+
}
|
|
664
|
+
deletePendingBatch(context);
|
|
665
|
+
}
|
|
666
|
+
function flushContext(context) {
|
|
667
|
+
if (stopped || paused || !context) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
flushPendingContext(context, now());
|
|
671
|
+
refreshUnpublishedCleanupTimer();
|
|
672
|
+
}
|
|
673
|
+
function flush() {
|
|
674
|
+
if (stopped || paused) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
var flushedAt = now();
|
|
678
|
+
pendingCommandsByContext.forEach(function (_, context) {
|
|
679
|
+
flushPendingContext(context, flushedAt);
|
|
680
|
+
});
|
|
681
|
+
refreshUnpublishedCleanupTimer();
|
|
682
|
+
}
|
|
683
|
+
function retryPublishedContext(context) {
|
|
684
|
+
if (stopped || paused || !context || !trackedContextSet.has(context)) {
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
expireOverdueUnpublishedBatches();
|
|
688
|
+
var id = getCanvasId(context);
|
|
689
|
+
if (id === undefined || id === null || id === -1) {
|
|
690
|
+
return false;
|
|
691
|
+
}
|
|
692
|
+
if (!pendingCommandsByContext.has(context)) {
|
|
693
|
+
if (!expiredUnpublishedContexts.has(context)) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
expiredUnpublishedContexts["delete"](context);
|
|
697
|
+
// A canvas published after its command grace period no longer has a
|
|
698
|
+
// complete command history. Rebaseline it once instead of retaining the
|
|
699
|
+
// detached context strongly or replaying an incomplete command stream.
|
|
700
|
+
markSnapshotFallbackDirty(context, true);
|
|
701
|
+
}
|
|
702
|
+
// Publication belongs to one exact DOM admission boundary. Flushing every
|
|
703
|
+
// context here could move commands from another, already-published canvas
|
|
704
|
+
// ahead of DOM mutations that happened before its scheduled frame.
|
|
705
|
+
flushContext(context);
|
|
706
|
+
return true;
|
|
170
707
|
}
|
|
171
708
|
function shouldCaptureContext(context) {
|
|
172
|
-
|
|
709
|
+
if (!trackedContextSet.has(context)) {
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
if (captureGenerationByContext.get(context) !== captureGeneration) {
|
|
713
|
+
captureGenerationByContext.set(context, captureGeneration);
|
|
714
|
+
// reset() accompanies a new replay/full-snapshot canvas baseline, but
|
|
715
|
+
// it cannot reset the live application's transform, clip, path or style
|
|
716
|
+
// state. Existing contexts therefore cannot safely resume command mode.
|
|
717
|
+
enableSnapshotFallbackForContext(context, 'canvas_state_reset', false, true);
|
|
718
|
+
}
|
|
719
|
+
return true;
|
|
173
720
|
}
|
|
174
721
|
function registerTrackedContext(context, restoreFns) {
|
|
175
722
|
if (!context || trackedContextSet.has(context)) {
|
|
176
723
|
return false;
|
|
177
724
|
}
|
|
178
725
|
restoreFns = restoreFns || [];
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
726
|
+
if (restoreFns.length && trackedContexts.length >= MAX_STRONG_CANVAS_CONTEXT_RESTORE_RECORDS) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
if (restoreFns.length) {
|
|
730
|
+
trackedContexts.push({
|
|
731
|
+
context: context,
|
|
732
|
+
restore: function restore() {
|
|
733
|
+
trackedContextSet["delete"](context);
|
|
734
|
+
deletePendingBatch(context);
|
|
735
|
+
expiredUnpublishedContexts["delete"](context);
|
|
736
|
+
fallbackModeContexts["delete"](context);
|
|
737
|
+
persistentFallbackModeContexts["delete"](context);
|
|
738
|
+
fallbackReasonByContext["delete"](context);
|
|
739
|
+
persistentFallbackReasonByContext["delete"](context);
|
|
740
|
+
while (restoreFns.length) {
|
|
741
|
+
restoreFns.pop()();
|
|
742
|
+
}
|
|
195
743
|
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
198
746
|
trackedContextSet.add(context);
|
|
747
|
+
captureGenerationByContext.set(context, captureGeneration);
|
|
199
748
|
return true;
|
|
200
749
|
}
|
|
201
750
|
function maybeTrackContext(context) {
|
|
202
|
-
if (!context || trackedContextSet.has(context) ||
|
|
751
|
+
if (stopped || !context || trackedContextSet.has(context) || rejectedContextSet.has(context) || !context.canvas) {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
if (shouldRecordContext(context) === false) {
|
|
755
|
+
rejectedContextSet.add(context);
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
if (!registerTrackedContext(context, [])) {
|
|
203
759
|
return false;
|
|
204
760
|
}
|
|
205
|
-
|
|
761
|
+
var hasAuthoritativeBitmapBaseline = false;
|
|
762
|
+
try {
|
|
763
|
+
hasAuthoritativeBitmapBaseline = onContextDiscovered(context) === true;
|
|
764
|
+
} catch (_) {}
|
|
765
|
+
|
|
766
|
+
// A context discovered through the already-patched shared prototype was
|
|
767
|
+
// created before this recorder observed getContext(). Its current drawing
|
|
768
|
+
// state (transform, clip/path and styles) cannot be reconstructed safely
|
|
769
|
+
// from later commands, so keep this context on the snapshot path.
|
|
770
|
+
if (hasAuthoritativeBitmapBaseline) {
|
|
771
|
+
markPersistentSnapshotFallback(context, 'existing_bitmap_state');
|
|
772
|
+
} else {
|
|
773
|
+
enableSnapshotFallbackForContext(context, 'existing_canvas_context', false, true);
|
|
774
|
+
}
|
|
775
|
+
return true;
|
|
206
776
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
777
|
+
function notifyContextMutation(context) {
|
|
778
|
+
try {
|
|
779
|
+
onContextMutation(context);
|
|
780
|
+
} catch (_) {}
|
|
781
|
+
}
|
|
782
|
+
function rejectContext(context) {
|
|
783
|
+
if (!context) {
|
|
784
|
+
return;
|
|
211
785
|
}
|
|
212
|
-
|
|
213
|
-
|
|
786
|
+
rejectedContextSet.add(context);
|
|
787
|
+
trackedContextSet["delete"](context);
|
|
788
|
+
deletePendingBatch(context);
|
|
789
|
+
expiredUnpublishedContexts["delete"](context);
|
|
790
|
+
fallbackModeContexts["delete"](context);
|
|
791
|
+
persistentFallbackModeContexts["delete"](context);
|
|
792
|
+
fallbackReasonByContext["delete"](context);
|
|
793
|
+
persistentFallbackReasonByContext["delete"](context);
|
|
794
|
+
}
|
|
795
|
+
function enableSnapshotFallbackForContext(context, reason, isGlobalOverflow, persistent) {
|
|
796
|
+
var fallbackContexts = persistent ? persistentFallbackModeContexts : fallbackModeContexts;
|
|
797
|
+
var fallbackReasons = persistent ? persistentFallbackReasonByContext : fallbackReasonByContext;
|
|
798
|
+
fallbackContexts.add(context);
|
|
799
|
+
if (!fallbackReasons.has(context)) {
|
|
800
|
+
fallbackReasons.set(context, reason || 'unsupported_canvas_object');
|
|
801
|
+
}
|
|
802
|
+
if (isGlobalOverflow) {
|
|
803
|
+
reportCommandOverflow(reason, context);
|
|
804
|
+
}
|
|
805
|
+
deletePendingBatch(context);
|
|
806
|
+
markSnapshotFallbackDirty(context, true);
|
|
214
807
|
}
|
|
215
808
|
function patchGradientObjectMethods(value, context) {
|
|
216
809
|
if (!value || _typeof(value) !== 'object' || typeof value.addColorStop !== 'function') {
|
|
@@ -220,143 +813,277 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
220
813
|
if (patchedOpaqueObjects.has(value)) {
|
|
221
814
|
return;
|
|
222
815
|
}
|
|
223
|
-
|
|
816
|
+
if (!weakRefFactory && patchedOpaqueObjectRefs.length >= MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS) {
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
var objectRef;
|
|
224
820
|
try {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
821
|
+
objectRef = weakRefFactory ? weakRefFactory(value) : {
|
|
822
|
+
value: value
|
|
823
|
+
};
|
|
824
|
+
} catch (_) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (!addPatchedOpaqueObjectRef(objectRef)) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
var originalAddColorStop = value.addColorStop;
|
|
831
|
+
var _wrappedAddColorStop = function wrappedAddColorStop() {
|
|
832
|
+
if (stopped || this[PATCHED_ADD_COLOR_STOP_KEY] !== _wrappedAddColorStop) {
|
|
833
|
+
var restoredOriginal = this[ORIGINAL_ADD_COLOR_STOP_KEY];
|
|
834
|
+
if (typeof restoredOriginal === 'function') {
|
|
835
|
+
if (this.addColorStop === _wrappedAddColorStop) {
|
|
231
836
|
this.addColorStop = restoredOriginal;
|
|
232
|
-
delete this[ORIGINAL_ADD_COLOR_STOP_KEY];
|
|
233
|
-
delete this[PATCHED_ADD_COLOR_STOP_KEY];
|
|
234
|
-
return restoredOriginal.apply(this, arguments);
|
|
235
837
|
}
|
|
838
|
+
delete this[ORIGINAL_ADD_COLOR_STOP_KEY];
|
|
839
|
+
delete this[PATCHED_ADD_COLOR_STOP_KEY];
|
|
840
|
+
return restoredOriginal.apply(this, arguments);
|
|
236
841
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
842
|
+
}
|
|
843
|
+
var result = originalAddColorStop.apply(this, arguments);
|
|
844
|
+
var fallbackContext = opaqueObjectContextMap.get(this);
|
|
845
|
+
if (fallbackContext && shouldCaptureContext(fallbackContext)) {
|
|
846
|
+
notifyContextMutation(fallbackContext);
|
|
847
|
+
enableSnapshotFallbackForContext(fallbackContext, 'gradient_color_stop');
|
|
848
|
+
}
|
|
849
|
+
return result;
|
|
850
|
+
};
|
|
851
|
+
try {
|
|
852
|
+
value[ORIGINAL_ADD_COLOR_STOP_KEY] = originalAddColorStop;
|
|
853
|
+
value[PATCHED_ADD_COLOR_STOP_KEY] = _wrappedAddColorStop;
|
|
854
|
+
value.addColorStop = _wrappedAddColorStop;
|
|
243
855
|
patchedOpaqueObjects.add(value);
|
|
244
|
-
patchedOpaqueObjectRefs.push(weakRefFactory ? weakRefFactory(value) : {
|
|
245
|
-
value: value
|
|
246
|
-
});
|
|
247
856
|
} catch (_) {}
|
|
248
857
|
}
|
|
858
|
+
function dereferencePatchedOpaqueObject(objectRef) {
|
|
859
|
+
return objectRef && typeof objectRef.deref === 'function' ? objectRef.deref() : objectRef && objectRef.value;
|
|
860
|
+
}
|
|
861
|
+
function compactPatchedOpaqueObjectRefs() {
|
|
862
|
+
var retainedRefs = [];
|
|
863
|
+
for (var index = 0; index < patchedOpaqueObjectRefs.length; index += 1) {
|
|
864
|
+
var objectRef = patchedOpaqueObjectRefs[index];
|
|
865
|
+
if (dereferencePatchedOpaqueObject(objectRef)) {
|
|
866
|
+
retainedRefs.push(objectRef);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
patchedOpaqueObjectRefs = retainedRefs;
|
|
870
|
+
}
|
|
871
|
+
function addPatchedOpaqueObjectRef(objectRef) {
|
|
872
|
+
patchedOpaqueObjectRefAddCount += 1;
|
|
873
|
+
if (weakRefFactory && patchedOpaqueObjectRefs.length >= MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS && (patchedOpaqueObjectRefLastCompactionCount === 0 || patchedOpaqueObjectRefAddCount - patchedOpaqueObjectRefLastCompactionCount >= Math.max(Math.floor(MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS / 4), 1))) {
|
|
874
|
+
compactPatchedOpaqueObjectRefs();
|
|
875
|
+
patchedOpaqueObjectRefLastCompactionCount = patchedOpaqueObjectRefAddCount;
|
|
876
|
+
}
|
|
877
|
+
if (patchedOpaqueObjectRefs.length < MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS) {
|
|
878
|
+
patchedOpaqueObjectRefs.push(objectRef);
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
// Never evict a live restore record: doing so would leave an SDK wrapper
|
|
882
|
+
// (and its recorder closure) installed after stop(). A gradient that
|
|
883
|
+
// cannot get a bounded restore record remains native; assigning it to a
|
|
884
|
+
// style still switches the owning context to snapshot fallback.
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
249
887
|
function restorePatchedOpaqueObjects() {
|
|
250
888
|
while (patchedOpaqueObjectRefs.length) {
|
|
251
889
|
var objectRef = patchedOpaqueObjectRefs.pop();
|
|
252
|
-
var object = objectRef
|
|
890
|
+
var object = dereferencePatchedOpaqueObject(objectRef);
|
|
253
891
|
if (object && object[PATCHED_ADD_COLOR_STOP_KEY] && typeof object[ORIGINAL_ADD_COLOR_STOP_KEY] === 'function') {
|
|
254
|
-
object.addColorStop
|
|
892
|
+
if (object.addColorStop === object[PATCHED_ADD_COLOR_STOP_KEY]) {
|
|
893
|
+
object.addColorStop = object[ORIGINAL_ADD_COLOR_STOP_KEY];
|
|
894
|
+
}
|
|
255
895
|
delete object[ORIGINAL_ADD_COLOR_STOP_KEY];
|
|
256
896
|
delete object[PATCHED_ADD_COLOR_STOP_KEY];
|
|
257
897
|
}
|
|
258
898
|
}
|
|
259
899
|
}
|
|
260
|
-
function patchMethodOnTarget(target, methodName, restoreFns) {
|
|
900
|
+
function patchMethodOnTarget(target, methodName, restoreFns, alwaysSnapshotFallback) {
|
|
261
901
|
if (typeof target[methodName] !== 'function') {
|
|
262
|
-
return;
|
|
902
|
+
return false;
|
|
263
903
|
}
|
|
264
904
|
var originalMethod = target[methodName];
|
|
265
|
-
|
|
905
|
+
var wrappedMethod = function wrappedMethod() {
|
|
266
906
|
maybeTrackContext(this);
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
907
|
+
var shouldCapture = shouldCaptureContext(this);
|
|
908
|
+
var result = originalMethod.apply(this, arguments);
|
|
909
|
+
if (shouldCapture) {
|
|
910
|
+
notifyContextMutation(this);
|
|
911
|
+
}
|
|
912
|
+
if (shouldCapture && alwaysSnapshotFallback) {
|
|
913
|
+
try {
|
|
914
|
+
if (isSnapshotFallbackContext(this)) {
|
|
915
|
+
markSnapshotFallbackDirty(this);
|
|
916
|
+
} else {
|
|
917
|
+
enableSnapshotFallbackForContext(this, 'unsupported_canvas_method', false, true);
|
|
918
|
+
}
|
|
919
|
+
} catch (_) {}
|
|
920
|
+
return result;
|
|
921
|
+
}
|
|
922
|
+
if (shouldCapture && isSnapshotFallbackContext(this)) {
|
|
923
|
+
try {
|
|
924
|
+
markSnapshotFallbackDirty(this);
|
|
925
|
+
} catch (_) {}
|
|
926
|
+
return result;
|
|
927
|
+
}
|
|
928
|
+
if (shouldCapture) {
|
|
279
929
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
930
|
+
var drawImageFallbackReason = methodName === 'drawImage' ? isUnsupportedDrawImageSource(arguments[0]) : undefined;
|
|
931
|
+
if (drawImageFallbackReason) {
|
|
932
|
+
enableSnapshotFallbackForContext(this, drawImageFallbackReason);
|
|
933
|
+
} else {
|
|
934
|
+
captureCommand(this, methodName, arguments, false);
|
|
935
|
+
}
|
|
936
|
+
} catch (_) {
|
|
937
|
+
try {
|
|
938
|
+
enableSnapshotFallbackForContext(this, 'command_serialization_error');
|
|
939
|
+
} catch (_) {}
|
|
283
940
|
}
|
|
284
|
-
enqueueCommand(this, {
|
|
285
|
-
property: methodName,
|
|
286
|
-
args: serializedArgs
|
|
287
|
-
});
|
|
288
941
|
}
|
|
289
|
-
|
|
290
|
-
if (shouldCaptureContext(this) && (methodName === 'createLinearGradient' || methodName === 'createRadialGradient' || methodName === 'createConicGradient')) {
|
|
942
|
+
if (shouldCapture && (methodName === 'createLinearGradient' || methodName === 'createRadialGradient' || methodName === 'createConicGradient')) {
|
|
291
943
|
patchGradientObjectMethods(result, this);
|
|
292
944
|
}
|
|
293
945
|
return result;
|
|
294
946
|
};
|
|
947
|
+
try {
|
|
948
|
+
target[methodName] = wrappedMethod;
|
|
949
|
+
} catch (_) {
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
if (target[methodName] !== wrappedMethod) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
295
955
|
restoreFns.push(function () {
|
|
296
|
-
target[methodName]
|
|
956
|
+
if (target[methodName] === wrappedMethod) {
|
|
957
|
+
target[methodName] = originalMethod;
|
|
958
|
+
}
|
|
297
959
|
});
|
|
960
|
+
return true;
|
|
298
961
|
}
|
|
299
|
-
function patchPropertyOnTarget(target, propertyName, restoreFns) {
|
|
962
|
+
function patchPropertyOnTarget(target, propertyName, restoreFns, alwaysSnapshotFallback) {
|
|
300
963
|
if (!canPatchProperty(target, propertyName)) {
|
|
301
|
-
return;
|
|
964
|
+
return false;
|
|
302
965
|
}
|
|
303
966
|
var originalDescriptor = getPropertyDescriptor(target, propertyName);
|
|
304
967
|
var fallbackValues = new WeakMap();
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
968
|
+
var wrappedGetter = function wrappedGetter() {
|
|
969
|
+
if (originalDescriptor && originalDescriptor.get) {
|
|
970
|
+
return originalDescriptor.get.call(this);
|
|
971
|
+
}
|
|
972
|
+
return fallbackValues.get(this);
|
|
973
|
+
};
|
|
974
|
+
var wrappedSetter = function wrappedSetter(value) {
|
|
975
|
+
maybeTrackContext(this);
|
|
976
|
+
fallbackValues.set(this, value);
|
|
977
|
+
if (originalDescriptor && originalDescriptor.set) {
|
|
978
|
+
originalDescriptor.set.call(this, value);
|
|
979
|
+
}
|
|
980
|
+
var shouldCapture = shouldCaptureContext(this);
|
|
981
|
+
if (shouldCapture) {
|
|
982
|
+
notifyContextMutation(this);
|
|
983
|
+
if (alwaysSnapshotFallback) {
|
|
984
|
+
try {
|
|
985
|
+
if (isSnapshotFallbackContext(this)) {
|
|
986
|
+
markSnapshotFallbackDirty(this);
|
|
987
|
+
} else {
|
|
988
|
+
enableSnapshotFallbackForContext(this, 'unsupported_canvas_property', false, true);
|
|
989
|
+
}
|
|
990
|
+
} catch (_) {}
|
|
991
|
+
return;
|
|
311
992
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (originalDescriptor && originalDescriptor.set) {
|
|
318
|
-
originalDescriptor.set.call(this, value);
|
|
993
|
+
if (isSnapshotFallbackContext(this)) {
|
|
994
|
+
try {
|
|
995
|
+
markSnapshotFallbackDirty(this);
|
|
996
|
+
} catch (_) {}
|
|
997
|
+
return;
|
|
319
998
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
enqueueCommand(this, {
|
|
327
|
-
property: propertyName,
|
|
328
|
-
args: [serializeCanvasCommandArgs([value], this)[0]],
|
|
329
|
-
setter: true
|
|
330
|
-
});
|
|
999
|
+
try {
|
|
1000
|
+
captureCommand(this, propertyName, [value], true);
|
|
1001
|
+
} catch (_) {
|
|
1002
|
+
try {
|
|
1003
|
+
enableSnapshotFallbackForContext(this, 'command_serialization_error');
|
|
1004
|
+
} catch (_) {}
|
|
331
1005
|
}
|
|
332
1006
|
}
|
|
333
|
-
}
|
|
1007
|
+
};
|
|
1008
|
+
try {
|
|
1009
|
+
Object.defineProperty(target, propertyName, {
|
|
1010
|
+
configurable: true,
|
|
1011
|
+
enumerable: true,
|
|
1012
|
+
get: wrappedGetter,
|
|
1013
|
+
set: wrappedSetter
|
|
1014
|
+
});
|
|
1015
|
+
} catch (_) {
|
|
1016
|
+
return false;
|
|
1017
|
+
}
|
|
334
1018
|
restoreFns.push(function () {
|
|
1019
|
+
var currentDescriptor = Object.getOwnPropertyDescriptor(target, propertyName);
|
|
1020
|
+
if (!currentDescriptor || currentDescriptor.get !== wrappedGetter || currentDescriptor.set !== wrappedSetter) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
335
1023
|
if (originalDescriptor) {
|
|
336
1024
|
Object.defineProperty(target, propertyName, originalDescriptor);
|
|
337
1025
|
} else {
|
|
338
1026
|
delete target[propertyName];
|
|
339
1027
|
}
|
|
340
1028
|
});
|
|
1029
|
+
return true;
|
|
1030
|
+
}
|
|
1031
|
+
function patchUnknownMutationsOnTarget(target, restoreFns) {
|
|
1032
|
+
var propertyNames;
|
|
1033
|
+
try {
|
|
1034
|
+
propertyNames = Object.getOwnPropertyNames(target);
|
|
1035
|
+
} catch (_) {
|
|
1036
|
+
snapshotFallbackPatchTargets.add(target);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
propertyNames.forEach(function (propertyName) {
|
|
1040
|
+
if (propertyName === 'constructor' || CANVAS_2D_CAPTURED_METHOD_NAMES[propertyName] || CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] || CANVAS_2D_NON_MUTATING_METHODS[propertyName]) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
var descriptor;
|
|
1044
|
+
try {
|
|
1045
|
+
descriptor = Object.getOwnPropertyDescriptor(target, propertyName);
|
|
1046
|
+
} catch (_) {
|
|
1047
|
+
snapshotFallbackPatchTargets.add(target);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
1051
|
+
if (!patchMethodOnTarget(target, propertyName, restoreFns, true)) {
|
|
1052
|
+
snapshotFallbackPatchTargets.add(target);
|
|
1053
|
+
}
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (descriptor && typeof descriptor.set === 'function' && !patchPropertyOnTarget(target, propertyName, restoreFns, true)) {
|
|
1057
|
+
snapshotFallbackPatchTargets.add(target);
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
341
1060
|
}
|
|
342
1061
|
function patchPrototype(context) {
|
|
343
1062
|
var prototype = Object.getPrototypeOf(context);
|
|
344
1063
|
if (!prototype || prototype === Object.prototype) {
|
|
345
|
-
return;
|
|
1064
|
+
return false;
|
|
346
1065
|
}
|
|
347
1066
|
var existingRecord = patchedPrototypeRecords.find(function (record) {
|
|
348
1067
|
return record.prototype === prototype;
|
|
349
1068
|
});
|
|
350
1069
|
if (existingRecord) {
|
|
351
|
-
return;
|
|
1070
|
+
return true;
|
|
1071
|
+
}
|
|
1072
|
+
if (patchedPrototypeRecords.length >= MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS) {
|
|
1073
|
+
return false;
|
|
352
1074
|
}
|
|
353
1075
|
var restoreFns = [];
|
|
354
1076
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
355
|
-
patchMethodOnTarget(prototype, methodName, restoreFns)
|
|
1077
|
+
if (typeof prototype[methodName] === 'function' && !patchMethodOnTarget(prototype, methodName, restoreFns)) {
|
|
1078
|
+
snapshotFallbackPatchTargets.add(prototype);
|
|
1079
|
+
}
|
|
356
1080
|
});
|
|
357
1081
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
358
|
-
patchPropertyOnTarget(prototype, propertyName, restoreFns)
|
|
1082
|
+
if (getPropertyDescriptor(prototype, propertyName) && !patchPropertyOnTarget(prototype, propertyName, restoreFns)) {
|
|
1083
|
+
snapshotFallbackPatchTargets.add(prototype);
|
|
1084
|
+
}
|
|
359
1085
|
});
|
|
1086
|
+
patchUnknownMutationsOnTarget(prototype, restoreFns);
|
|
360
1087
|
patchedPrototypeRecords.push({
|
|
361
1088
|
prototype: prototype,
|
|
362
1089
|
restore: function restore() {
|
|
@@ -365,24 +1092,33 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
365
1092
|
}
|
|
366
1093
|
}
|
|
367
1094
|
});
|
|
1095
|
+
return true;
|
|
368
1096
|
}
|
|
369
1097
|
function patchSharedPrototype(prototype) {
|
|
370
1098
|
if (!prototype || prototype === Object.prototype) {
|
|
371
|
-
return;
|
|
1099
|
+
return false;
|
|
372
1100
|
}
|
|
373
1101
|
var existingRecord = patchedPrototypeRecords.find(function (record) {
|
|
374
1102
|
return record.prototype === prototype;
|
|
375
1103
|
});
|
|
376
1104
|
if (existingRecord) {
|
|
377
|
-
return;
|
|
1105
|
+
return true;
|
|
1106
|
+
}
|
|
1107
|
+
if (patchedPrototypeRecords.length >= MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS) {
|
|
1108
|
+
return false;
|
|
378
1109
|
}
|
|
379
1110
|
var restoreFns = [];
|
|
380
1111
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
381
|
-
patchMethodOnTarget(prototype, methodName, restoreFns)
|
|
1112
|
+
if (typeof prototype[methodName] === 'function' && !patchMethodOnTarget(prototype, methodName, restoreFns)) {
|
|
1113
|
+
snapshotFallbackPatchTargets.add(prototype);
|
|
1114
|
+
}
|
|
382
1115
|
});
|
|
383
1116
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
384
|
-
patchPropertyOnTarget(prototype, propertyName, restoreFns)
|
|
1117
|
+
if (getPropertyDescriptor(prototype, propertyName) && !patchPropertyOnTarget(prototype, propertyName, restoreFns)) {
|
|
1118
|
+
snapshotFallbackPatchTargets.add(prototype);
|
|
1119
|
+
}
|
|
385
1120
|
});
|
|
1121
|
+
patchUnknownMutationsOnTarget(prototype, restoreFns);
|
|
386
1122
|
patchedPrototypeRecords.push({
|
|
387
1123
|
prototype: prototype,
|
|
388
1124
|
restore: function restore() {
|
|
@@ -391,28 +1127,51 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
391
1127
|
}
|
|
392
1128
|
}
|
|
393
1129
|
});
|
|
1130
|
+
return true;
|
|
394
1131
|
}
|
|
395
1132
|
function patchContextInstance(context, restoreFns) {
|
|
396
1133
|
CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
|
|
397
|
-
patchMethodOnTarget(context, methodName, restoreFns)
|
|
1134
|
+
if (typeof context[methodName] === 'function' && !patchMethodOnTarget(context, methodName, restoreFns)) {
|
|
1135
|
+
snapshotFallbackPatchTargets.add(context);
|
|
1136
|
+
}
|
|
398
1137
|
});
|
|
399
1138
|
CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
|
|
400
|
-
patchPropertyOnTarget(context, propertyName, restoreFns)
|
|
1139
|
+
if (!patchPropertyOnTarget(context, propertyName, restoreFns)) {
|
|
1140
|
+
snapshotFallbackPatchTargets.add(context);
|
|
1141
|
+
}
|
|
401
1142
|
});
|
|
1143
|
+
patchUnknownMutationsOnTarget(context, restoreFns);
|
|
402
1144
|
}
|
|
403
1145
|
function patchContext(context) {
|
|
404
|
-
if (!context || context
|
|
1146
|
+
if (stopped || !context || trackedContextSet.has(context)) {
|
|
405
1147
|
return function () {};
|
|
406
1148
|
}
|
|
407
1149
|
var restoreFns = [];
|
|
408
1150
|
var prototype = Object.getPrototypeOf(context);
|
|
409
1151
|
if (prototype && prototype !== Object.prototype) {
|
|
410
|
-
patchPrototype(context)
|
|
1152
|
+
if (!patchPrototype(context)) {
|
|
1153
|
+
return function () {};
|
|
1154
|
+
}
|
|
411
1155
|
} else {
|
|
412
1156
|
patchContextInstance(context, restoreFns);
|
|
413
1157
|
}
|
|
414
|
-
registerTrackedContext(context, restoreFns)
|
|
1158
|
+
if (!registerTrackedContext(context, restoreFns)) {
|
|
1159
|
+
while (restoreFns.length) {
|
|
1160
|
+
restoreFns.pop()();
|
|
1161
|
+
}
|
|
1162
|
+
return function () {};
|
|
1163
|
+
}
|
|
1164
|
+
if (snapshotFallbackPatchTargets.has(context) || prototype && snapshotFallbackPatchTargets.has(prototype)) {
|
|
1165
|
+
enableSnapshotFallbackForContext(context, 'unpatchable_canvas_api', false, true);
|
|
1166
|
+
}
|
|
415
1167
|
return function () {
|
|
1168
|
+
trackedContextSet["delete"](context);
|
|
1169
|
+
deletePendingBatch(context);
|
|
1170
|
+
expiredUnpublishedContexts["delete"](context);
|
|
1171
|
+
fallbackModeContexts["delete"](context);
|
|
1172
|
+
persistentFallbackModeContexts["delete"](context);
|
|
1173
|
+
fallbackReasonByContext["delete"](context);
|
|
1174
|
+
persistentFallbackReasonByContext["delete"](context);
|
|
416
1175
|
var trackedIndex = trackedContexts.findIndex(function (tracked) {
|
|
417
1176
|
return tracked.context === context;
|
|
418
1177
|
});
|
|
@@ -427,9 +1186,13 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
427
1186
|
cancelAnimationFrameImpl(scheduledFlushId);
|
|
428
1187
|
scheduledFlushId = undefined;
|
|
429
1188
|
}
|
|
430
|
-
|
|
1189
|
+
clearPendingBatches();
|
|
431
1190
|
fallbackModeContexts = new WeakSet();
|
|
1191
|
+
persistentFallbackModeContexts = new WeakSet();
|
|
432
1192
|
fallbackReasonByContext = new WeakMap();
|
|
1193
|
+
persistentFallbackReasonByContext = new WeakMap();
|
|
1194
|
+
expiredUnpublishedContexts = new WeakSet();
|
|
1195
|
+
rejectedContextSet = new WeakSet();
|
|
433
1196
|
opaqueObjectContextMap = new WeakMap();
|
|
434
1197
|
restorePatchedOpaqueObjects();
|
|
435
1198
|
while (trackedContexts.length) {
|
|
@@ -438,6 +1201,9 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
438
1201
|
while (patchedPrototypeRecords.length) {
|
|
439
1202
|
patchedPrototypeRecords.pop().restore();
|
|
440
1203
|
}
|
|
1204
|
+
trackedContextSet = new WeakSet();
|
|
1205
|
+
captureGenerationByContext = new WeakMap();
|
|
1206
|
+
objectRefRegistry.reset();
|
|
441
1207
|
}
|
|
442
1208
|
function pause() {
|
|
443
1209
|
paused = true;
|
|
@@ -445,26 +1211,60 @@ export function createCanvas2DCommandRecorder(options) {
|
|
|
445
1211
|
cancelAnimationFrameImpl(scheduledFlushId);
|
|
446
1212
|
scheduledFlushId = undefined;
|
|
447
1213
|
}
|
|
448
|
-
|
|
1214
|
+
clearPendingBatches();
|
|
449
1215
|
fallbackModeContexts = new WeakSet();
|
|
450
1216
|
fallbackReasonByContext = new WeakMap();
|
|
1217
|
+
rejectedContextSet = new WeakSet();
|
|
1218
|
+
objectRefRegistry.reset();
|
|
451
1219
|
}
|
|
452
1220
|
function resume() {
|
|
453
1221
|
paused = false;
|
|
454
1222
|
}
|
|
455
1223
|
function reset() {
|
|
1224
|
+
captureGeneration += 1;
|
|
456
1225
|
if (scheduledFlushId !== undefined) {
|
|
457
1226
|
cancelAnimationFrameImpl(scheduledFlushId);
|
|
458
1227
|
scheduledFlushId = undefined;
|
|
459
1228
|
}
|
|
460
|
-
|
|
1229
|
+
clearPendingBatches();
|
|
461
1230
|
fallbackModeContexts = new WeakSet();
|
|
462
1231
|
fallbackReasonByContext = new WeakMap();
|
|
1232
|
+
rejectedContextSet = new WeakSet();
|
|
1233
|
+
objectRefRegistry.reset();
|
|
1234
|
+
}
|
|
1235
|
+
function forceSnapshotFallback(context, reason) {
|
|
1236
|
+
if (stopped || !trackedContextSet.has(context)) {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
// An explicit authoritative rebaseline supersedes the implicit
|
|
1240
|
+
// canvas_state_reset transition for this generation.
|
|
1241
|
+
captureGenerationByContext.set(context, captureGeneration);
|
|
1242
|
+
expiredUnpublishedContexts["delete"](context);
|
|
1243
|
+
enableSnapshotFallbackForContext(context, reason || 'forced_snapshot_rebaseline', false, true);
|
|
1244
|
+
}
|
|
1245
|
+
function markPersistentSnapshotFallback(context, reason) {
|
|
1246
|
+
if (stopped || !trackedContextSet.has(context)) {
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
expiredUnpublishedContexts["delete"](context);
|
|
1250
|
+
persistentFallbackModeContexts.add(context);
|
|
1251
|
+
if (!persistentFallbackReasonByContext.has(context)) {
|
|
1252
|
+
persistentFallbackReasonByContext.set(context, reason || 'persistent_snapshot_fallback');
|
|
1253
|
+
}
|
|
1254
|
+
// The authoritative bitmap was already admitted by the caller. Only
|
|
1255
|
+
// retire command state here; requesting another snapshot would duplicate
|
|
1256
|
+
// the initial encode and increase startup work for every canvas.
|
|
1257
|
+
deletePendingBatch(context);
|
|
463
1258
|
}
|
|
464
1259
|
return {
|
|
465
1260
|
patchContext: patchContext,
|
|
466
1261
|
patchSharedPrototype: patchSharedPrototype,
|
|
1262
|
+
rejectContext: rejectContext,
|
|
1263
|
+
forceSnapshotFallback: forceSnapshotFallback,
|
|
1264
|
+
markPersistentSnapshotFallback: markPersistentSnapshotFallback,
|
|
467
1265
|
flush: flush,
|
|
1266
|
+
flushContext: flushContext,
|
|
1267
|
+
retryPublishedContext: retryPublishedContext,
|
|
468
1268
|
pause: pause,
|
|
469
1269
|
resume: resume,
|
|
470
1270
|
reset: reset,
|