@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,57 +1,1135 @@
1
- import { startMutationObserver } from './mutationObserver'
1
+ import {
2
+ getParentNode,
3
+ instrumentMethod,
4
+ isNodeShadowRoot,
5
+ noop,
6
+ setTimeout
7
+ } from '@cloudcare/browser-core'
8
+ import {
9
+ getMutationPayloadApproxBytes,
10
+ startMutationObserver
11
+ } from './mutationObserver'
2
12
  import { initInputObserver } from './observers'
13
+ import { MUTATION_RESOURCE_FLUSH } from './mutationResourceBudget'
14
+
15
+ export var SHADOW_ROOT_CLEANUP_BATCH_SIZE = 32
16
+ export var SHADOW_ROOT_CLEANUP_BUDGET_MS = 4
17
+ export var SHADOW_ROOT_FLUSH_MAX_COUNT = 64
18
+ export var SHADOW_ROOT_FLUSH_BUDGET_MS = 4
19
+ // Kept as an internal compatibility export for existing diagnostics/tests.
20
+ // It is now the per-turn activation/flush slice, not a total observer cap.
21
+ export var SHADOW_ROOT_ACTIVE_CONTROLLER_LIMIT =
22
+ SHADOW_ROOT_FLUSH_MAX_COUNT
23
+ // Kept as an internal compatibility export for diagnostics. Retired
24
+ // generations are now invalidated in O(1) and disconnected in bounded slices;
25
+ // this value no longer triggers synchronous cleanup.
26
+ export var SHADOW_ROOT_RETIRED_CONTROLLER_LIMIT = 512
27
+ export var SHADOW_ROOT_SKIPPED_ANCESTOR_MAX_DEPTH = 1000
28
+
29
+ var attachShadowSubscribers = []
30
+ var attachShadowInstrumentation
3
31
 
4
32
  export var initShadowRootsController = function (configuration, data) {
5
33
  var mutationCb = data.mutationCb
34
+ var mutationOverflowCb = data.mutationOverflowCb
35
+ var mutationActivityCb = data.mutationActivityCb
6
36
  var inputCb = data.inputCb
37
+ var isNodeIgnored = data.isNodeIgnored
38
+ var isInputNodeIgnored = data.isInputNodeIgnored || isNodeIgnored
39
+ var isMutationNodeIgnored =
40
+ isNodeIgnored &&
41
+ function (node) {
42
+ return isNodeIgnored(node, true)
43
+ }
44
+ var isNodePublished = data.isNodePublished
45
+ var mutationNodeSerializationCb = data.mutationNodeSerializationCb
46
+ var mutationResourceBudget = data.mutationResourceBudget
47
+ var startMutationObserverImpl = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
48
+ ? data.startMutationObserver || startMutationObserver
49
+ : startMutationObserver
50
+ var initInputObserverImpl = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
51
+ ? data.initInputObserver || initInputObserver
52
+ : initInputObserver
53
+ var scheduleCleanupImpl = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
54
+ ? data.scheduleCleanup || defaultScheduleCleanup
55
+ : defaultScheduleCleanup
56
+ var getCurrentTimeImpl = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
57
+ ? data.getCurrentTime || getCurrentTime
58
+ : getCurrentTime
59
+ var cleanupErrorCb = __BUILD_ENV__REPLAY_DEBUG_ENABLED__
60
+ ? data.cleanupErrorCb
61
+ : undefined
62
+ var stopAttachShadowObserver = data.shadowRootCreatedCb
63
+ ? subscribeToOpenShadowRoots(function (shadowRoot, host) {
64
+ if (stopped) {
65
+ return
66
+ }
67
+ try {
68
+ data.shadowRootCreatedCb(shadowRoot, host)
69
+ } catch (error) {
70
+ if (mutationOverflowCb) {
71
+ mutationOverflowCb({
72
+ reason: 'dynamic_shadow_root_capture_error',
73
+ error: String(error)
74
+ })
75
+ }
76
+ }
77
+ })
78
+ : noop
79
+
80
+ var nextGenerationId = 0
81
+ var activeGeneration = createGeneration()
7
82
  var controllerByShadowRoot = new Map()
83
+ // Persist only the latest registration identity. This distinguishes a root
84
+ // retired by a baseline reset from a never-registered nested root without
85
+ // walking the retired generation during reset.
86
+ var latestEntryByShadowRoot = new WeakMap()
87
+ var cleanupQueueHead
88
+ var cleanupQueueTail
89
+ var cleanupScheduled = false
90
+ var retiredControllerCount = 0
91
+ var currentFlush
92
+ var pendingFlushIterator
93
+ var pendingFlushGeneration
94
+ var pendingFlushEntry
95
+ var disconnectedCleanupIterator
96
+ var disconnectedCleanupGeneration
97
+ var disconnectedCleanupScheduled = false
98
+ var baselineResetIterator
99
+ var baselineResetGeneration
100
+ var stopped = false
101
+ var recoveryShadowRoots
102
+ var mutationDependencyState = {
103
+ $rPublishedRoots: new WeakSet(),
104
+ $rLocallyDroppedRoots: new WeakSet()
105
+ }
8
106
 
9
107
  var shadowRootsController = {
10
- addShadowRoot: function (shadowRoot) {
108
+ $rMutationDependencyState: mutationDependencyState,
109
+ addShadowRoot: function (shadowRoot, provisionalOwner) {
110
+ if (stopped) {
111
+ return false
112
+ }
11
113
  if (controllerByShadowRoot.has(shadowRoot)) {
12
- return
114
+ return true
13
115
  }
14
- var _startMutaionObserve = startMutationObserver(
15
- mutationCb,
16
- configuration,
17
- shadowRootsController,
18
- shadowRoot
19
- )
20
- var flush = _startMutaionObserve.flush
21
- var stopMutationObserver = _startMutaionObserve.stop
22
-
23
- // the change event no do bubble up across the shadow root, we have to listen on the shadow root
24
- var stopInputObserver = initInputObserver(
25
- inputCb,
26
- configuration,
27
- shadowRoot
28
- )
29
- controllerByShadowRoot.set(shadowRoot, {
30
- flush: flush,
31
- stop: function () {
32
- stopMutationObserver()
33
- stopInputObserver()
116
+ var entry = {
117
+ active: true,
118
+ registered: false,
119
+ shadowRoot: shadowRoot,
120
+ generation: activeGeneration,
121
+ mutationObserverDeactivated: false,
122
+ pendingOverflowAfterReset: false,
123
+ unpublishedMutationOverflowReported: false,
124
+ provisionalOwner: provisionalOwner,
125
+ deactivateMutationObserver: function () {},
126
+ refreshAndFlushPendingRootForNode: function () {},
127
+ resetMutationObserver: function () {},
128
+ stopMutationObserver: function () {},
129
+ stopInputObserver: function () {}
130
+ }
131
+ if (provisionalOwner) {
132
+ if (!provisionalOwner.provisionalShadowRoots) {
133
+ provisionalOwner.provisionalShadowRoots = []
34
134
  }
35
- })
135
+ provisionalOwner.provisionalShadowRoots.push(shadowRoot)
136
+ }
137
+ latestEntryByShadowRoot.set(shadowRoot, entry)
138
+ var mutationObserverController
139
+ try {
140
+ mutationObserverController = startMutationObserverImpl(
141
+ createGatedCallback(entry, 'mutation', mutationCb),
142
+ configuration,
143
+ createGatedShadowRootsController(entry),
144
+ shadowRoot,
145
+ data.mutationPerfCb,
146
+ createGatedCallback(entry, 'overflow', mutationOverflowCb),
147
+ createGatedCallback(entry, 'activity', mutationActivityCb),
148
+ mutationNodeSerializationCb,
149
+ isMutationNodeIgnored,
150
+ isNodePublished,
151
+ function () {
152
+ return isEntryActive(entry)
153
+ },
154
+ mutationResourceBudget
155
+ )
156
+ entry.flush = mutationObserverController.flush || function () {}
157
+ entry.deactivateMutationObserver =
158
+ mutationObserverController.deactivate || function () {}
159
+ entry.refreshAndFlushPendingRootForNode =
160
+ mutationObserverController.refreshAndFlushPendingRootForNode ||
161
+ function () {}
162
+ entry.resetMutationObserver =
163
+ mutationObserverController.reset || function () {}
164
+ entry.stopMutationObserver =
165
+ mutationObserverController.stop || function () {}
166
+
167
+ // The change event does not bubble across a shadow root, so each active
168
+ // generation needs its own listener. The callback is generation-gated
169
+ // before the controller becomes visible in the active map.
170
+ var gatedInputCb = createGatedCallback(entry, 'input', inputCb)
171
+ entry.stopInputObserver =
172
+ (isInputNodeIgnored
173
+ ? initInputObserverImpl(
174
+ gatedInputCb,
175
+ configuration,
176
+ shadowRoot,
177
+ isInputNodeIgnored
178
+ )
179
+ : initInputObserverImpl(
180
+ gatedInputCb,
181
+ configuration,
182
+ shadowRoot
183
+ )) || function () {}
184
+ entry.registered = true
185
+ controllerByShadowRoot.set(shadowRoot, entry)
186
+ return true
187
+ } catch (error) {
188
+ entry.active = false
189
+ stopControllerEntry(entry, false)
190
+ throw error
191
+ }
36
192
  },
193
+
37
194
  removeShadowRoot: function (shadowRoot) {
38
195
  var entry = controllerByShadowRoot.get(shadowRoot)
39
196
  if (!entry) {
40
197
  return
41
198
  }
42
- entry.stop()
199
+ entry.active = false
200
+ entry.registered = false
43
201
  controllerByShadowRoot.delete(shadowRoot)
202
+ stopControllerEntry(entry, true)
203
+ },
204
+
205
+ cleanupDisconnectedShadowRoots: function () {
206
+ if (stopped || controllerByShadowRoot.size === 0) {
207
+ return
208
+ }
209
+ runDisconnectedShadowRootCleanupSlice()
210
+ },
211
+
212
+ refreshAndFlushPendingRootForNode: function (node) {
213
+ if (stopped || !node) {
214
+ return
215
+ }
216
+ var rootNode
217
+ try {
218
+ rootNode = node.getRootNode()
219
+ } catch (_) {
220
+ return
221
+ }
222
+ var entry = controllerByShadowRoot.get(rootNode)
223
+ if (!entry || !entry.active || !entry.registered) {
224
+ return
225
+ }
226
+ return entry.refreshAndFlushPendingRootForNode(node)
44
227
  },
228
+
229
+ commitProvisionalShadowRoots: function (owner) {
230
+ var shadowRoots = owner.provisionalShadowRoots || []
231
+ for (
232
+ var shadowRootIndex = 0;
233
+ shadowRootIndex < shadowRoots.length;
234
+ shadowRootIndex += 1
235
+ ) {
236
+ var shadowRoot = shadowRoots[shadowRootIndex]
237
+ var entry = controllerByShadowRoot.get(shadowRoot)
238
+ if (entry && entry.provisionalOwner === owner) {
239
+ entry.provisionalOwner = undefined
240
+ // Recovery can begin while a serialized host add is still pending.
241
+ // If that add is admitted before the generation reset, its root now
242
+ // belongs to the previous published tree and must participate in a
243
+ // later rollback just like roots captured at $rBeginRecovery time.
244
+ if (
245
+ recoveryShadowRoots &&
246
+ entry.active &&
247
+ entry.registered &&
248
+ recoveryShadowRoots.indexOf(shadowRoot) === -1
249
+ ) {
250
+ recoveryShadowRoots.push(shadowRoot)
251
+ }
252
+ }
253
+ }
254
+ owner.provisionalShadowRoots = undefined
255
+ },
256
+
257
+ rollbackProvisionalShadowRoots: function (owner) {
258
+ var shadowRoots = owner.provisionalShadowRoots || []
259
+ var retiredControllers = new Map()
260
+ for (
261
+ var shadowRootIndex = 0;
262
+ shadowRootIndex < shadowRoots.length;
263
+ shadowRootIndex += 1
264
+ ) {
265
+ var shadowRoot = shadowRoots[shadowRootIndex]
266
+ var entry = controllerByShadowRoot.get(shadowRoot)
267
+ if (!entry || entry.provisionalOwner !== owner) {
268
+ continue
269
+ }
270
+ entry.provisionalOwner = undefined
271
+ entry.active = false
272
+ entry.registered = false
273
+ controllerByShadowRoot.delete(shadowRoot)
274
+ retiredControllers.set(shadowRoot, entry)
275
+ }
276
+ owner.provisionalShadowRoots = undefined
277
+ retireControllerEntries(retiredControllers)
278
+ },
279
+
280
+ isNodeInSkippedShadowRoot: function (node) {
281
+ if (stopped) {
282
+ return true
283
+ }
284
+ var current = node
285
+ var depth = 0
286
+ while (current) {
287
+ if (depth >= SHADOW_ROOT_SKIPPED_ANCESTOR_MAX_DEPTH) {
288
+ return true
289
+ }
290
+ try {
291
+ current = getParentNode(current)
292
+ } catch (_) {
293
+ return true
294
+ }
295
+ if (!current) {
296
+ return false
297
+ }
298
+ if (isNodeShadowRoot(current)) {
299
+ var entry = latestEntryByShadowRoot.get(current)
300
+ if (entry && !isEntryActive(entry)) {
301
+ return true
302
+ }
303
+ }
304
+ depth += 1
305
+ }
306
+ return false
307
+ },
308
+
45
309
  stop: function () {
46
- controllerByShadowRoot.forEach(function (event) {
47
- event.stop()
48
- })
310
+ if (stopped) {
311
+ return
312
+ }
313
+ try {
314
+ stopAttachShadowObserver()
315
+ } catch (error) {
316
+ reportCleanupError(error)
317
+ }
318
+ stopped = true
319
+ recoveryShadowRoots = undefined
320
+ retireActiveGeneration()
49
321
  },
322
+
50
323
  flush: function () {
51
- controllerByShadowRoot.forEach(function (event) {
52
- event.flush()
324
+ if (stopped || controllerByShadowRoot.size === 0) {
325
+ return true
326
+ }
327
+
328
+ var generation = activeGeneration
329
+ var shadowRootCount = controllerByShadowRoot.size
330
+
331
+ var flushState =
332
+ currentFlush && currentFlush.generation === generation
333
+ ? currentFlush
334
+ : {
335
+ events: [],
336
+ eventApproxBytes: 0,
337
+ eventCount: 0,
338
+ eventBudgetReservation: undefined,
339
+ generation: generation,
340
+ overflow: undefined
341
+ }
342
+ currentFlush = flushState
343
+ var deadline = getCurrentTimeImpl() + SHADOW_ROOT_FLUSH_BUDGET_MS
344
+ if (
345
+ !pendingFlushIterator ||
346
+ pendingFlushGeneration !== generation
347
+ ) {
348
+ pendingFlushIterator = controllerByShadowRoot.values()
349
+ pendingFlushGeneration = generation
350
+ }
351
+ var iterator = pendingFlushIterator
352
+ var flushedShadowRootCount = 0
353
+ var failure
354
+ var iteratorCompleted = false
355
+
356
+ while (
357
+ flushedShadowRootCount < SHADOW_ROOT_FLUSH_MAX_COUNT
358
+ ) {
359
+ if (
360
+ flushedShadowRootCount > 0 &&
361
+ getCurrentTimeImpl() >= deadline
362
+ ) {
363
+ break
364
+ }
365
+ var entry = pendingFlushEntry
366
+ if (!entry) {
367
+ var nextEntry = iterator.next()
368
+ if (nextEntry.done) {
369
+ iteratorCompleted = true
370
+ break
371
+ }
372
+ entry = nextEntry.value
373
+ }
374
+ if (!isEntryActive(entry)) {
375
+ pendingFlushEntry = undefined
376
+ continue
377
+ }
378
+ try {
379
+ var flushSucceeded = entry.flush()
380
+ flushedShadowRootCount += 1
381
+ if (flushSucceeded === false || flushState.overflow) {
382
+ failure = {
383
+ reason: 'shadow_root_flush_overflow',
384
+ cause:
385
+ flushState.overflow && flushState.overflow.reason,
386
+ shadowRootCount: shadowRootCount,
387
+ flushedShadowRootCount: flushedShadowRootCount,
388
+ $rSuppressMutationOverflow:
389
+ flushState.overflow
390
+ ? flushState.overflow.$rSuppressMutationOverflow
391
+ : flushSucceeded === false &&
392
+ mutationResourceBudget &&
393
+ mutationResourceBudget.isFailed()
394
+ }
395
+ break
396
+ }
397
+ if (flushSucceeded === 'pending') {
398
+ // A single root can itself own a paged raw-mutation transaction.
399
+ // Keep the iterator pinned to that root until its final chunk is
400
+ // committed; advancing here would let a boundary reset/stop drop
401
+ // the unfinished transaction while reporting a successful flush.
402
+ pendingFlushEntry = entry
403
+ break
404
+ }
405
+ pendingFlushEntry = undefined
406
+ } catch (error) {
407
+ failure = {
408
+ reason: 'shadow_root_flush_error',
409
+ error: String(error),
410
+ shadowRootCount: shadowRootCount,
411
+ flushedShadowRootCount: flushedShadowRootCount
412
+ }
413
+ break
414
+ }
415
+ }
416
+
417
+ if (failure) {
418
+ clearPendingShadowRootFlush()
419
+ return failFlush(generation, failure)
420
+ }
421
+
422
+ if (!iteratorCompleted) {
423
+ // Keep every page buffered in one logical commit. The caller can
424
+ // yield and invoke flush() again; native callbacks occurring between
425
+ // pages join the same generation-gated transaction.
426
+ return 'pending'
427
+ }
428
+
429
+ currentFlush = undefined
430
+
431
+ var eventsToDispatch = coalesceMutationEvents(
432
+ flushState.events.filter(function (event) {
433
+ return isEntryActive(event.entry)
434
+ })
435
+ )
436
+ try {
437
+ for (
438
+ var eventIndex = 0;
439
+ eventIndex < eventsToDispatch.length;
440
+ eventIndex += 1
441
+ ) {
442
+ var event = eventsToDispatch[eventIndex]
443
+ var eventEntries = event.entries || [event.entry]
444
+ if (
445
+ !eventEntries.some(function (entry) {
446
+ return isEntryActive(entry)
447
+ })
448
+ ) {
449
+ continue
450
+ }
451
+ event.callback(event.value)
452
+ }
453
+ } finally {
454
+ releaseShadowRootFlushBudget(flushState)
455
+ }
456
+ if (iteratorCompleted) {
457
+ clearPendingShadowRootFlush()
458
+ }
459
+ return isGenerationActive(generation)
460
+ },
461
+
462
+ $rResetPendingMutationsForBaseline: function () {
463
+ if (stopped || controllerByShadowRoot.size === 0) {
464
+ clearPendingShadowRootBaselineReset()
465
+ return true
466
+ }
467
+ var generation = activeGeneration
468
+ if (
469
+ !baselineResetIterator ||
470
+ baselineResetGeneration !== generation
471
+ ) {
472
+ baselineResetIterator = controllerByShadowRoot.values()
473
+ baselineResetGeneration = generation
474
+ }
475
+ var deadline =
476
+ getCurrentTimeImpl() + SHADOW_ROOT_FLUSH_BUDGET_MS
477
+ var resetCount = 0
478
+ while (resetCount < SHADOW_ROOT_FLUSH_MAX_COUNT) {
479
+ if (resetCount > 0 && getCurrentTimeImpl() >= deadline) {
480
+ return 'pending'
481
+ }
482
+ var nextEntry = baselineResetIterator.next()
483
+ if (nextEntry.done) {
484
+ clearPendingShadowRootBaselineReset()
485
+ return true
486
+ }
487
+ var entry = nextEntry.value
488
+ if (!isEntryActive(entry)) {
489
+ continue
490
+ }
491
+ try {
492
+ // reset() performs takeRecords(), reports mutation activity, and
493
+ // discards the obsolete raw/task generation without serializing it.
494
+ // The caller restarts the mixed-time FullSnapshot when that activity
495
+ // advances its DOM version.
496
+ entry.resetMutationObserver()
497
+ } catch (error) {
498
+ clearPendingShadowRootBaselineReset()
499
+ if (mutationOverflowCb) {
500
+ mutationOverflowCb({
501
+ reason: 'shadow_root_baseline_reset_error',
502
+ error: String(error)
503
+ })
504
+ }
505
+ return false
506
+ }
507
+ resetCount += 1
508
+ }
509
+ return 'pending'
510
+ },
511
+
512
+ reset: function () {
513
+ if (stopped) {
514
+ return
515
+ }
516
+ retireActiveGeneration()
517
+ },
518
+
519
+ $rBeginRecovery: function () {
520
+ if (stopped || recoveryShadowRoots) {
521
+ return
522
+ }
523
+ recoveryShadowRoots = []
524
+ controllerByShadowRoot.forEach(function (entry, shadowRoot) {
525
+ if (
526
+ entry.active &&
527
+ entry.registered &&
528
+ !entry.provisionalOwner
529
+ ) {
530
+ recoveryShadowRoots.push(shadowRoot)
531
+ }
532
+ })
533
+ },
534
+
535
+ $rCommitRecovery: function () {
536
+ recoveryShadowRoots = undefined
537
+ },
538
+
539
+ $rRollbackRecovery: function () {
540
+ if (stopped || !recoveryShadowRoots) {
541
+ return
542
+ }
543
+ var shadowRoots = recoveryShadowRoots
544
+ recoveryShadowRoots = undefined
545
+ // Retire observers registered by the incomplete snapshot before
546
+ // rebuilding the bounded observer set from the previous published
547
+ // baseline. Observer installation is complete for every registered
548
+ // root; explicit flushing is independently time-sliced.
549
+ retireActiveGeneration()
550
+ // This synchronous reinstall is deliberately limited to the abandoned
551
+ // replacement-baseline path. Paging it would leave a window where
552
+ // mutations inside a previously published root are not observed, so
553
+ // correctness takes precedence over latency on this rare failure path.
554
+ shadowRoots.forEach(function (shadowRoot) {
555
+ try {
556
+ if (shadowRootBelongsToObservedDocument(shadowRoot)) {
557
+ shadowRootsController.addShadowRoot(shadowRoot)
558
+ }
559
+ } catch (error) {
560
+ reportCleanupError(error)
561
+ }
53
562
  })
54
563
  }
55
564
  }
56
565
  return shadowRootsController
566
+
567
+ function createGeneration() {
568
+ return {
569
+ active: true,
570
+ id: ++nextGenerationId
571
+ }
572
+ }
573
+
574
+ function isGenerationActive(generation) {
575
+ return (
576
+ !stopped &&
577
+ generation.active &&
578
+ generation === activeGeneration
579
+ )
580
+ }
581
+
582
+ function shadowRootBelongsToObservedDocument(shadowRoot) {
583
+ try {
584
+ return Boolean(
585
+ shadowRoot.host &&
586
+ shadowRoot.host.isConnected &&
587
+ shadowRoot.host.ownerDocument === document
588
+ )
589
+ } catch (_) {
590
+ return false
591
+ }
592
+ }
593
+
594
+ function isEntryActive(entry) {
595
+ return (
596
+ entry.active &&
597
+ entry.registered &&
598
+ controllerByShadowRoot.get(entry.shadowRoot) === entry &&
599
+ isGenerationActive(entry.generation)
600
+ )
601
+ }
602
+
603
+ function createGatedCallback(entry, type, callback) {
604
+ if (!callback) {
605
+ return undefined
606
+ }
607
+ return function (value) {
608
+ if (
609
+ type === 'mutation' &&
610
+ isEntryShadowRootIgnored(entry)
611
+ ) {
612
+ if (!entry.unpublishedMutationOverflowReported) {
613
+ entry.unpublishedMutationOverflowReported = true
614
+ var unpublishedMutationOverflow = {
615
+ reason: 'shadow_root_mutation_before_publication'
616
+ }
617
+ if (
618
+ currentFlush &&
619
+ currentFlush.generation === entry.generation
620
+ ) {
621
+ currentFlush.overflow = unpublishedMutationOverflow
622
+ } else if (mutationOverflowCb) {
623
+ mutationOverflowCb(unpublishedMutationOverflow)
624
+ }
625
+ }
626
+ return
627
+ }
628
+ var pendingOverflowAfterReset =
629
+ type === 'overflow' &&
630
+ entry.pendingOverflowAfterReset &&
631
+ !stopped
632
+ if (!isEntryActive(entry) && !pendingOverflowAfterReset) {
633
+ return
634
+ }
635
+ if (pendingOverflowAfterReset) {
636
+ entry.pendingOverflowAfterReset = false
637
+ }
638
+ if (currentFlush && currentFlush.generation === entry.generation) {
639
+ if (type === 'overflow') {
640
+ currentFlush.overflow = value || {
641
+ reason: 'shadow_root_observer_overflow'
642
+ }
643
+ } else {
644
+ if (!reserveShadowRootFlushEvent(currentFlush, type, value)) {
645
+ var shouldReportOverflow =
646
+ !mutationResourceBudget ||
647
+ mutationResourceBudget.failOnce()
648
+ currentFlush.overflow = {
649
+ reason: 'aggregate_shadow_flush_watermark',
650
+ mutationApproxBytes:
651
+ currentFlush.eventApproxBytes +
652
+ estimateShadowRootFlushEventApproxBytes(type, value),
653
+ $rSuppressMutationOverflow: !shouldReportOverflow
654
+ }
655
+ return
656
+ }
657
+ currentFlush.events.push({
658
+ callback: callback,
659
+ entry: entry,
660
+ type: type,
661
+ value: value
662
+ })
663
+ }
664
+ return
665
+ }
666
+ callback(value)
667
+ }
668
+ }
669
+
670
+ function coalesceMutationEvents(events) {
671
+ var result = []
672
+ var mergedMutationEvent
673
+ events.forEach(function (event) {
674
+ if (event.type !== 'mutation') {
675
+ // Only adjacent mutation callbacks are one coalescing window. Input
676
+ // and other state events can arrive between paged root flushes; moving
677
+ // a later mutation ahead of that event would corrupt replay ordering.
678
+ mergedMutationEvent = undefined
679
+ result.push(event)
680
+ return
681
+ }
682
+ if (!mergedMutationEvent) {
683
+ mergedMutationEvent = {
684
+ callback: event.callback,
685
+ entries: [],
686
+ entry: event.entry,
687
+ type: event.type,
688
+ value: {
689
+ adds: [],
690
+ removes: [],
691
+ texts: [],
692
+ attributes: []
693
+ }
694
+ }
695
+ result.push(mergedMutationEvent)
696
+ }
697
+ mergedMutationEvent.entries.push(event.entry)
698
+ Array.prototype.push.apply(
699
+ mergedMutationEvent.value.adds,
700
+ event.value.adds
701
+ )
702
+ Array.prototype.push.apply(
703
+ mergedMutationEvent.value.removes,
704
+ event.value.removes
705
+ )
706
+ Array.prototype.push.apply(
707
+ mergedMutationEvent.value.texts,
708
+ event.value.texts
709
+ )
710
+ Array.prototype.push.apply(
711
+ mergedMutationEvent.value.attributes,
712
+ event.value.attributes
713
+ )
714
+ })
715
+ return result
716
+ }
717
+
718
+ function reserveShadowRootFlushEvent(flushState, type, value) {
719
+ var eventApproxBytes =
720
+ estimateShadowRootFlushEventApproxBytes(type, value)
721
+ var nextEventCount = flushState.eventCount + 1
722
+ var nextEventApproxBytes =
723
+ flushState.eventApproxBytes + eventApproxBytes
724
+ if (mutationResourceBudget) {
725
+ if (!flushState.eventBudgetReservation) {
726
+ flushState.eventBudgetReservation =
727
+ mutationResourceBudget.reserve(MUTATION_RESOURCE_FLUSH, {
728
+ eventCount: nextEventCount,
729
+ approxBytes: nextEventApproxBytes
730
+ })
731
+ if (!flushState.eventBudgetReservation) {
732
+ return false
733
+ }
734
+ } else if (
735
+ !flushState.eventBudgetReservation.update({
736
+ eventCount: nextEventCount,
737
+ approxBytes: nextEventApproxBytes
738
+ })
739
+ ) {
740
+ return false
741
+ }
742
+ }
743
+ flushState.eventCount = nextEventCount
744
+ flushState.eventApproxBytes = nextEventApproxBytes
745
+ return true
746
+ }
747
+
748
+ function releaseShadowRootFlushBudget(flushState) {
749
+ if (flushState && flushState.eventBudgetReservation) {
750
+ flushState.eventBudgetReservation()
751
+ flushState.eventBudgetReservation = undefined
752
+ }
753
+ }
754
+
755
+ function estimateShadowRootFlushEventApproxBytes(type, value) {
756
+ if (type === 'mutation') {
757
+ return getMutationPayloadApproxBytes(value)
758
+ }
759
+ var approxBytes = 64
760
+ if (!value || typeof value !== 'object') {
761
+ return (
762
+ approxBytes +
763
+ (typeof value === 'string' ? value.length * 2 : 0)
764
+ )
765
+ }
766
+ Object.keys(value).slice(0, 64).forEach(function (name) {
767
+ var propertyValue = value[name]
768
+ approxBytes += name.length * 2 + 16
769
+ if (typeof propertyValue === 'string') {
770
+ approxBytes += propertyValue.length * 2
771
+ }
772
+ })
773
+ return approxBytes
774
+ }
775
+
776
+ function isEntryShadowRootIgnored(entry) {
777
+ if (!isNodeIgnored) {
778
+ return false
779
+ }
780
+ try {
781
+ return isNodeIgnored(entry.shadowRoot)
782
+ } catch (_) {
783
+ return true
784
+ }
785
+ }
786
+
787
+ function createGatedShadowRootsController(entry) {
788
+ return {
789
+ $rMutationDependencyState: mutationDependencyState,
790
+ addShadowRoot: function (shadowRoot, provisionalOwner) {
791
+ if (isEntryActive(entry)) {
792
+ return shadowRootsController.addShadowRoot(
793
+ shadowRoot,
794
+ provisionalOwner
795
+ )
796
+ }
797
+ return false
798
+ },
799
+ removeShadowRoot: function (shadowRoot) {
800
+ if (isEntryActive(entry)) {
801
+ shadowRootsController.removeShadowRoot(shadowRoot)
802
+ }
803
+ },
804
+ cleanupDisconnectedShadowRoots: function () {
805
+ if (isEntryActive(entry)) {
806
+ shadowRootsController.cleanupDisconnectedShadowRoots()
807
+ }
808
+ },
809
+ reset: function () {
810
+ if (isEntryActive(entry)) {
811
+ // A removed-subtree traversal overflow resets the shadow-root
812
+ // registry immediately, then reports its reason through the
813
+ // observer overflow callback. Keep that one callback armed across
814
+ // the generation swap so recovery is not lost. Every other callback
815
+ // from the retired generation remains gated.
816
+ entry.pendingOverflowAfterReset = true
817
+ shadowRootsController.reset()
818
+ }
819
+ },
820
+ commitProvisionalShadowRoots: function (owner) {
821
+ shadowRootsController.commitProvisionalShadowRoots(owner)
822
+ },
823
+ rollbackProvisionalShadowRoots: function (owner) {
824
+ shadowRootsController.rollbackProvisionalShadowRoots(owner)
825
+ }
826
+ }
827
+ }
828
+
829
+ function failFlush(generation, overflow) {
830
+ releaseShadowRootFlushBudget(currentFlush)
831
+ currentFlush = undefined
832
+ if (generation === activeGeneration) {
833
+ retireActiveGeneration()
834
+ }
835
+ if (
836
+ !stopped &&
837
+ mutationOverflowCb &&
838
+ !overflow.$rSuppressMutationOverflow
839
+ ) {
840
+ mutationOverflowCb(overflow)
841
+ }
842
+ return false
843
+ }
844
+
845
+ function retireActiveGeneration() {
846
+ releaseShadowRootFlushBudget(currentFlush)
847
+ currentFlush = undefined
848
+ clearPendingShadowRootFlush()
849
+ clearPendingShadowRootBaselineReset()
850
+ clearDisconnectedShadowRootCleanup()
851
+ var retiredGeneration = activeGeneration
852
+ var retiredControllers = controllerByShadowRoot
853
+ retiredGeneration.active = false
854
+ // These sets describe dependencies inside one published replay baseline.
855
+ // Reusing them after a reset would make a node dropped in an old
856
+ // generation permanently poison later moves of the same live node.
857
+ mutationDependencyState.$rPublishedRoots = new WeakSet()
858
+ mutationDependencyState.$rLocallyDroppedRoots = new WeakSet()
859
+ activeGeneration = createGeneration()
860
+ controllerByShadowRoot = new Map()
861
+ retireControllerEntries(retiredControllers)
862
+ }
863
+
864
+ function clearPendingShadowRootFlush() {
865
+ pendingFlushIterator = undefined
866
+ pendingFlushGeneration = undefined
867
+ pendingFlushEntry = undefined
868
+ }
869
+
870
+ function clearPendingShadowRootBaselineReset() {
871
+ baselineResetIterator = undefined
872
+ baselineResetGeneration = undefined
873
+ }
874
+
875
+ function runDisconnectedShadowRootCleanupSlice() {
876
+ if (
877
+ !disconnectedCleanupIterator ||
878
+ disconnectedCleanupGeneration !== activeGeneration
879
+ ) {
880
+ disconnectedCleanupIterator = controllerByShadowRoot.entries()
881
+ disconnectedCleanupGeneration = activeGeneration
882
+ }
883
+ var deadline = getCurrentTimeImpl() + SHADOW_ROOT_CLEANUP_BUDGET_MS
884
+ var scanned = 0
885
+ while (scanned < SHADOW_ROOT_CLEANUP_BATCH_SIZE) {
886
+ var nextEntry = disconnectedCleanupIterator.next()
887
+ if (nextEntry.done) {
888
+ clearDisconnectedShadowRootCleanup()
889
+ return
890
+ }
891
+ scanned += 1
892
+ var shadowRoot = nextEntry.value[0]
893
+ if (!shadowRootBelongsToObservedDocument(shadowRoot)) {
894
+ try {
895
+ shadowRootsController.removeShadowRoot(shadowRoot)
896
+ } catch (_) {}
897
+ }
898
+ if (getCurrentTimeImpl() >= deadline) {
899
+ break
900
+ }
901
+ }
902
+ scheduleDisconnectedShadowRootCleanup()
903
+ }
904
+
905
+ function scheduleDisconnectedShadowRootCleanup() {
906
+ if (
907
+ disconnectedCleanupScheduled ||
908
+ !disconnectedCleanupIterator ||
909
+ stopped
910
+ ) {
911
+ return
912
+ }
913
+ disconnectedCleanupScheduled = true
914
+ setTimeout(function () {
915
+ disconnectedCleanupScheduled = false
916
+ if (!stopped && disconnectedCleanupIterator) {
917
+ runDisconnectedShadowRootCleanupSlice()
918
+ }
919
+ }, 0)
920
+ }
921
+
922
+ function clearDisconnectedShadowRootCleanup() {
923
+ disconnectedCleanupIterator = undefined
924
+ disconnectedCleanupGeneration = undefined
925
+ }
926
+
927
+ function retireControllerEntries(retiredControllers) {
928
+ if (retiredControllers.size > 0) {
929
+ // The generation (or provisional map membership) has already been
930
+ // invalidated, so native observer ingress is gated without walking every
931
+ // entry here. Physical observer/listener teardown remains bounded below.
932
+ var cleanupItem = {
933
+ controllers: retiredControllers,
934
+ iterator: retiredControllers.entries(),
935
+ next: undefined
936
+ }
937
+ retiredControllerCount += retiredControllers.size
938
+ if (cleanupQueueTail) {
939
+ cleanupQueueTail.next = cleanupItem
940
+ } else {
941
+ cleanupQueueHead = cleanupItem
942
+ }
943
+ cleanupQueueTail = cleanupItem
944
+ scheduleCleanup()
945
+ }
946
+ }
947
+
948
+ function scheduleCleanup() {
949
+ if (cleanupScheduled || !cleanupQueueHead) {
950
+ return
951
+ }
952
+ cleanupScheduled = true
953
+ try {
954
+ scheduleCleanupImpl(runCleanupSlice)
955
+ } catch (error) {
956
+ cleanupScheduled = false
957
+ reportCleanupError(error)
958
+ if (scheduleCleanupImpl !== defaultScheduleCleanup) {
959
+ cleanupScheduled = true
960
+ try {
961
+ defaultScheduleCleanup(runCleanupSlice)
962
+ } catch (fallbackError) {
963
+ cleanupScheduled = false
964
+ reportCleanupError(fallbackError)
965
+ }
966
+ }
967
+ }
968
+ }
969
+
970
+ function runCleanupSlice() {
971
+ cleanupScheduled = false
972
+ var deadline = getCurrentTimeImpl() + SHADOW_ROOT_CLEANUP_BUDGET_MS
973
+ var cleanedControllerCount = 0
974
+
975
+ while (cleanupQueueHead) {
976
+ var cleanupItem = cleanupQueueHead
977
+ var nextEntry = cleanupItem.iterator.next()
978
+ if (nextEntry.done) {
979
+ cleanupQueueHead = cleanupItem.next
980
+ cleanupItem.next = undefined
981
+ if (!cleanupQueueHead) {
982
+ cleanupQueueTail = undefined
983
+ }
984
+ continue
985
+ }
986
+
987
+ var shadowRoot = nextEntry.value[0]
988
+ var entry = nextEntry.value[1]
989
+ cleanupItem.controllers.delete(shadowRoot)
990
+ retiredControllerCount = Math.max(retiredControllerCount - 1, 0)
991
+ entry.active = false
992
+ entry.registered = false
993
+ entry.pendingOverflowAfterReset = false
994
+ stopControllerEntry(entry, false)
995
+ cleanedControllerCount += 1
996
+
997
+ if (
998
+ cleanedControllerCount >= SHADOW_ROOT_CLEANUP_BATCH_SIZE ||
999
+ getCurrentTimeImpl() >= deadline
1000
+ ) {
1001
+ break
1002
+ }
1003
+ }
1004
+
1005
+ if (!cleanupQueueHead) {
1006
+ return
1007
+ }
1008
+ scheduleCleanup()
1009
+ }
1010
+
1011
+ function deactivateControllerEntry(entry) {
1012
+ if (entry.mutationObserverDeactivated) {
1013
+ return
1014
+ }
1015
+ entry.mutationObserverDeactivated = true
1016
+ try {
1017
+ entry.deactivateMutationObserver()
1018
+ } catch (error) {
1019
+ return error
1020
+ }
1021
+ }
1022
+
1023
+ function stopControllerEntry(entry, shouldThrow) {
1024
+ var firstError = deactivateControllerEntry(entry)
1025
+ try {
1026
+ entry.stopMutationObserver()
1027
+ } catch (error) {
1028
+ if (!firstError) {
1029
+ firstError = error
1030
+ }
1031
+ }
1032
+ try {
1033
+ entry.stopInputObserver()
1034
+ } catch (error) {
1035
+ if (!firstError) {
1036
+ firstError = error
1037
+ }
1038
+ }
1039
+ if (firstError) {
1040
+ reportCleanupError(firstError)
1041
+ }
1042
+ if (firstError && shouldThrow) {
1043
+ throw firstError
1044
+ }
1045
+ }
1046
+
1047
+ function reportCleanupError(error) {
1048
+ if (!cleanupErrorCb) {
1049
+ return
1050
+ }
1051
+ try {
1052
+ cleanupErrorCb(error)
1053
+ } catch (_) {}
1054
+ }
1055
+
1056
+ function defaultScheduleCleanup(callback) {
1057
+ setTimeout(callback, 0)
1058
+ }
1059
+ }
1060
+
1061
+ function getCurrentTime() {
1062
+ if (typeof performance !== 'undefined' && performance.now) {
1063
+ return performance.now()
1064
+ }
1065
+ return Date.now()
1066
+ }
1067
+
1068
+ function subscribeToOpenShadowRoots(callback) {
1069
+ if (
1070
+ typeof Element === 'undefined' ||
1071
+ !Element.prototype ||
1072
+ typeof Element.prototype.attachShadow !== 'function'
1073
+ ) {
1074
+ return noop
1075
+ }
1076
+
1077
+ var subscriber = {
1078
+ callback: callback
1079
+ }
1080
+ attachShadowSubscribers.push(subscriber)
1081
+
1082
+ if (!attachShadowInstrumentation) {
1083
+ try {
1084
+ attachShadowInstrumentation = instrumentMethod(
1085
+ Element.prototype,
1086
+ 'attachShadow',
1087
+ function (call) {
1088
+ var host = call.target
1089
+ call.onPostCall(function (shadowRoot) {
1090
+ // Closed roots are intentionally outside the replay contract.
1091
+ // Checking the public host property avoids reading the caller's
1092
+ // options twice and only admits roots exposed as mode: "open".
1093
+ if (!shadowRoot || host.shadowRoot !== shadowRoot) {
1094
+ return
1095
+ }
1096
+ attachShadowSubscribers
1097
+ .slice()
1098
+ .forEach(function (activeSubscriber) {
1099
+ try {
1100
+ activeSubscriber.callback(shadowRoot, host)
1101
+ } catch (_) {}
1102
+ })
1103
+ })
1104
+ }
1105
+ )
1106
+ } catch (error) {
1107
+ removeAttachShadowSubscriber(subscriber)
1108
+ throw error
1109
+ }
1110
+ }
1111
+
1112
+ var subscriptionStopped = false
1113
+ return function () {
1114
+ if (subscriptionStopped) {
1115
+ return
1116
+ }
1117
+ subscriptionStopped = true
1118
+ removeAttachShadowSubscriber(subscriber)
1119
+ if (
1120
+ attachShadowSubscribers.length === 0 &&
1121
+ attachShadowInstrumentation
1122
+ ) {
1123
+ var instrumentation = attachShadowInstrumentation
1124
+ attachShadowInstrumentation = undefined
1125
+ instrumentation.stop()
1126
+ }
1127
+ }
1128
+ }
1129
+
1130
+ function removeAttachShadowSubscriber(subscriber) {
1131
+ var subscriberIndex = attachShadowSubscribers.indexOf(subscriber)
1132
+ if (subscriberIndex !== -1) {
1133
+ attachShadowSubscribers.splice(subscriberIndex, 1)
1134
+ }
57
1135
  }