@cloudcare/browser-rum 3.3.6 → 3.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/README.md +24 -3
  2. package/README.zh.md +19 -3
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/buildEnv.js.map +1 -1
  6. package/cjs/boot/perStartRum.js.map +1 -1
  7. package/cjs/boot/recorderApi.js +170 -200
  8. package/cjs/boot/recorderApi.js.map +1 -1
  9. package/cjs/boot/recorderApiStub.js +3 -29
  10. package/cjs/boot/recorderApiStub.js.map +1 -1
  11. package/cjs/boot/rum.entry.js.map +1 -1
  12. package/cjs/boot/rum.js.map +1 -1
  13. package/cjs/boot/rum.slim.entry.js.map +1 -1
  14. package/cjs/boot/rumEntryFactory.js.map +1 -1
  15. package/cjs/boot/rumPublicApi.js.map +1 -1
  16. package/cjs/boot/rumRecorderApiStub.js.map +1 -1
  17. package/cjs/boot/rumSlimConfiguration.js.map +1 -1
  18. package/cjs/boot/sessionReplayPublicApi.js +14 -27
  19. package/cjs/boot/sessionReplayPublicApi.js.map +1 -1
  20. package/cjs/boot/startRecording.js +333 -108
  21. package/cjs/boot/startRecording.js.map +1 -1
  22. package/cjs/constants.js.map +1 -1
  23. package/cjs/domain/assembly.js +1 -7
  24. package/cjs/domain/assembly.js.map +1 -1
  25. package/cjs/domain/configuration.js +31 -43
  26. package/cjs/domain/configuration.js.map +1 -1
  27. package/cjs/domain/contexts/commonContext.js.map +1 -1
  28. package/cjs/domain/contexts/displayContext.js.map +1 -1
  29. package/cjs/domain/contexts/foregroundContexts.js.map +1 -1
  30. package/cjs/domain/contexts/internalContext.js.map +1 -1
  31. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  32. package/cjs/domain/contexts/urlContexts.js +10 -1
  33. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  34. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  35. package/cjs/domain/deflate/deflateEncoder.js +517 -39
  36. package/cjs/domain/deflate/deflateEncoder.js.map +1 -1
  37. package/cjs/domain/deflate/deflateWorker.js +194 -115
  38. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  39. package/cjs/domain/deflate/index.js.map +1 -1
  40. package/cjs/domain/domMutationObservable.js.map +1 -1
  41. package/cjs/domain/encoderStreamId.js.map +1 -1
  42. package/cjs/domain/firstInputPolyfill.js.map +1 -1
  43. package/cjs/domain/initViewportObservable.js.map +1 -1
  44. package/cjs/domain/locationChangeObservable.js.map +1 -1
  45. package/cjs/domain/performanceObservable.js.map +1 -1
  46. package/cjs/domain/performanceUtils.js.map +1 -1
  47. package/cjs/domain/plugins.js.map +1 -1
  48. package/cjs/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
  49. package/cjs/domain/replay/record/canvasCommandCapture.js +968 -167
  50. package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
  51. package/cjs/domain/replay/record/canvasCommandObserver.js +1058 -119
  52. package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
  53. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +61 -37
  54. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  55. package/cjs/domain/replay/record/canvasContext.js +63 -0
  56. package/cjs/domain/replay/record/canvasContext.js.map +1 -0
  57. package/cjs/domain/replay/record/canvasContinuousScheduler.js +246 -118
  58. package/cjs/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
  59. package/cjs/domain/replay/record/canvasEncodeBridge.js +539 -87
  60. package/cjs/domain/replay/record/canvasEncodeBridge.js.map +1 -1
  61. package/cjs/domain/replay/record/canvasEncodeWorker.js +50 -32
  62. package/cjs/domain/replay/record/canvasEncodeWorker.js.map +1 -1
  63. package/cjs/domain/replay/record/canvasFrameSignature.js +49 -17
  64. package/cjs/domain/replay/record/canvasFrameSignature.js.map +1 -1
  65. package/cjs/domain/replay/record/canvasMutationRecord.js.map +1 -1
  66. package/cjs/domain/replay/record/canvasObserver.js +295 -59
  67. package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
  68. package/cjs/domain/replay/record/canvasSerializeArgs.js.map +1 -1
  69. package/cjs/domain/replay/record/canvasWebGLPluginHost.js +33 -0
  70. package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
  71. package/cjs/domain/replay/record/elementsScrollPositions.js +3 -0
  72. package/cjs/domain/replay/record/elementsScrollPositions.js.map +1 -1
  73. package/cjs/domain/replay/record/index.js.map +1 -1
  74. package/cjs/domain/replay/record/mutationBatch.js +542 -25
  75. package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
  76. package/cjs/domain/replay/record/mutationObserver.js +1900 -191
  77. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  78. package/cjs/domain/replay/record/mutationResourceBudget.js +144 -0
  79. package/cjs/domain/replay/record/mutationResourceBudget.js.map +1 -0
  80. package/cjs/domain/replay/record/observers.js +222 -53
  81. package/cjs/domain/replay/record/observers.js.map +1 -1
  82. package/cjs/domain/replay/record/privacy.js +31 -8
  83. package/cjs/domain/replay/record/privacy.js.map +1 -1
  84. package/cjs/domain/replay/record/record.js +3083 -321
  85. package/cjs/domain/replay/record/record.js.map +1 -1
  86. package/cjs/domain/replay/record/serializationUtils.js +426 -26
  87. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  88. package/cjs/domain/replay/record/serialize.js +259 -49
  89. package/cjs/domain/replay/record/serialize.js.map +1 -1
  90. package/cjs/domain/replay/record/shadowRootsController.js +875 -21
  91. package/cjs/domain/replay/record/shadowRootsController.js.map +1 -1
  92. package/cjs/domain/replay/record/utils.js.map +1 -1
  93. package/cjs/domain/replay/record/viewports.js.map +1 -1
  94. package/cjs/domain/replay/replayStats.js.map +1 -1
  95. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  96. package/cjs/domain/replay/segmentCollection/index.js.map +1 -1
  97. package/cjs/domain/replay/segmentCollection/segment.js +315 -11
  98. package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
  99. package/cjs/domain/replay/segmentCollection/segmentCollection.js +956 -71
  100. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  101. package/cjs/domain/replay/startRecordBridge.js.map +1 -1
  102. package/cjs/domain/requestCollection.js.map +1 -1
  103. package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  104. package/cjs/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
  105. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
  106. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  107. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  108. package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
  109. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  110. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  111. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  112. package/cjs/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
  113. package/cjs/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
  114. package/cjs/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
  115. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  116. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  117. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  118. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  119. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  120. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  121. package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
  122. package/cjs/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
  123. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  124. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  125. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  126. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  127. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  128. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  129. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  130. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  131. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  132. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  133. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  134. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  135. package/cjs/domain/rumEventsCollection/view/trackViews.js +29 -11
  136. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  137. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  138. package/cjs/domain/rumSessionManager.js.map +1 -1
  139. package/cjs/domain/tracing/ddtraceTracer.js.map +1 -1
  140. package/cjs/domain/tracing/getDocumentTraceId.js.map +1 -1
  141. package/cjs/domain/tracing/jaegerTracer.js.map +1 -1
  142. package/cjs/domain/tracing/sampler.js.map +1 -1
  143. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  144. package/cjs/domain/tracing/traceIdentifier.js.map +1 -1
  145. package/cjs/domain/tracing/tracer.js +2 -2
  146. package/cjs/domain/tracing/tracer.js.map +1 -1
  147. package/cjs/domain/tracing/w3cTraceParentTracer.js.map +1 -1
  148. package/cjs/domain/tracing/zipkinMultiTracer.js.map +1 -1
  149. package/cjs/domain/tracing/zipkinSingleTracer.js.map +1 -1
  150. package/cjs/domain/trackEventCounts.js.map +1 -1
  151. package/cjs/domain/usr/index.js.map +1 -1
  152. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  153. package/cjs/index.js.map +1 -1
  154. package/cjs/transport/startRumBatch.js +3 -1
  155. package/cjs/transport/startRumBatch.js.map +1 -1
  156. package/cjs/transport/startRumEventBridge.js.map +1 -1
  157. package/cjs/types/index.js.map +1 -1
  158. package/cjs/types/sessionReplayConstants.js.map +1 -1
  159. package/esm/boot/buildEnv.js +1 -1
  160. package/esm/boot/buildEnv.js.map +1 -1
  161. package/esm/boot/perStartRum.js.map +1 -1
  162. package/esm/boot/recorderApi.js +172 -202
  163. package/esm/boot/recorderApi.js.map +1 -1
  164. package/esm/boot/recorderApiStub.js +3 -29
  165. package/esm/boot/recorderApiStub.js.map +1 -1
  166. package/esm/boot/rum.entry.js.map +1 -1
  167. package/esm/boot/rum.js.map +1 -1
  168. package/esm/boot/rum.slim.entry.js.map +1 -1
  169. package/esm/boot/rumEntryFactory.js.map +1 -1
  170. package/esm/boot/rumPublicApi.js.map +1 -1
  171. package/esm/boot/rumRecorderApiStub.js.map +1 -1
  172. package/esm/boot/rumSlimConfiguration.js.map +1 -1
  173. package/esm/boot/sessionReplayPublicApi.js +14 -27
  174. package/esm/boot/sessionReplayPublicApi.js.map +1 -1
  175. package/esm/boot/startRecording.js +334 -109
  176. package/esm/boot/startRecording.js.map +1 -1
  177. package/esm/constants.js.map +1 -1
  178. package/esm/domain/assembly.js +1 -7
  179. package/esm/domain/assembly.js.map +1 -1
  180. package/esm/domain/configuration.js +31 -43
  181. package/esm/domain/configuration.js.map +1 -1
  182. package/esm/domain/contexts/commonContext.js.map +1 -1
  183. package/esm/domain/contexts/displayContext.js.map +1 -1
  184. package/esm/domain/contexts/foregroundContexts.js.map +1 -1
  185. package/esm/domain/contexts/internalContext.js.map +1 -1
  186. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  187. package/esm/domain/contexts/urlContexts.js +11 -2
  188. package/esm/domain/contexts/urlContexts.js.map +1 -1
  189. package/esm/domain/contexts/viewContexts.js.map +1 -1
  190. package/esm/domain/deflate/deflateEncoder.js +517 -39
  191. package/esm/domain/deflate/deflateEncoder.js.map +1 -1
  192. package/esm/domain/deflate/deflateWorker.js +193 -116
  193. package/esm/domain/deflate/deflateWorker.js.map +1 -1
  194. package/esm/domain/deflate/index.js.map +1 -1
  195. package/esm/domain/domMutationObservable.js.map +1 -1
  196. package/esm/domain/encoderStreamId.js.map +1 -1
  197. package/esm/domain/firstInputPolyfill.js.map +1 -1
  198. package/esm/domain/initViewportObservable.js.map +1 -1
  199. package/esm/domain/locationChangeObservable.js.map +1 -1
  200. package/esm/domain/performanceObservable.js.map +1 -1
  201. package/esm/domain/performanceUtils.js.map +1 -1
  202. package/esm/domain/plugins.js.map +1 -1
  203. package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
  204. package/esm/domain/replay/record/canvasCommandCapture.js +968 -168
  205. package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
  206. package/esm/domain/replay/record/canvasCommandObserver.js +1058 -119
  207. package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
  208. package/esm/domain/replay/record/canvasCommandSerializeArgs.js +60 -37
  209. package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  210. package/esm/domain/replay/record/canvasContext.js +50 -0
  211. package/esm/domain/replay/record/canvasContext.js.map +1 -0
  212. package/esm/domain/replay/record/canvasContinuousScheduler.js +246 -118
  213. package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
  214. package/esm/domain/replay/record/canvasEncodeBridge.js +539 -87
  215. package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -1
  216. package/esm/domain/replay/record/canvasEncodeWorker.js +51 -33
  217. package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -1
  218. package/esm/domain/replay/record/canvasFrameSignature.js +50 -17
  219. package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -1
  220. package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -1
  221. package/esm/domain/replay/record/canvasObserver.js +295 -59
  222. package/esm/domain/replay/record/canvasObserver.js.map +1 -1
  223. package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -1
  224. package/esm/domain/replay/record/canvasWebGLPluginHost.js +26 -0
  225. package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
  226. package/esm/domain/replay/record/elementsScrollPositions.js +3 -0
  227. package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
  228. package/esm/domain/replay/record/index.js.map +1 -1
  229. package/esm/domain/replay/record/mutationBatch.js +541 -25
  230. package/esm/domain/replay/record/mutationBatch.js.map +1 -1
  231. package/esm/domain/replay/record/mutationObserver.js +1892 -195
  232. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  233. package/esm/domain/replay/record/mutationResourceBudget.js +137 -0
  234. package/esm/domain/replay/record/mutationResourceBudget.js.map +1 -0
  235. package/esm/domain/replay/record/observers.js +224 -55
  236. package/esm/domain/replay/record/observers.js.map +1 -1
  237. package/esm/domain/replay/record/privacy.js +30 -7
  238. package/esm/domain/replay/record/privacy.js.map +1 -1
  239. package/esm/domain/replay/record/record.js +3086 -325
  240. package/esm/domain/replay/record/record.js.map +1 -1
  241. package/esm/domain/replay/record/serializationUtils.js +422 -25
  242. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  243. package/esm/domain/replay/record/serialize.js +258 -50
  244. package/esm/domain/replay/record/serialize.js.map +1 -1
  245. package/esm/domain/replay/record/shadowRootsController.js +875 -21
  246. package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
  247. package/esm/domain/replay/record/utils.js.map +1 -1
  248. package/esm/domain/replay/record/viewports.js.map +1 -1
  249. package/esm/domain/replay/replayStats.js.map +1 -1
  250. package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  251. package/esm/domain/replay/segmentCollection/index.js.map +1 -1
  252. package/esm/domain/replay/segmentCollection/segment.js +315 -10
  253. package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
  254. package/esm/domain/replay/segmentCollection/segmentCollection.js +957 -72
  255. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  256. package/esm/domain/replay/startRecordBridge.js.map +1 -1
  257. package/esm/domain/requestCollection.js.map +1 -1
  258. package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  259. package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
  260. package/esm/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
  261. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  262. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  263. package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
  264. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  265. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  266. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  267. package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
  268. package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
  269. package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
  270. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  271. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  272. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  273. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  274. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  275. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  276. package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
  277. package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
  278. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  279. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  280. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  281. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  282. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  283. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  284. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  285. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  286. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  287. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  288. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  289. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  290. package/esm/domain/rumEventsCollection/view/trackViews.js +30 -12
  291. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  292. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  293. package/esm/domain/rumSessionManager.js.map +1 -1
  294. package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
  295. package/esm/domain/tracing/getDocumentTraceId.js.map +1 -1
  296. package/esm/domain/tracing/jaegerTracer.js.map +1 -1
  297. package/esm/domain/tracing/sampler.js.map +1 -1
  298. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  299. package/esm/domain/tracing/traceIdentifier.js.map +1 -1
  300. package/esm/domain/tracing/tracer.js +2 -2
  301. package/esm/domain/tracing/tracer.js.map +1 -1
  302. package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
  303. package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
  304. package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
  305. package/esm/domain/trackEventCounts.js.map +1 -1
  306. package/esm/domain/usr/index.js.map +1 -1
  307. package/esm/domain/waitPageActivityEnd.js.map +1 -1
  308. package/esm/index.js.map +1 -1
  309. package/esm/transport/startRumBatch.js +4 -2
  310. package/esm/transport/startRumBatch.js.map +1 -1
  311. package/esm/transport/startRumEventBridge.js.map +1 -1
  312. package/esm/types/index.js.map +1 -1
  313. package/esm/types/sessionReplayConstants.js.map +1 -1
  314. package/package.json +12 -7
  315. package/src/boot/recorderApi.js +247 -220
  316. package/src/boot/recorderApiStub.js +3 -29
  317. package/src/boot/sessionReplayPublicApi.js +15 -28
  318. package/src/boot/startRecording.js +429 -146
  319. package/src/domain/assembly.js +5 -4
  320. package/src/domain/configuration.js +63 -100
  321. package/src/domain/contexts/urlContexts.js +16 -4
  322. package/src/domain/deflate/deflateEncoder.js +699 -43
  323. package/src/domain/deflate/deflateWorker.js +237 -136
  324. package/src/domain/replay/record/canvasCommandCapture.js +1374 -180
  325. package/src/domain/replay/record/canvasCommandObserver.js +1585 -150
  326. package/src/domain/replay/record/canvasCommandSerializeArgs.js +79 -42
  327. package/src/domain/replay/record/canvasContext.js +67 -0
  328. package/src/domain/replay/record/canvasContinuousScheduler.js +379 -143
  329. package/src/domain/replay/record/canvasEncodeBridge.js +691 -106
  330. package/src/domain/replay/record/canvasEncodeWorker.js +67 -43
  331. package/src/domain/replay/record/canvasFrameSignature.js +58 -24
  332. package/src/domain/replay/record/canvasObserver.js +461 -89
  333. package/src/domain/replay/record/canvasWebGLPluginHost.js +43 -0
  334. package/src/domain/replay/record/elementsScrollPositions.js +3 -0
  335. package/src/domain/replay/record/mutationBatch.js +761 -27
  336. package/src/domain/replay/record/mutationObserver.js +2992 -261
  337. package/src/domain/replay/record/mutationResourceBudget.js +191 -0
  338. package/src/domain/replay/record/observers.js +367 -97
  339. package/src/domain/replay/record/privacy.js +34 -12
  340. package/src/domain/replay/record/record.js +4284 -413
  341. package/src/domain/replay/record/serializationUtils.js +587 -28
  342. package/src/domain/replay/record/serialize.js +432 -66
  343. package/src/domain/replay/record/shadowRootsController.js +1108 -30
  344. package/src/domain/replay/segmentCollection/segment.js +441 -11
  345. package/src/domain/replay/segmentCollection/segmentCollection.js +1300 -77
  346. package/src/domain/rumEventsCollection/view/trackViews.js +36 -12
  347. package/src/domain/tracing/tracer.js +4 -5
  348. package/src/transport/startRumBatch.js +6 -1
  349. package/types/index.d.ts +15 -2
  350. package/cjs/domain/replay/record/canvasReplayFixtures.js +0 -105
  351. package/cjs/domain/replay/record/canvasReplayFixtures.js.map +0 -1
  352. package/esm/domain/replay/record/canvasReplayFixtures.js +0 -96
  353. package/esm/domain/replay/record/canvasReplayFixtures.js.map +0 -1
  354. package/src/domain/replay/record/canvasReplayFixtures.js +0 -113
@@ -1,49 +1,783 @@
1
1
  import { noop, throttle, requestIdleCallback } from '@cloudcare/browser-core'
2
+ import { MUTATION_RESOURCE_RAW } from './mutationResourceBudget'
2
3
 
3
- /**
4
- * Maximum duration to wait before processing mutations. If the browser is idle, mutations will be
5
- * processed more quickly. If the browser is busy executing small tasks (ex: rendering frames), the
6
- * mutations will wait MUTATION_PROCESS_MAX_DELAY milliseconds before being processed. If the
7
- * browser is busy executing a longer task, mutations will be processed after this task.
8
- */
9
4
  var MUTATION_PROCESS_MAX_DELAY = 120
10
5
  export var MUTATION_PROCESS_MIN_DELAY = 48
11
- export function createMutationBatch(processMutationBatch) {
6
+ export var MAX_PENDING_MUTATION_RECORDS = 256
7
+ export var MAX_PENDING_MUTATION_NODES = 1000
8
+ export var MAX_PENDING_MUTATION_APPROX_BYTES = 256 * 1024
9
+ export var MUTATION_CHUNK_MAX_RECORDS = 64
10
+ // Keep add-heavy normalization below the operation grace used by
11
+ // mutationObserver. A wider pending batch is preserved as one transaction, but
12
+ // normalized over several bounded tasks so a short GC/renderer interruption
13
+ // cannot turn unpublished additions into mandatory FullSnapshot recovery.
14
+ export var MUTATION_CHUNK_MAX_NODES = 32
15
+ export var MUTATION_CHUNK_MAX_APPROX_BYTES = 64 * 1024
16
+ export var MAX_QUEUED_MUTATION_RECORDS = 4096
17
+ export var MAX_QUEUED_MUTATION_NODES = 16384
18
+ export var MAX_QUEUED_MUTATION_APPROX_BYTES = 8 * 1024 * 1024
19
+ var MUTATION_FLUSH_BUDGET_MS = 4
20
+
21
+ export function createMutationBatch(
22
+ processMutationBatch,
23
+ onOverflow,
24
+ mutationResourceBudget
25
+ ) {
12
26
  var cancelScheduledFlush = noop
27
+ var continuationTimeout
13
28
  var pendingMutations = []
29
+ var pendingMutationNodes = 0
30
+ var pendingMutationApproxBytes = 0
31
+ var pendingMutationDirectNodes = 0
32
+ var pendingNativeCallbackCount = 0
33
+ var pendingMutationReservations = []
34
+ var workQueue = []
35
+ var queuedMutationRecords = 0
36
+ var queuedMutationNodes = 0
37
+ var queuedMutationApproxBytes = 0
38
+ var stopped = false
39
+ var coalescedTextReplacementByRemovedNode = new WeakMap()
40
+
41
+ var throttled = throttle(flush, MUTATION_PROCESS_MIN_DELAY, {
42
+ leading: false
43
+ })
44
+
45
+ function scheduleInitialFlush() {
46
+ if (cancelScheduledFlush !== noop) {
47
+ return
48
+ }
49
+ cancelScheduledFlush = requestIdleCallback(throttled.throttled, {
50
+ timeout: MUTATION_PROCESS_MAX_DELAY
51
+ })
52
+ }
53
+
54
+ function scheduleContinuation() {
55
+ if (
56
+ continuationTimeout !== undefined ||
57
+ stopped ||
58
+ !workQueue.length
59
+ ) {
60
+ return
61
+ }
62
+ continuationTimeout = setTimeout(function () {
63
+ continuationTimeout = undefined
64
+ drainOneChunk()
65
+ scheduleContinuation()
66
+ }, 0)
67
+ }
68
+
69
+ function enqueuePending() {
70
+ if (!pendingMutations.length) {
71
+ return
72
+ }
73
+ var work = {
74
+ $rMutations: pendingMutations,
75
+ $rMeasurement: {
76
+ mutationRecordCount: pendingMutations.length,
77
+ nodeCount: pendingMutationNodes,
78
+ approxBytes: pendingMutationApproxBytes
79
+ },
80
+ directNodeCount: pendingMutationDirectNodes,
81
+ nativeCallbackCount: pendingNativeCallbackCount,
82
+ reservations: pendingMutationReservations
83
+ }
84
+ enqueueMutationWork(work)
85
+ pendingMutations = []
86
+ pendingMutationNodes = 0
87
+ pendingMutationApproxBytes = 0
88
+ pendingMutationDirectNodes = 0
89
+ pendingNativeCallbackCount = 0
90
+ pendingMutationReservations = []
91
+ }
92
+
93
+ function enqueueMutationWork(work) {
94
+ work.$rTextReplacementByRemovedNode =
95
+ coalescedTextReplacementByRemovedNode
96
+ if (shouldChunkMutationWork(work)) {
97
+ initializeChunkedWork(work)
98
+ }
99
+ enqueueWork(work)
100
+ }
101
+
102
+ function enqueueWork(work) {
103
+ workQueue.push(work)
104
+ queuedMutationRecords += work.$rMeasurement.mutationRecordCount
105
+ queuedMutationNodes += work.$rMeasurement.nodeCount
106
+ queuedMutationApproxBytes += work.$rMeasurement.approxBytes
107
+ }
108
+
109
+ function releaseWork(work) {
110
+ queuedMutationRecords -= work.$rMeasurement.mutationRecordCount
111
+ queuedMutationNodes -= work.$rMeasurement.nodeCount
112
+ queuedMutationApproxBytes -= work.$rMeasurement.approxBytes
113
+ releaseReservations(work.reservations)
114
+ if (!workQueue.length && !pendingMutations.length) {
115
+ coalescedTextReplacementByRemovedNode = new WeakMap()
116
+ }
117
+ }
14
118
 
15
119
  function flush() {
16
120
  cancelScheduledFlush()
17
- processMutationBatch(pendingMutations)
121
+ cancelScheduledFlush = noop
122
+ throttled.cancel()
123
+ enqueuePending()
124
+ var deadline = getCurrentTime() + MUTATION_FLUSH_BUDGET_MS
125
+ var succeeded = true
126
+ do {
127
+ if (!drainOneChunk()) {
128
+ succeeded = false
129
+ break
130
+ }
131
+ } while (workQueue.length && getCurrentTime() < deadline)
132
+ if (!succeeded) {
133
+ return false
134
+ }
135
+ if (workQueue.length) {
136
+ scheduleContinuation()
137
+ return 'pending'
138
+ }
139
+ return true
140
+ }
141
+
142
+ function drainOneChunk() {
143
+ if (stopped || !workQueue.length) {
144
+ return true
145
+ }
146
+ var work = workQueue[0]
147
+ if (work.recordIndex === undefined) {
148
+ workQueue.shift()
149
+ releaseWork(work)
150
+ var batchSucceeded = process(
151
+ work.$rMutations,
152
+ createBatchContext(work)
153
+ )
154
+ if (!batchSucceeded) {
155
+ reset()
156
+ }
157
+ return batchSucceeded
158
+ }
159
+ var chunk = takeChunk(work)
160
+ var isLast = work.$rTransaction.$rPureAdd
161
+ ? work.recordIndex < 0
162
+ : work.recordIndex >= work.$rMutations.length
163
+ var succeeded = process(
164
+ chunk,
165
+ createBatchContext(work, work.$rTransaction, isLast)
166
+ )
167
+ if (workQueue[0] !== work) {
168
+ // Recovery callbacks may synchronously reset the whole batch. The old
169
+ // work has already been released in that case; do not shift/release it
170
+ // a second time or let a stale successful return escape.
171
+ return false
172
+ }
173
+ if (!succeeded || isLast) {
174
+ workQueue.shift()
175
+ releaseWork(work)
176
+ }
177
+ if (!succeeded) {
178
+ // Recovery supersedes the whole queued generation. Do not let a later
179
+ // callback escape after the failed atomic transaction.
180
+ reset()
181
+ }
182
+ return succeeded
183
+ }
184
+
185
+ function process(mutations, batchContext) {
186
+ try {
187
+ var result = processMutationBatch(mutations, batchContext)
188
+ return batchContext.transaction
189
+ ? result === true
190
+ : result !== false
191
+ } catch (_) {
192
+ if (onOverflow) {
193
+ onOverflow({
194
+ reason: 'mutation_processing_error',
195
+ mutationRecordCount: mutations.length
196
+ })
197
+ }
198
+ return false
199
+ }
200
+ }
201
+
202
+ function reset() {
203
+ cancelScheduledFlush()
204
+ cancelScheduledFlush = noop
205
+ throttled.cancel()
206
+ if (continuationTimeout !== undefined) {
207
+ clearTimeout(continuationTimeout)
208
+ continuationTimeout = undefined
209
+ }
210
+ releaseReservations(pendingMutationReservations)
211
+ workQueue.forEach(function (work) {
212
+ releaseReservations(work.reservations)
213
+ })
18
214
  pendingMutations = []
215
+ pendingMutationNodes = 0
216
+ pendingMutationApproxBytes = 0
217
+ pendingMutationDirectNodes = 0
218
+ pendingNativeCallbackCount = 0
219
+ pendingMutationReservations = []
220
+ workQueue = []
221
+ queuedMutationRecords = 0
222
+ queuedMutationNodes = 0
223
+ queuedMutationApproxBytes = 0
224
+ coalescedTextReplacementByRemovedNode = new WeakMap()
19
225
  }
20
- //const { throttled: throttledFlush, cancel: cancelThrottle }
21
- var _throttled = throttle(flush, MUTATION_PROCESS_MIN_DELAY, {
22
- leading: false
23
- })
24
- var throttledFlush = _throttled.throttled
25
- var cancelThrottle = _throttled.cancel
226
+
26
227
  return {
27
228
  addMutations: function (mutations) {
28
- if (pendingMutations.length === 0) {
29
- cancelScheduledFlush = requestIdleCallback(throttledFlush, {
30
- timeout: MUTATION_PROCESS_MAX_DELAY
229
+ if (!mutations.length || stopped) {
230
+ return true
231
+ }
232
+ var queuedMeasurement = measureMutationsUntilLimit(
233
+ mutations,
234
+ MAX_QUEUED_MUTATION_NODES -
235
+ queuedMutationNodes -
236
+ pendingMutationNodes,
237
+ MAX_QUEUED_MUTATION_APPROX_BYTES -
238
+ queuedMutationApproxBytes -
239
+ pendingMutationApproxBytes
240
+ )
241
+ if (
242
+ queuedMutationRecords +
243
+ pendingMutations.length +
244
+ mutations.length >
245
+ MAX_QUEUED_MUTATION_RECORDS ||
246
+ queuedMutationNodes +
247
+ pendingMutationNodes +
248
+ queuedMeasurement.nodeCount >
249
+ MAX_QUEUED_MUTATION_NODES ||
250
+ queuedMutationApproxBytes +
251
+ pendingMutationApproxBytes +
252
+ queuedMeasurement.approxBytes >
253
+ MAX_QUEUED_MUTATION_APPROX_BYTES
254
+ ) {
255
+ reset()
256
+ if (onOverflow) {
257
+ onOverflow({
258
+ reason: 'raw_mutation_queue_watermark',
259
+ mutationRecordCount: mutations.length,
260
+ mutationNodeCount: queuedMeasurement.nodeCount,
261
+ mutationApproxBytes: queuedMeasurement.approxBytes
262
+ })
263
+ }
264
+ return false
265
+ }
266
+ var mutationResourceReservation
267
+ if (mutationResourceBudget) {
268
+ mutationResourceReservation = mutationResourceBudget.reserve(
269
+ MUTATION_RESOURCE_RAW,
270
+ {
271
+ recordCount: mutations.length,
272
+ nodeCount: queuedMeasurement.nodeCount,
273
+ approxBytes: queuedMeasurement.approxBytes
274
+ }
275
+ )
276
+ if (!mutationResourceReservation) {
277
+ reset()
278
+ if (onOverflow) {
279
+ onOverflow({
280
+ reason: 'aggregate_raw_mutation_watermark',
281
+ mutationRecordCount: mutations.length,
282
+ mutationNodeCount: queuedMeasurement.nodeCount,
283
+ mutationApproxBytes: queuedMeasurement.approxBytes
284
+ })
285
+ }
286
+ return false
287
+ }
288
+ }
289
+ var directNodeCount = countDirectMutationNodes(mutations)
290
+ var canStorePending =
291
+ !workQueue.length &&
292
+ (!pendingMutations.length ||
293
+ canMergePendingCallback(
294
+ mutations.length,
295
+ queuedMeasurement,
296
+ directNodeCount
297
+ ))
298
+ if (canStorePending) {
299
+ if (!pendingMutations.length) {
300
+ scheduleInitialFlush()
301
+ }
302
+ Array.prototype.push.apply(pendingMutations, mutations)
303
+ if (mutationResourceReservation) {
304
+ pendingMutationReservations.push(
305
+ mutationResourceReservation
306
+ )
307
+ }
308
+ pendingMutationNodes += queuedMeasurement.nodeCount
309
+ pendingMutationApproxBytes += queuedMeasurement.approxBytes
310
+ pendingMutationDirectNodes += directNodeCount
311
+ pendingNativeCallbackCount += 1
312
+ } else {
313
+ enqueuePending()
314
+ enqueueMutationWork({
315
+ $rMutations: mutations,
316
+ $rMeasurement: {
317
+ mutationRecordCount: mutations.length,
318
+ nodeCount: queuedMeasurement.nodeCount,
319
+ approxBytes: queuedMeasurement.approxBytes
320
+ },
321
+ directNodeCount: directNodeCount,
322
+ nativeCallbackCount: 1,
323
+ reservations: mutationResourceReservation
324
+ ? [mutationResourceReservation]
325
+ : []
31
326
  })
327
+ scheduleContinuation()
32
328
  }
33
- Array.prototype.push.apply(pendingMutations, mutations)
329
+ return true
34
330
  },
35
-
36
331
  flush: flush,
37
-
38
- reset: function () {
39
- cancelScheduledFlush()
40
- cancelThrottle()
41
- pendingMutations = []
332
+ reset: reset,
333
+ hasPending: function () {
334
+ return Boolean(pendingMutations.length || workQueue.length)
42
335
  },
43
-
44
336
  stop: function () {
45
- cancelScheduledFlush()
46
- cancelThrottle()
337
+ stopped = true
338
+ reset()
339
+ }
340
+ }
341
+
342
+ function canMergePendingCallback(
343
+ mutationRecordCount,
344
+ measurement,
345
+ directNodeCount
346
+ ) {
347
+ return (
348
+ pendingMutationDirectNodes + directNodeCount <=
349
+ MUTATION_CHUNK_MAX_NODES &&
350
+ pendingMutations.length + mutationRecordCount <=
351
+ MAX_PENDING_MUTATION_RECORDS &&
352
+ pendingMutationNodes + measurement.nodeCount <=
353
+ MAX_PENDING_MUTATION_NODES &&
354
+ pendingMutationApproxBytes + measurement.approxBytes <=
355
+ MAX_PENDING_MUTATION_APPROX_BYTES
356
+ )
357
+ }
358
+ }
359
+
360
+ function initializeChunkedWork(work) {
361
+ var isPureAdd =
362
+ work.nativeCallbackCount === 1 &&
363
+ isReverseChunkableSiblingAddWork(work.$rMutations)
364
+ work.$rTransaction = {
365
+ $rPureAdd: isPureAdd
366
+ }
367
+ work.recordIndex = isPureAdd ? work.$rMutations.length - 1 : 0
368
+ work.addedIndex = isPureAdd
369
+ ? getNodeListLength(work.$rMutations[work.recordIndex].addedNodes)
370
+ : 0
371
+ work.removedIndex = 0
372
+ }
373
+
374
+ function createBatchContext(work, transaction, isLast) {
375
+ return {
376
+ transaction: transaction,
377
+ isLast: isLast,
378
+ $rTextReplacementByRemovedNode:
379
+ work.$rTextReplacementByRemovedNode
380
+ }
381
+ }
382
+
383
+ function hasStructuralRemoval(mutations) {
384
+ for (var index = 0; index < mutations.length; index += 1) {
385
+ if (
386
+ mutations[index].type === 'childList' &&
387
+ getNodeListLength(mutations[index].removedNodes)
388
+ ) {
389
+ return true
47
390
  }
48
391
  }
392
+ return false
393
+ }
394
+
395
+ function shouldChunkMutationWork(work) {
396
+ return (
397
+ (work.nativeCallbackCount === 1 &&
398
+ work.directNodeCount >= MUTATION_CHUNK_MAX_NODES &&
399
+ !hasStructuralRemoval(work.$rMutations)) ||
400
+ work.$rMeasurement.mutationRecordCount >
401
+ MAX_PENDING_MUTATION_RECORDS ||
402
+ work.$rMeasurement.nodeCount > MAX_PENDING_MUTATION_NODES ||
403
+ work.$rMeasurement.approxBytes > MAX_PENDING_MUTATION_APPROX_BYTES
404
+ )
405
+ }
406
+
407
+ function isReverseChunkableSiblingAddWork(mutations) {
408
+ var hasAdd = false
409
+ var target
410
+ var addedNodeSet = new Set()
411
+ var previousAddedNode
412
+ for (var index = 0; index < mutations.length; index += 1) {
413
+ var mutation = mutations[index]
414
+ if (
415
+ mutation.type !== 'childList' ||
416
+ getNodeListLength(mutation.removedNodes)
417
+ ) {
418
+ return false
419
+ }
420
+ if (target === undefined) {
421
+ target = mutation.target
422
+ } else if (mutation.target !== target) {
423
+ return false
424
+ }
425
+ for (
426
+ var addedIndex = 0;
427
+ addedIndex < getNodeListLength(mutation.addedNodes);
428
+ addedIndex += 1
429
+ ) {
430
+ var addedNode = mutation.addedNodes[addedIndex]
431
+ if (
432
+ !target ||
433
+ addedNodeSet.has(addedNode) ||
434
+ addedNode.parentNode !== target ||
435
+ (previousAddedNode &&
436
+ !isFollowingSibling(previousAddedNode, addedNode))
437
+ ) {
438
+ return false
439
+ }
440
+ addedNodeSet.add(addedNode)
441
+ previousAddedNode = addedNode
442
+ hasAdd = true
443
+ }
444
+ }
445
+ return hasAdd
446
+ }
447
+
448
+ function isFollowingSibling(previousNode, node) {
449
+ if (typeof previousNode.compareDocumentPosition !== 'function') {
450
+ return false
451
+ }
452
+ /* eslint-disable no-bitwise */
453
+ return Boolean(
454
+ previousNode.compareDocumentPosition(node) &
455
+ Node.DOCUMENT_POSITION_FOLLOWING
456
+ )
457
+ /* eslint-enable no-bitwise */
458
+ }
459
+
460
+ function countDirectMutationNodes(mutations) {
461
+ var nodeCount = 0
462
+ for (var index = 0; index < mutations.length; index += 1) {
463
+ var mutation = mutations[index]
464
+ if (mutation.type === 'childList') {
465
+ nodeCount +=
466
+ getNodeListLength(mutation.addedNodes) +
467
+ getNodeListLength(mutation.removedNodes)
468
+ }
469
+ }
470
+ return nodeCount
471
+ }
472
+
473
+ function releaseReservations(reservations) {
474
+ if (!reservations) {
475
+ return
476
+ }
477
+ reservations.forEach(function (release) {
478
+ release()
479
+ })
480
+ reservations.length = 0
481
+ }
482
+
483
+ function takeChunk(work) {
484
+ if (work.$rTransaction.$rPureAdd) {
485
+ return takePureAddChunk(work)
486
+ }
487
+ var chunk = []
488
+ var nodeCount = 0
489
+ var approxBytes = 0
490
+ while (
491
+ work.recordIndex < work.$rMutations.length &&
492
+ chunk.length < MUTATION_CHUNK_MAX_RECORDS
493
+ ) {
494
+ var mutation = work.$rMutations[work.recordIndex]
495
+ var synthetic = mutation
496
+ var isChildList = mutation.type === 'childList'
497
+ var nextAddedIndex = work.addedIndex
498
+ var nextRemovedIndex = work.removedIndex
499
+ var completesChildList = false
500
+ if (mutation.type === 'childList') {
501
+ var addedNodeCount = getNodeListLength(mutation.addedNodes)
502
+ var removedNodeCount = getNodeListLength(mutation.removedNodes)
503
+ var keepStructuralMutationWhole =
504
+ removedNodeCount > 0 &&
505
+ addedNodeCount + removedNodeCount < MAX_PENDING_MUTATION_NODES
506
+ if (keepStructuralMutationWhole) {
507
+ var structuralMeasurement = measureMutation(mutation)
508
+ if (
509
+ chunk.length &&
510
+ (nodeCount + structuralMeasurement.nodeCount >
511
+ MUTATION_CHUNK_MAX_NODES ||
512
+ approxBytes + structuralMeasurement.approxBytes >
513
+ MUTATION_CHUNK_MAX_APPROX_BYTES)
514
+ ) {
515
+ // A remove/add pair is one replay-tree transition. If it cannot fit
516
+ // at the tail of this chunk, move the complete native record to the
517
+ // next chunk instead of splitting the two structural sides.
518
+ break
519
+ }
520
+ synthetic = {
521
+ type: 'childList',
522
+ target: mutation.target,
523
+ addedNodes: Array.prototype.slice.call(mutation.addedNodes),
524
+ removedNodes: Array.prototype.slice.call(mutation.removedNodes),
525
+ previousSibling: mutation.previousSibling,
526
+ nextSibling: mutation.nextSibling
527
+ }
528
+ nextAddedIndex = addedNodeCount
529
+ nextRemovedIndex = removedNodeCount
530
+ completesChildList = true
531
+ } else {
532
+ // A large native remove+add record is normalized in bounded slices but
533
+ // admitted as one mutation group by mutationObserver. Consume removals
534
+ // first so every later add slice can inherit whether the native record
535
+ // removed a published node. This preserves the fail-closed replacement
536
+ // dependency without synchronously scanning the whole NodeList.
537
+ var structuralState =
538
+ removedNodeCount > 0
539
+ ? getStructuralMutationState(work, work.recordIndex)
540
+ : undefined
541
+ var remainingNodes = Math.max(
542
+ Math.min(
543
+ MUTATION_CHUNK_MAX_NODES - nodeCount - 1,
544
+ Math.floor(
545
+ (MUTATION_CHUNK_MAX_APPROX_BYTES -
546
+ approxBytes -
547
+ 32) /
548
+ 16
549
+ )
550
+ ),
551
+ 1
552
+ )
553
+ var removedNodes = structuralState
554
+ ? Array.prototype.slice.call(
555
+ mutation.removedNodes,
556
+ work.removedIndex,
557
+ work.removedIndex + remainingNodes
558
+ )
559
+ : []
560
+ remainingNodes -= removedNodes.length
561
+ var addedNodes = Array.prototype.slice.call(
562
+ mutation.addedNodes,
563
+ work.addedIndex,
564
+ work.addedIndex + remainingNodes
565
+ )
566
+ remainingNodes -= addedNodes.length
567
+ if (!structuralState) {
568
+ removedNodes = Array.prototype.slice.call(
569
+ mutation.removedNodes,
570
+ work.removedIndex,
571
+ work.removedIndex + remainingNodes
572
+ )
573
+ }
574
+ synthetic = {
575
+ type: 'childList',
576
+ target: mutation.target,
577
+ addedNodes: addedNodes,
578
+ removedNodes: removedNodes,
579
+ previousSibling: mutation.previousSibling,
580
+ nextSibling: mutation.nextSibling,
581
+ $rStructuralState: structuralState
582
+ }
583
+ nextAddedIndex += addedNodes.length
584
+ nextRemovedIndex += removedNodes.length
585
+ completesChildList =
586
+ nextAddedIndex >= addedNodeCount &&
587
+ nextRemovedIndex >= removedNodeCount
588
+ }
589
+ } else {
590
+ synthetic = cloneMutationRecord(mutation)
591
+ work.recordIndex += 1
592
+ }
593
+ var measurement = measureMutation(synthetic)
594
+ if (
595
+ chunk.length &&
596
+ (nodeCount + measurement.nodeCount > MUTATION_CHUNK_MAX_NODES ||
597
+ approxBytes + measurement.approxBytes >
598
+ MUTATION_CHUNK_MAX_APPROX_BYTES)
599
+ ) {
600
+ // The cursor is committed only after the synthetic record fits. This is
601
+ // important at an exact boundary: advancing a child-list cursor before
602
+ // this check would silently drop the rejected slice.
603
+ if (!isChildList) {
604
+ work.recordIndex -= 1
605
+ }
606
+ break
607
+ }
608
+ if (isChildList) {
609
+ if (completesChildList) {
610
+ work.recordIndex += 1
611
+ work.addedIndex = 0
612
+ work.removedIndex = 0
613
+ } else {
614
+ work.addedIndex = nextAddedIndex
615
+ work.removedIndex = nextRemovedIndex
616
+ }
617
+ }
618
+ chunk.push(synthetic)
619
+ nodeCount += measurement.nodeCount
620
+ approxBytes += measurement.approxBytes
621
+ if (
622
+ nodeCount >= MUTATION_CHUNK_MAX_NODES ||
623
+ approxBytes >= MUTATION_CHUNK_MAX_APPROX_BYTES
624
+ ) {
625
+ break
626
+ }
627
+ }
628
+ return chunk
629
+ }
630
+
631
+ function getStructuralMutationState(work, recordIndex) {
632
+ if (!work.$rStructuralStateByRecordIndex) {
633
+ work.$rStructuralStateByRecordIndex = []
634
+ }
635
+ var structuralState = work.$rStructuralStateByRecordIndex[recordIndex]
636
+ if (!structuralState) {
637
+ structuralState = { $rHasPublishedRemoval: false }
638
+ work.$rStructuralStateByRecordIndex[recordIndex] = structuralState
639
+ }
640
+ return structuralState
641
+ }
642
+
643
+ function takePureAddChunk(work) {
644
+ var chunk = []
645
+ var nodeCount = 0
646
+ var approxBytes = 0
647
+ while (
648
+ work.recordIndex >= 0 &&
649
+ chunk.length < MUTATION_CHUNK_MAX_RECORDS
650
+ ) {
651
+ while (work.recordIndex >= 0 && work.addedIndex === 0) {
652
+ work.recordIndex -= 1
653
+ work.addedIndex =
654
+ work.recordIndex >= 0
655
+ ? getNodeListLength(
656
+ work.$rMutations[work.recordIndex].addedNodes
657
+ )
658
+ : 0
659
+ }
660
+ if (work.recordIndex < 0) {
661
+ break
662
+ }
663
+
664
+ var mutation = work.$rMutations[work.recordIndex]
665
+ var remainingNodes = Math.max(
666
+ Math.min(
667
+ MUTATION_CHUNK_MAX_NODES - nodeCount - 1,
668
+ Math.floor(
669
+ (MUTATION_CHUNK_MAX_APPROX_BYTES - approxBytes - 32) /
670
+ 16
671
+ )
672
+ ),
673
+ 1
674
+ )
675
+ var sliceStart = Math.max(
676
+ work.addedIndex - remainingNodes,
677
+ 0
678
+ )
679
+ var synthetic = {
680
+ type: 'childList',
681
+ target: mutation.target,
682
+ addedNodes: Array.prototype.slice.call(
683
+ mutation.addedNodes,
684
+ sliceStart,
685
+ work.addedIndex
686
+ ),
687
+ removedNodes: []
688
+ }
689
+ var measurement = measureMutation(synthetic)
690
+ if (
691
+ chunk.length &&
692
+ (nodeCount + measurement.nodeCount > MUTATION_CHUNK_MAX_NODES ||
693
+ approxBytes + measurement.approxBytes >
694
+ MUTATION_CHUNK_MAX_APPROX_BYTES)
695
+ ) {
696
+ break
697
+ }
698
+
699
+ work.addedIndex = sliceStart
700
+ if (work.addedIndex === 0) {
701
+ work.recordIndex -= 1
702
+ work.addedIndex =
703
+ work.recordIndex >= 0
704
+ ? getNodeListLength(
705
+ work.$rMutations[work.recordIndex].addedNodes
706
+ )
707
+ : 0
708
+ }
709
+ chunk.push(synthetic)
710
+ nodeCount += measurement.nodeCount
711
+ approxBytes += measurement.approxBytes
712
+ if (
713
+ nodeCount >= MUTATION_CHUNK_MAX_NODES ||
714
+ approxBytes >= MUTATION_CHUNK_MAX_APPROX_BYTES
715
+ ) {
716
+ break
717
+ }
718
+ }
719
+ return chunk
720
+ }
721
+
722
+ function cloneMutationRecord(mutation) {
723
+ var oldValue = mutation.oldValue
724
+ if (
725
+ typeof oldValue === 'string' &&
726
+ oldValue.length > MUTATION_CHUNK_MAX_APPROX_BYTES / 4
727
+ ) {
728
+ oldValue = undefined
729
+ }
730
+ return {
731
+ type: mutation.type,
732
+ target: mutation.target,
733
+ attributeName: mutation.attributeName,
734
+ oldValue: oldValue
735
+ }
736
+ }
737
+
738
+ function measureMutationsUntilLimit(mutations, nodeLimit, byteLimit) {
739
+ var nodeCount = 0
740
+ var approxBytes = 0
741
+ for (var index = 0; index < mutations.length; index += 1) {
742
+ var measurement = measureMutation(mutations[index])
743
+ nodeCount += measurement.nodeCount
744
+ approxBytes += measurement.approxBytes
745
+ if (nodeCount > nodeLimit || approxBytes > byteLimit) {
746
+ break
747
+ }
748
+ }
749
+ return { nodeCount: nodeCount, approxBytes: approxBytes }
750
+ }
751
+
752
+ function measureMutation(mutation) {
753
+ var nodeCount = 1
754
+ var approxBytes = 32
755
+ if (mutation.type === 'childList') {
756
+ var childNodeCount =
757
+ getNodeListLength(mutation.addedNodes) +
758
+ getNodeListLength(mutation.removedNodes)
759
+ nodeCount += childNodeCount
760
+ approxBytes += childNodeCount * 16
761
+ } else if (mutation.type === 'attributes') {
762
+ approxBytes +=
763
+ getStringApproxBytes(mutation.attributeName) +
764
+ getStringApproxBytes(mutation.oldValue)
765
+ } else if (mutation.type === 'characterData') {
766
+ approxBytes += getStringApproxBytes(mutation.oldValue)
767
+ }
768
+ return { nodeCount: nodeCount, approxBytes: approxBytes }
769
+ }
770
+
771
+ function getNodeListLength(nodes) {
772
+ return nodes && typeof nodes.length === 'number' ? nodes.length : 0
773
+ }
774
+
775
+ function getStringApproxBytes(value) {
776
+ return typeof value === 'string' ? value.length * 2 : 0
777
+ }
778
+
779
+ function getCurrentTime() {
780
+ return typeof performance !== 'undefined' && performance.now
781
+ ? performance.now()
782
+ : Date.now()
49
783
  }