@cloudcare/browser-rum 3.3.23 → 3.3.24

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