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