@cloudcare/browser-rum 3.3.24 → 3.3.26

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 (209) hide show
  1. package/README.md +33 -0
  2. package/README.zh.md +30 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/disabledRumPublicApi.js +5 -0
  6. package/cjs/boot/disabledRumPublicApi.js.map +1 -1
  7. package/cjs/boot/initCallbacks.js +25 -0
  8. package/cjs/boot/initCallbacks.js.map +1 -0
  9. package/cjs/boot/perStartRum.js +99 -50
  10. package/cjs/boot/perStartRum.js.map +1 -1
  11. package/cjs/boot/recorderApi.js +36 -1
  12. package/cjs/boot/recorderApi.js.map +1 -1
  13. package/cjs/boot/rum.js +8 -9
  14. package/cjs/boot/rum.js.map +1 -1
  15. package/cjs/boot/rumPublicApi.js +6 -7
  16. package/cjs/boot/rumPublicApi.js.map +1 -1
  17. package/cjs/boot/startRecording.js +2 -0
  18. package/cjs/boot/startRecording.js.map +1 -1
  19. package/cjs/domain/configuration.js +15 -2
  20. package/cjs/domain/configuration.js.map +1 -1
  21. package/cjs/domain/contexts/urlContexts.js +32 -21
  22. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  23. package/cjs/domain/contexts/viewContexts.js +1 -1
  24. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  25. package/cjs/domain/deflate/deflateWorker.js +39 -27
  26. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  27. package/cjs/domain/privacy.js +79 -107
  28. package/cjs/domain/privacy.js.map +1 -1
  29. package/cjs/domain/replay/record/canvasCommandCapture.js +87 -179
  30. package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
  31. package/cjs/domain/replay/record/canvasCommandObserver.js +10 -6
  32. package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
  33. package/cjs/domain/replay/record/canvasCommandObserverStub.js +24 -0
  34. package/cjs/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  35. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +3 -2
  36. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  37. package/cjs/domain/replay/record/canvasContext.js +15 -0
  38. package/cjs/domain/replay/record/canvasContext.js.map +1 -1
  39. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  40. package/cjs/domain/replay/record/canvasObserver.js +3 -0
  41. package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
  42. package/cjs/domain/replay/record/canvasWebGLPluginHost.js +5 -1
  43. package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  44. package/cjs/domain/replay/record/mutationObserver.js +3 -12
  45. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  46. package/cjs/domain/replay/record/observers.js +3 -7
  47. package/cjs/domain/replay/record/observers.js.map +1 -1
  48. package/cjs/domain/replay/record/record.js +15 -2
  49. package/cjs/domain/replay/record/record.js.map +1 -1
  50. package/cjs/domain/replay/record/serializationUtils.js +8 -23
  51. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  52. package/cjs/domain/replay/record/serialize.js +19 -33
  53. package/cjs/domain/replay/record/serialize.js.map +1 -1
  54. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +21 -6
  55. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  56. package/cjs/domain/replay/segmentCollection/segmentCollection.js +91 -143
  57. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  58. package/cjs/domain/replayCanvasSupported.js +8 -0
  59. package/cjs/domain/replayCanvasSupported.js.map +1 -0
  60. package/cjs/domain/requestCollection.js +38 -39
  61. package/cjs/domain/requestCollection.js.map +1 -1
  62. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  63. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  64. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js +143 -0
  65. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  66. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  67. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  68. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +91 -66
  69. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js +11 -9
  71. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  72. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +35 -50
  73. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  74. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +7 -1
  75. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  76. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  77. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  78. package/cjs/domain/rumEventsCollection/view/trackViews.js +3 -0
  79. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  80. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
  81. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  82. package/cjs/domain/tracing/skywalkingTracer.js +4 -50
  83. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  84. package/cjs/domain/tracing/tracer.js +26 -3
  85. package/cjs/domain/tracing/tracer.js.map +1 -1
  86. package/esm/boot/buildEnv.js +1 -1
  87. package/esm/boot/disabledRumPublicApi.js +1 -1
  88. package/esm/boot/disabledRumPublicApi.js.map +1 -1
  89. package/esm/boot/initCallbacks.js +2 -0
  90. package/esm/boot/initCallbacks.js.map +1 -0
  91. package/esm/boot/perStartRum.js +1 -1
  92. package/esm/boot/perStartRum.js.map +1 -1
  93. package/esm/boot/recorderApi.js +1 -1
  94. package/esm/boot/recorderApi.js.map +1 -1
  95. package/esm/boot/rum.js +1 -1
  96. package/esm/boot/rum.js.map +1 -1
  97. package/esm/boot/rumPublicApi.js +1 -1
  98. package/esm/boot/rumPublicApi.js.map +1 -1
  99. package/esm/boot/startRecording.js +1 -1
  100. package/esm/boot/startRecording.js.map +1 -1
  101. package/esm/domain/configuration.js +1 -1
  102. package/esm/domain/configuration.js.map +1 -1
  103. package/esm/domain/contexts/urlContexts.js +1 -1
  104. package/esm/domain/contexts/urlContexts.js.map +1 -1
  105. package/esm/domain/contexts/viewContexts.js +1 -1
  106. package/esm/domain/contexts/viewContexts.js.map +1 -1
  107. package/esm/domain/deflate/deflateWorker.js +1 -1
  108. package/esm/domain/deflate/deflateWorker.js.map +1 -1
  109. package/esm/domain/privacy.js +1 -1
  110. package/esm/domain/privacy.js.map +1 -1
  111. package/esm/domain/replay/record/canvasCommandCapture.js +1 -1
  112. package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
  113. package/esm/domain/replay/record/canvasCommandObserver.js +1 -1
  114. package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
  115. package/esm/domain/replay/record/canvasCommandObserverStub.js +2 -0
  116. package/esm/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  117. package/esm/domain/replay/record/canvasCommandSerializeArgs.js +1 -1
  118. package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  119. package/esm/domain/replay/record/canvasContext.js +1 -1
  120. package/esm/domain/replay/record/canvasContext.js.map +1 -1
  121. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  122. package/esm/domain/replay/record/canvasObserver.js +1 -1
  123. package/esm/domain/replay/record/canvasObserver.js.map +1 -1
  124. package/esm/domain/replay/record/canvasWebGLPluginHost.js +1 -1
  125. package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  126. package/esm/domain/replay/record/mutationObserver.js +1 -1
  127. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  128. package/esm/domain/replay/record/observers.js +1 -1
  129. package/esm/domain/replay/record/observers.js.map +1 -1
  130. package/esm/domain/replay/record/record.js +1 -1
  131. package/esm/domain/replay/record/record.js.map +1 -1
  132. package/esm/domain/replay/record/serializationUtils.js +1 -1
  133. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  134. package/esm/domain/replay/record/serialize.js +1 -1
  135. package/esm/domain/replay/record/serialize.js.map +1 -1
  136. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  137. package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  138. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  139. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  140. package/esm/domain/replayCanvasSupported.js +2 -0
  141. package/esm/domain/replayCanvasSupported.js.map +1 -0
  142. package/esm/domain/requestCollection.js +1 -1
  143. package/esm/domain/requestCollection.js.map +1 -1
  144. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  145. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  146. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js +2 -0
  147. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  148. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +1 -1
  149. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  150. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  151. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  152. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +1 -1
  153. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  154. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +1 -1
  155. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  156. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +1 -1
  157. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  158. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  159. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  160. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  161. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  162. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
  163. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  164. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  165. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  166. package/esm/domain/tracing/tracer.js +1 -1
  167. package/esm/domain/tracing/tracer.js.map +1 -1
  168. package/package.json +7 -7
  169. package/src/boot/disabledRumPublicApi.js +5 -0
  170. package/src/boot/initCallbacks.js +16 -0
  171. package/src/boot/perStartRum.js +102 -59
  172. package/src/boot/recorderApi.js +51 -2
  173. package/src/boot/rum.js +12 -18
  174. package/src/boot/rumPublicApi.js +6 -8
  175. package/src/boot/startRecording.js +2 -0
  176. package/src/domain/configuration.js +13 -2
  177. package/src/domain/contexts/urlContexts.js +34 -27
  178. package/src/domain/contexts/viewContexts.js +2 -2
  179. package/src/domain/deflate/deflateWorker.js +35 -21
  180. package/src/domain/privacy.js +93 -157
  181. package/src/domain/replay/record/canvasCommandCapture.js +102 -239
  182. package/src/domain/replay/record/canvasCommandObserver.js +11 -18
  183. package/src/domain/replay/record/canvasCommandObserverStub.js +11 -0
  184. package/src/domain/replay/record/canvasCommandSerializeArgs.js +2 -2
  185. package/src/domain/replay/record/canvasContext.js +18 -0
  186. package/src/domain/replay/record/canvasObserver.js +5 -1
  187. package/src/domain/replay/record/canvasWebGLPluginHost.js +4 -1
  188. package/src/domain/replay/record/mutationObserver.js +6 -22
  189. package/src/domain/replay/record/observers.js +4 -8
  190. package/src/domain/replay/record/record.js +20 -5
  191. package/src/domain/replay/record/serializationUtils.js +10 -33
  192. package/src/domain/replay/record/serialize.js +30 -38
  193. package/src/domain/replay/segmentCollection/buildReplayPayload.js +24 -14
  194. package/src/domain/replay/segmentCollection/segmentCollection.js +97 -227
  195. package/src/domain/replayCanvasSupported.js +1 -0
  196. package/src/domain/requestCollection.js +39 -51
  197. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +8 -2
  198. package/src/domain/rumEventsCollection/resource/fetchTimingRegistry.js +138 -0
  199. package/src/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  200. package/src/domain/rumEventsCollection/resource/resourceCollection.js +103 -88
  201. package/src/domain/rumEventsCollection/resource/resourceTrackerManager.js +10 -10
  202. package/src/domain/rumEventsCollection/resource/resourceUtils.js +41 -69
  203. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +8 -2
  204. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  205. package/src/domain/rumEventsCollection/view/trackViews.js +3 -0
  206. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -3
  207. package/src/domain/tracing/skywalkingTracer.js +14 -91
  208. package/src/domain/tracing/tracer.js +28 -4
  209. package/types/index.d.ts +9 -0
@@ -1,5 +1,6 @@
1
- import { SDKMap } from '@cloudcare/browser-core'
2
- import { createCanvasCommandObjectRefRegistry } from './canvasCommandSerializeArgs'
1
+ import { isCanvasPrivate } from './canvasContext'
2
+ import { noop, SDKMap } from '@cloudcare/browser-core'
3
+ import { createCanvasCommandObjectRefRegistry, isSerializedTypedArray } from './canvasCommandSerializeArgs'
3
4
  import { createCanvasMutationRecord } from './canvasMutationRecord'
4
5
 
5
6
  var CANVAS_2D_CAPTURED_METHODS = [
@@ -69,7 +70,8 @@ var CANVAS_2D_CAPTURED_PROPERTIES = [
69
70
  'filter'
70
71
  ]
71
72
 
72
- var CANVAS_2D_NON_MUTATING_METHODS = {
73
+ // Known API members are handled separately from unknown canvas mutations.
74
+ var knownCanvasMembers = {
73
75
  createImageData: true,
74
76
  getContextAttributes: true,
75
77
  getImageData: true,
@@ -80,13 +82,8 @@ var CANVAS_2D_NON_MUTATING_METHODS = {
80
82
  isPointInStroke: true,
81
83
  measureText: true
82
84
  }
83
- var CANVAS_2D_CAPTURED_METHOD_NAMES = {}
84
- var CANVAS_2D_CAPTURED_PROPERTY_NAMES = {}
85
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
86
- CANVAS_2D_CAPTURED_METHOD_NAMES[methodName] = true
87
- })
88
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
89
- CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] = true
85
+ CANVAS_2D_CAPTURED_METHODS.concat(CANVAS_2D_CAPTURED_PROPERTIES).forEach(function (name) {
86
+ knownCanvasMembers[name] = true
90
87
  })
91
88
 
92
89
  var UNSUPPORTED_REPLAY_OBJECT_NAMES = {
@@ -243,20 +240,6 @@ function getTypedArrayElementApproxBytes(value) {
243
240
  return 25
244
241
  }
245
242
 
246
- function isSerializedTypedArray(value) {
247
- return (
248
- value instanceof Float32Array ||
249
- value instanceof Float64Array ||
250
- value instanceof Int32Array ||
251
- value instanceof Uint32Array ||
252
- value instanceof Uint8Array ||
253
- value instanceof Uint16Array ||
254
- value instanceof Int16Array ||
255
- value instanceof Int8Array ||
256
- value instanceof Uint8ClampedArray
257
- )
258
- }
259
-
260
243
  function addTypedArrayApproxBytes(state, value) {
261
244
  var elementCount = value.length
262
245
  var perElementBytes = getTypedArrayElementApproxBytes(value)
@@ -481,7 +464,8 @@ function isUnsupportedDrawImageSource(value) {
481
464
 
482
465
  export function createCanvas2DCommandRecorder(options) {
483
466
  options = options || {}
484
- var emit = options.emit || function () {}
467
+ var configuration = options.configuration || {}
468
+ var emit = options.emit || noop
485
469
  var now = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
486
470
  ? options.now || Date.now
487
471
  : Date.now
@@ -517,8 +501,6 @@ export function createCanvas2DCommandRecorder(options) {
517
501
  var snapshotFallbackPatchTargets = new WeakSet()
518
502
  var pendingCommandsByContext = new SDKMap()
519
503
  var pendingCommandApproxBytes = 0
520
- var fallbackModeContexts = new WeakSet()
521
- var persistentFallbackModeContexts = new WeakSet()
522
504
  var fallbackReasonByContext = new WeakMap()
523
505
  var persistentFallbackReasonByContext = new WeakMap()
524
506
  var expiredUnpublishedContexts = new WeakSet()
@@ -547,7 +529,7 @@ export function createCanvas2DCommandRecorder(options) {
547
529
  (__BUILD_ENV__REPLAY_DEBUG_ENABLED__ && options.objectRefRegistry) ||
548
530
  createCanvasCommandObjectRefRegistry()
549
531
  var onCommandOverflow = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
550
- ? options.onCommandOverflow || function () {}
532
+ ? options.onCommandOverflow || noop
551
533
  : undefined
552
534
  var getCanvasId =
553
535
  options.getCanvasId ||
@@ -560,11 +542,11 @@ export function createCanvas2DCommandRecorder(options) {
560
542
  return '2D'
561
543
  }
562
544
  var requestSnapshotFallback =
563
- options.requestSnapshotFallback || function () {}
545
+ options.requestSnapshotFallback || noop
564
546
  var onContextDiscovered =
565
- options.onContextDiscovered || function () {}
547
+ options.onContextDiscovered || noop
566
548
  var onContextMutation =
567
- options.onContextMutation || function () {}
549
+ options.onContextMutation || noop
568
550
  var shouldRecordContext =
569
551
  options.shouldRecordContext ||
570
552
  function () {
@@ -616,8 +598,8 @@ export function createCanvas2DCommandRecorder(options) {
616
598
 
617
599
  function isSnapshotFallbackContext(context) {
618
600
  return (
619
- fallbackModeContexts.has(context) ||
620
- persistentFallbackModeContexts.has(context)
601
+ fallbackReasonByContext.has(context) ||
602
+ persistentFallbackReasonByContext.has(context)
621
603
  )
622
604
  }
623
605
 
@@ -656,7 +638,6 @@ export function createCanvas2DCommandRecorder(options) {
656
638
 
657
639
  function expireUnpublishedBatch(context) {
658
640
  deletePendingBatch(context)
659
- persistentFallbackModeContexts.add(context)
660
641
  expiredUnpublishedContexts.add(context)
661
642
  if (!persistentFallbackReasonByContext.has(context)) {
662
643
  persistentFallbackReasonByContext.set(
@@ -917,11 +898,21 @@ export function createCanvas2DCommandRecorder(options) {
917
898
  scheduleFlush()
918
899
  }
919
900
 
901
+ function discardPrivateCommands(context) {
902
+ if (!isCanvasPrivate(context.canvas, configuration)) return false
903
+ // Private draws change the live bitmap. Resume from pixels when allowed.
904
+ if (!persistentFallbackReasonByContext.has(context) || pendingCommandsByContext.has(context)) {
905
+ markPersistentSnapshotFallback(context, 'canvas_state_reset')
906
+ }
907
+ return true
908
+ }
909
+
920
910
  function flushPendingContext(context, flushedAt) {
921
911
  var batch = pendingCommandsByContext.get(context)
922
912
  if (!batch) {
923
913
  return
924
914
  }
915
+ if (discardPrivateCommands(context)) return
925
916
  if (isSnapshotFallbackContext(context)) {
926
917
  if (batch.fallbackDirty && !batch.fallbackSnapshotRequested) {
927
918
  requestSnapshotFallback(
@@ -1034,6 +1025,7 @@ export function createCanvas2DCommandRecorder(options) {
1034
1025
  if (!trackedContextSet.has(context)) {
1035
1026
  return false
1036
1027
  }
1028
+ if (discardPrivateCommands(context)) return false
1037
1029
  if (captureGenerationByContext.get(context) !== captureGeneration) {
1038
1030
  captureGenerationByContext.set(context, captureGeneration)
1039
1031
  // reset() accompanies a new replay/full-snapshot canvas baseline, but
@@ -1049,6 +1041,14 @@ export function createCanvas2DCommandRecorder(options) {
1049
1041
  return true
1050
1042
  }
1051
1043
 
1044
+ function clearContext(context) {
1045
+ trackedContextSet.delete(context)
1046
+ deletePendingBatch(context)
1047
+ expiredUnpublishedContexts.delete(context)
1048
+ fallbackReasonByContext.delete(context)
1049
+ persistentFallbackReasonByContext.delete(context)
1050
+ }
1051
+
1052
1052
  function registerTrackedContext(context, restoreFns) {
1053
1053
  if (!context || trackedContextSet.has(context)) {
1054
1054
  return false
@@ -1067,13 +1067,7 @@ export function createCanvas2DCommandRecorder(options) {
1067
1067
  trackedContexts.push({
1068
1068
  context: context,
1069
1069
  restore: function () {
1070
- trackedContextSet.delete(context)
1071
- deletePendingBatch(context)
1072
- expiredUnpublishedContexts.delete(context)
1073
- fallbackModeContexts.delete(context)
1074
- persistentFallbackModeContexts.delete(context)
1075
- fallbackReasonByContext.delete(context)
1076
- persistentFallbackReasonByContext.delete(context)
1070
+ clearContext(context)
1077
1071
  while (restoreFns.length) {
1078
1072
  restoreFns.pop()()
1079
1073
  }
@@ -1096,7 +1090,7 @@ export function createCanvas2DCommandRecorder(options) {
1096
1090
  return false
1097
1091
  }
1098
1092
  if (shouldRecordContext(context) === false) {
1099
- rejectedContextSet.add(context)
1093
+ rejectContext(context)
1100
1094
  return false
1101
1095
  }
1102
1096
  if (!registerTrackedContext(context, [])) {
@@ -1138,14 +1132,10 @@ export function createCanvas2DCommandRecorder(options) {
1138
1132
  if (!context) {
1139
1133
  return
1140
1134
  }
1135
+ // A hidden region can become visible while the same context stays alive.
1136
+ if (discardPrivateCommands(context)) return
1141
1137
  rejectedContextSet.add(context)
1142
- trackedContextSet.delete(context)
1143
- deletePendingBatch(context)
1144
- expiredUnpublishedContexts.delete(context)
1145
- fallbackModeContexts.delete(context)
1146
- persistentFallbackModeContexts.delete(context)
1147
- fallbackReasonByContext.delete(context)
1148
- persistentFallbackReasonByContext.delete(context)
1138
+ clearContext(context)
1149
1139
  }
1150
1140
 
1151
1141
  function enableSnapshotFallbackForContext(
@@ -1154,13 +1144,9 @@ export function createCanvas2DCommandRecorder(options) {
1154
1144
  isGlobalOverflow,
1155
1145
  persistent
1156
1146
  ) {
1157
- var fallbackContexts = persistent
1158
- ? persistentFallbackModeContexts
1159
- : fallbackModeContexts
1160
1147
  var fallbackReasons = persistent
1161
1148
  ? persistentFallbackReasonByContext
1162
1149
  : fallbackReasonByContext
1163
- fallbackContexts.add(context)
1164
1150
  if (!fallbackReasons.has(context)) {
1165
1151
  fallbackReasons.set(
1166
1152
  context,
@@ -1314,6 +1300,41 @@ export function createCanvas2DCommandRecorder(options) {
1314
1300
  }
1315
1301
  }
1316
1302
 
1303
+ function recordMutation(context, name, argsOrValue, setter, alwaysSnapshotFallback) {
1304
+ notifyContextMutation(context)
1305
+ try {
1306
+ if (isSnapshotFallbackContext(context)) {
1307
+ markSnapshotFallbackDirty(context)
1308
+ return false
1309
+ }
1310
+ if (alwaysSnapshotFallback) {
1311
+ enableSnapshotFallbackForContext(
1312
+ context,
1313
+ setter ? 'unsupported_canvas_property' : 'unsupported_canvas_method',
1314
+ false,
1315
+ true
1316
+ )
1317
+ return false
1318
+ }
1319
+ } catch (_) {
1320
+ return false
1321
+ }
1322
+
1323
+ try {
1324
+ var reason = !setter && name === 'drawImage' && isUnsupportedDrawImageSource(argsOrValue[0])
1325
+ if (reason) {
1326
+ enableSnapshotFallbackForContext(context, reason)
1327
+ } else {
1328
+ captureCommand(context, name, setter ? [argsOrValue] : argsOrValue, setter)
1329
+ }
1330
+ } catch (_) {
1331
+ try {
1332
+ enableSnapshotFallbackForContext(context, 'command_serialization_error')
1333
+ } catch (_) {}
1334
+ }
1335
+ return true
1336
+ }
1337
+
1317
1338
  function patchMethodOnTarget(
1318
1339
  target,
1319
1340
  methodName,
@@ -1328,55 +1349,9 @@ export function createCanvas2DCommandRecorder(options) {
1328
1349
  maybeTrackContext(this)
1329
1350
  var shouldCapture = shouldCaptureContext(this)
1330
1351
  var result = originalMethod.apply(this, arguments)
1331
- if (shouldCapture) {
1332
- notifyContextMutation(this)
1333
- }
1334
- if (shouldCapture && alwaysSnapshotFallback) {
1335
- try {
1336
- if (isSnapshotFallbackContext(this)) {
1337
- markSnapshotFallbackDirty(this)
1338
- } else {
1339
- enableSnapshotFallbackForContext(
1340
- this,
1341
- 'unsupported_canvas_method',
1342
- false,
1343
- true
1344
- )
1345
- }
1346
- } catch (_) {}
1347
- return result
1348
- }
1349
- if (shouldCapture && isSnapshotFallbackContext(this)) {
1350
- try {
1351
- markSnapshotFallbackDirty(this)
1352
- } catch (_) {}
1353
- return result
1354
- }
1355
- if (shouldCapture) {
1356
- try {
1357
- var drawImageFallbackReason =
1358
- methodName === 'drawImage'
1359
- ? isUnsupportedDrawImageSource(arguments[0])
1360
- : undefined
1361
- if (drawImageFallbackReason) {
1362
- enableSnapshotFallbackForContext(
1363
- this,
1364
- drawImageFallbackReason
1365
- )
1366
- } else {
1367
- captureCommand(this, methodName, arguments, false)
1368
- }
1369
- } catch (_) {
1370
- try {
1371
- enableSnapshotFallbackForContext(
1372
- this,
1373
- 'command_serialization_error'
1374
- )
1375
- } catch (_) {}
1376
- }
1377
- }
1378
1352
  if (
1379
1353
  shouldCapture &&
1354
+ recordMutation(this, methodName, arguments, false, alwaysSnapshotFallback) &&
1380
1355
  (methodName === 'createLinearGradient' ||
1381
1356
  methodName === 'createRadialGradient' ||
1382
1357
  methodName === 'createConicGradient')
@@ -1424,40 +1399,8 @@ export function createCanvas2DCommandRecorder(options) {
1424
1399
  if (originalDescriptor && originalDescriptor.set) {
1425
1400
  originalDescriptor.set.call(this, value)
1426
1401
  }
1427
- var shouldCapture = shouldCaptureContext(this)
1428
- if (shouldCapture) {
1429
- notifyContextMutation(this)
1430
- if (alwaysSnapshotFallback) {
1431
- try {
1432
- if (isSnapshotFallbackContext(this)) {
1433
- markSnapshotFallbackDirty(this)
1434
- } else {
1435
- enableSnapshotFallbackForContext(
1436
- this,
1437
- 'unsupported_canvas_property',
1438
- false,
1439
- true
1440
- )
1441
- }
1442
- } catch (_) {}
1443
- return
1444
- }
1445
- if (isSnapshotFallbackContext(this)) {
1446
- try {
1447
- markSnapshotFallbackDirty(this)
1448
- } catch (_) {}
1449
- return
1450
- }
1451
- try {
1452
- captureCommand(this, propertyName, [value], true)
1453
- } catch (_) {
1454
- try {
1455
- enableSnapshotFallbackForContext(
1456
- this,
1457
- 'command_serialization_error'
1458
- )
1459
- } catch (_) {}
1460
- }
1402
+ if (shouldCaptureContext(this)) {
1403
+ recordMutation(this, propertyName, value, true, alwaysSnapshotFallback)
1461
1404
  }
1462
1405
  }
1463
1406
  try {
@@ -1500,12 +1443,7 @@ export function createCanvas2DCommandRecorder(options) {
1500
1443
  return
1501
1444
  }
1502
1445
  propertyNames.forEach(function (propertyName) {
1503
- if (
1504
- propertyName === 'constructor' ||
1505
- CANVAS_2D_CAPTURED_METHOD_NAMES[propertyName] ||
1506
- CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] ||
1507
- CANVAS_2D_NON_MUTATING_METHODS[propertyName]
1508
- ) {
1446
+ if (propertyName === 'constructor' || knownCanvasMembers[propertyName]) {
1509
1447
  return
1510
1448
  }
1511
1449
  var descriptor
@@ -1546,54 +1484,6 @@ export function createCanvas2DCommandRecorder(options) {
1546
1484
  })
1547
1485
  }
1548
1486
 
1549
- function patchPrototype(context) {
1550
- var prototype = Object.getPrototypeOf(context)
1551
- if (!prototype || prototype === Object.prototype) {
1552
- return false
1553
- }
1554
- var existingRecord = patchedPrototypeRecords.find(function (record) {
1555
- return record.prototype === prototype
1556
- })
1557
- if (existingRecord) {
1558
- return true
1559
- }
1560
- if (
1561
- patchedPrototypeRecords.length >=
1562
- MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS
1563
- ) {
1564
- return false
1565
- }
1566
-
1567
- var restoreFns = []
1568
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1569
- if (
1570
- typeof prototype[methodName] === 'function' &&
1571
- !patchMethodOnTarget(prototype, methodName, restoreFns)
1572
- ) {
1573
- snapshotFallbackPatchTargets.add(prototype)
1574
- }
1575
- })
1576
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1577
- if (
1578
- getPropertyDescriptor(prototype, propertyName) &&
1579
- !patchPropertyOnTarget(prototype, propertyName, restoreFns)
1580
- ) {
1581
- snapshotFallbackPatchTargets.add(prototype)
1582
- }
1583
- })
1584
- patchUnknownMutationsOnTarget(prototype, restoreFns)
1585
-
1586
- patchedPrototypeRecords.push({
1587
- prototype: prototype,
1588
- restore: function () {
1589
- while (restoreFns.length) {
1590
- restoreFns.pop()()
1591
- }
1592
- }
1593
- })
1594
- return true
1595
- }
1596
-
1597
1487
  function patchSharedPrototype(prototype) {
1598
1488
  if (!prototype || prototype === Object.prototype) {
1599
1489
  return false
@@ -1612,23 +1502,7 @@ export function createCanvas2DCommandRecorder(options) {
1612
1502
  }
1613
1503
 
1614
1504
  var restoreFns = []
1615
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1616
- if (
1617
- typeof prototype[methodName] === 'function' &&
1618
- !patchMethodOnTarget(prototype, methodName, restoreFns)
1619
- ) {
1620
- snapshotFallbackPatchTargets.add(prototype)
1621
- }
1622
- })
1623
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1624
- if (
1625
- getPropertyDescriptor(prototype, propertyName) &&
1626
- !patchPropertyOnTarget(prototype, propertyName, restoreFns)
1627
- ) {
1628
- snapshotFallbackPatchTargets.add(prototype)
1629
- }
1630
- })
1631
- patchUnknownMutationsOnTarget(prototype, restoreFns)
1505
+ patchContextTarget(prototype, restoreFns, true)
1632
1506
 
1633
1507
  patchedPrototypeRecords.push({
1634
1508
  prototype: prototype,
@@ -1641,44 +1515,47 @@ export function createCanvas2DCommandRecorder(options) {
1641
1515
  return true
1642
1516
  }
1643
1517
 
1644
- function patchContextInstance(context, restoreFns) {
1518
+ function patchContextTarget(target, restoreFns, isPrototype) {
1645
1519
  CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1646
1520
  if (
1647
- typeof context[methodName] === 'function' &&
1648
- !patchMethodOnTarget(context, methodName, restoreFns)
1521
+ typeof target[methodName] === 'function' &&
1522
+ !patchMethodOnTarget(target, methodName, restoreFns)
1649
1523
  ) {
1650
- snapshotFallbackPatchTargets.add(context)
1524
+ snapshotFallbackPatchTargets.add(target)
1651
1525
  }
1652
1526
  })
1653
1527
 
1654
1528
  CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1655
- if (!patchPropertyOnTarget(context, propertyName, restoreFns)) {
1656
- snapshotFallbackPatchTargets.add(context)
1529
+ if (
1530
+ (!isPrototype || getPropertyDescriptor(target, propertyName)) &&
1531
+ !patchPropertyOnTarget(target, propertyName, restoreFns)
1532
+ ) {
1533
+ snapshotFallbackPatchTargets.add(target)
1657
1534
  }
1658
1535
  })
1659
- patchUnknownMutationsOnTarget(context, restoreFns)
1536
+ patchUnknownMutationsOnTarget(target, restoreFns)
1660
1537
  }
1661
1538
 
1662
1539
  function patchContext(context) {
1663
1540
  if (stopped || !context || trackedContextSet.has(context)) {
1664
- return function () {}
1541
+ return noop
1665
1542
  }
1666
1543
 
1667
1544
  var restoreFns = []
1668
1545
  var prototype = Object.getPrototypeOf(context)
1669
1546
  if (prototype && prototype !== Object.prototype) {
1670
- if (!patchPrototype(context)) {
1671
- return function () {}
1547
+ if (!patchSharedPrototype(prototype)) {
1548
+ return noop
1672
1549
  }
1673
1550
  } else {
1674
- patchContextInstance(context, restoreFns)
1551
+ patchContextTarget(context, restoreFns, false)
1675
1552
  }
1676
1553
 
1677
1554
  if (!registerTrackedContext(context, restoreFns)) {
1678
1555
  while (restoreFns.length) {
1679
1556
  restoreFns.pop()()
1680
1557
  }
1681
- return function () {}
1558
+ return noop
1682
1559
  }
1683
1560
  if (
1684
1561
  snapshotFallbackPatchTargets.has(context) ||
@@ -1693,13 +1570,7 @@ export function createCanvas2DCommandRecorder(options) {
1693
1570
  }
1694
1571
 
1695
1572
  return function () {
1696
- trackedContextSet.delete(context)
1697
- deletePendingBatch(context)
1698
- expiredUnpublishedContexts.delete(context)
1699
- fallbackModeContexts.delete(context)
1700
- persistentFallbackModeContexts.delete(context)
1701
- fallbackReasonByContext.delete(context)
1702
- persistentFallbackReasonByContext.delete(context)
1573
+ clearContext(context)
1703
1574
  var trackedIndex = trackedContexts.findIndex(function (tracked) {
1704
1575
  return tracked.context === context
1705
1576
  })
@@ -1716,8 +1587,6 @@ export function createCanvas2DCommandRecorder(options) {
1716
1587
  scheduledFlushId = undefined
1717
1588
  }
1718
1589
  clearPendingBatches()
1719
- fallbackModeContexts = new WeakSet()
1720
- persistentFallbackModeContexts = new WeakSet()
1721
1590
  fallbackReasonByContext = new WeakMap()
1722
1591
  persistentFallbackReasonByContext = new WeakMap()
1723
1592
  expiredUnpublishedContexts = new WeakSet()
@@ -1735,34 +1604,29 @@ export function createCanvas2DCommandRecorder(options) {
1735
1604
  objectRefRegistry.reset()
1736
1605
  }
1737
1606
 
1738
- function pause() {
1739
- paused = true
1607
+ function resetPendingCapture() {
1740
1608
  if (scheduledFlushId !== undefined) {
1741
1609
  cancelAnimationFrameImpl(scheduledFlushId)
1742
1610
  scheduledFlushId = undefined
1743
1611
  }
1744
1612
  clearPendingBatches()
1745
- fallbackModeContexts = new WeakSet()
1746
1613
  fallbackReasonByContext = new WeakMap()
1747
1614
  rejectedContextSet = new WeakSet()
1748
1615
  objectRefRegistry.reset()
1749
1616
  }
1750
1617
 
1618
+ function pause() {
1619
+ paused = true
1620
+ resetPendingCapture()
1621
+ }
1622
+
1751
1623
  function resume() {
1752
1624
  paused = false
1753
1625
  }
1754
1626
 
1755
1627
  function reset() {
1756
1628
  captureGeneration += 1
1757
- if (scheduledFlushId !== undefined) {
1758
- cancelAnimationFrameImpl(scheduledFlushId)
1759
- scheduledFlushId = undefined
1760
- }
1761
- clearPendingBatches()
1762
- fallbackModeContexts = new WeakSet()
1763
- fallbackReasonByContext = new WeakMap()
1764
- rejectedContextSet = new WeakSet()
1765
- objectRefRegistry.reset()
1629
+ resetPendingCapture()
1766
1630
  }
1767
1631
 
1768
1632
  function forceSnapshotFallback(context, reason) {
@@ -1786,7 +1650,6 @@ export function createCanvas2DCommandRecorder(options) {
1786
1650
  return
1787
1651
  }
1788
1652
  expiredUnpublishedContexts.delete(context)
1789
- persistentFallbackModeContexts.add(context)
1790
1653
  if (!persistentFallbackReasonByContext.has(context)) {
1791
1654
  persistentFallbackReasonByContext.set(
1792
1655
  context,
@@ -54,6 +54,10 @@ export function startCanvasCommandCapture(options) {
54
54
  }
55
55
  }
56
56
 
57
+ function getRecordingDecision(canvas) {
58
+ return getReplayCanvasRecordingDecision(configuration, canvas)
59
+ }
60
+
57
61
  var emit = options.emit
58
62
  var now = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
59
63
  ? options.now || Date.now
@@ -737,10 +741,7 @@ export function startCanvasCommandCapture(options) {
737
741
  return
738
742
  }
739
743
 
740
- var recordingDecision = getReplayCanvasRecordingDecision(
741
- configuration,
742
- canvas
743
- )
744
+ var recordingDecision = getRecordingDecision(canvas)
744
745
  if (recordingDecision === false) {
745
746
  state.$rDirty = false
746
747
  state.$rReason = undefined
@@ -904,10 +905,7 @@ export function startCanvasCommandCapture(options) {
904
905
  }
905
906
  var canvas = context.canvas
906
907
  var state = getFallbackState(canvas)
907
- var recordingDecision = getReplayCanvasRecordingDecision(
908
- configuration,
909
- canvas
910
- )
908
+ var recordingDecision = getRecordingDecision(canvas)
911
909
  if (recordingDecision === false) {
912
910
  clearFallbackTimer(state)
913
911
  state.$rDirty = false
@@ -1002,15 +1000,13 @@ export function startCanvasCommandCapture(options) {
1002
1000
  var recorder =
1003
1001
  (__BUILD_ENV__REPLAY_DEBUG_ENABLED__ && options.commandRecorder) ||
1004
1002
  createCanvas2DCommandRecorder({
1003
+ configuration: configuration,
1005
1004
  shouldRecordContext: function (context) {
1006
1005
  return (
1007
1006
  context &&
1008
1007
  context.canvas &&
1009
1008
  !isReplayInternalCanvas(context.canvas) &&
1010
- getReplayCanvasRecordingDecision(
1011
- configuration,
1012
- context.canvas
1013
- ) !== false
1009
+ getRecordingDecision(context.canvas) !== false
1014
1010
  )
1015
1011
  },
1016
1012
  getCanvasId: function (context) {
@@ -1360,7 +1356,7 @@ export function startCanvasCommandCapture(options) {
1360
1356
  foundUnseenCanvas = true
1361
1357
  if (
1362
1358
  stopped ||
1363
- getReplayCanvasRecordingDecision(configuration, canvas) === false
1359
+ getRecordingDecision(canvas) === false
1364
1360
  ) {
1365
1361
  return
1366
1362
  }
@@ -1474,10 +1470,7 @@ export function startCanvasCommandCapture(options) {
1474
1470
  continue
1475
1471
  }
1476
1472
  canvasId = getSerializedNodeId(canvas)
1477
- recordingDecision = getReplayCanvasRecordingDecision(
1478
- configuration,
1479
- canvas
1480
- )
1473
+ recordingDecision = getRecordingDecision(canvas)
1481
1474
  if (
1482
1475
  (!canvasId && canvasId !== 0) ||
1483
1476
  initialSnapshotCanvases.has(canvas) ||
@@ -1639,7 +1632,7 @@ export function startCanvasCommandCapture(options) {
1639
1632
  !isReplayInternalCanvas(this)
1640
1633
  if (
1641
1634
  shouldRecordContext &&
1642
- getReplayCanvasRecordingDecision(configuration, this) === false
1635
+ getRecordingDecision(this) === false
1643
1636
  ) {
1644
1637
  shouldRecordContext = false
1645
1638
  }
@@ -0,0 +1,11 @@
1
+ import { noop } from '@cloudcare/browser-core'
2
+
3
+ export const replayCanvasSupported = false
4
+
5
+ export function startCanvasCommandCapture() {
6
+ return { flush: noop, reset: noop, stop: noop }
7
+ }
8
+
9
+ export function startContinuousCanvasSnapshotLoop() {
10
+ return { reset: noop, stop: noop }
11
+ }
@@ -8,7 +8,7 @@ function arrayBufferToBase64(buffer) {
8
8
  return btoa(binary)
9
9
  }
10
10
 
11
- function isTypedArray(value) {
11
+ export function isSerializedTypedArray(value) {
12
12
  return (
13
13
  value instanceof Float32Array ||
14
14
  value instanceof Float64Array ||
@@ -39,7 +39,7 @@ function serializeCanvasCommandArgWithRegistry(value, context, registry) {
39
39
  return value
40
40
  }
41
41
 
42
- if (isTypedArray(value)) {
42
+ if (isSerializedTypedArray(value)) {
43
43
  return {
44
44
  rr_type: value.constructor.name,
45
45
  args: [Array.prototype.slice.call(value)]