@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
@@ -3,7 +3,8 @@ import {
3
3
  startsWith,
4
4
  isNodeShadowRoot,
5
5
  forEachChildNodes,
6
- hasChildNodes
6
+ hasChildNodes,
7
+ getParentNode
7
8
  } from '@cloudcare/browser-core'
8
9
  import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelectorsFromElement'
9
10
  import {
@@ -27,12 +28,14 @@ import {
27
28
  getElementInputValue,
28
29
  getHiddenElementPlaceholderSize,
29
30
  switchToAbsoluteUrl,
30
- serializeStyleSheets,
31
+ createStyleSheetsSerializerTask,
31
32
  absoluteToDoc,
32
33
  getAbsoluteSrcsetString,
33
34
  isSVGElement,
34
35
  getHref,
35
- getCssRulesString
36
+ getCssRulesString,
37
+ STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT,
38
+ STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES
36
39
  } from './serializationUtils'
37
40
  import {
38
41
  isLongDataUrl,
@@ -48,6 +51,21 @@ export var SerializationContextStatus = {
48
51
  MUTATION: 2
49
52
  }
50
53
 
54
+ export var SERIALIZATION_MAX_SYNC_DURATION_MS = 32
55
+ export var SERIALIZATION_MAX_NODE_COUNT = 50000
56
+ export var SERIALIZATION_MAX_DEPTH = 1000
57
+ export var SERIALIZATION_MAX_STRING_LENGTH =
58
+ STYLESHEET_SERIALIZATION_MAX_CHARACTER_COUNT
59
+ export var SERIALIZATION_MAX_ATTRIBUTE_COUNT = 1000
60
+ export var SERIALIZATION_MAX_NODE_SOURCE_LENGTH = 200000
61
+ export var SERIALIZATION_MAX_MUTATION_SOURCE_LENGTH = 64 * 1024
62
+ export var SERIALIZATION_TRUNCATION_MARK = '…'
63
+ // A full snapshot is followed by a synchronous JSON serialization before it
64
+ // enters the asynchronous encoder. Keep that unavoidable main-thread step
65
+ // well below the segment collection's 4 MiB backlog watermark.
66
+ export var SERIALIZATION_MAX_APPROX_BYTES = 1024 * 1024
67
+ var serializedNodeApproxBytes = new WeakMap()
68
+
51
69
  export function serializeDocument(
52
70
  document,
53
71
  configuration,
@@ -62,23 +80,13 @@ export function serializeDocument(
62
80
  }
63
81
 
64
82
  export function serializeNodeWithId(node, options) {
65
- var serializedNodeDescription = describeSerializedNode(node, options)
66
- if (!serializedNodeDescription) {
83
+ var serializerTask = createMutationSerializerTask(node, options)
84
+ if (!serializerTask) {
67
85
  return null
68
86
  }
69
-
70
- var serializedNodeWithId = assignSerializedNodeId(
71
- node,
72
- serializedNodeDescription.serializedNode,
73
- options
74
- )
75
- if (serializedNodeDescription.shouldSerializeChildren) {
76
- serializedNodeWithId.childNodes = serializeChildNodes(
77
- node,
78
- serializedNodeDescription.childNodesOptions
79
- )
80
- }
81
- return serializedNodeWithId
87
+ return completeSerializerTaskSynchronously(serializerTask)
88
+ ? serializerTask.serializedNode
89
+ : null
82
90
  }
83
91
 
84
92
  export function serializeNodeWithIdForMutation(node, options) {
@@ -86,8 +94,9 @@ export function serializeNodeWithIdForMutation(node, options) {
86
94
  if (!mutationSerializerTask) {
87
95
  return null
88
96
  }
89
- mutationSerializerTask.advance(Infinity)
90
- return mutationSerializerTask.serializedNode
97
+ return completeSerializerTaskSynchronously(mutationSerializerTask)
98
+ ? mutationSerializerTask.serializedNode
99
+ : null
91
100
  }
92
101
 
93
102
  export function createMutationSerializerTask(node, options) {
@@ -95,67 +104,246 @@ export function createMutationSerializerTask(node, options) {
95
104
  if (!rootNodeDescription) {
96
105
  return null
97
106
  }
107
+ if (rootNodeDescription.isSerializationComplexityOverflow) {
108
+ return createSerializationComplexityOverflowTask()
109
+ }
98
110
 
99
111
  var serializedRootNode = assignSerializedNodeId(
100
112
  node,
101
113
  rootNodeDescription.serializedNode,
102
114
  options
103
115
  )
116
+ var approxBytes = estimateSerializedNodeShallowBytes(serializedRootNode)
117
+ serializedNodeApproxBytes.set(serializedRootNode, approxBytes)
104
118
  var stack = []
119
+ var pendingStyleSheetTasks = []
120
+ var styleSheetApproxBytes = 0
105
121
 
106
- if (rootNodeDescription.shouldSerializeChildren) {
107
- pushChildNodes(node, serializedRootNode, rootNodeDescription.childNodesOptions)
122
+ if (rootNodeDescription.styleSheetTask) {
123
+ pendingStyleSheetTasks.push(rootNodeDescription.styleSheetTask)
124
+ }
125
+
126
+ if (
127
+ rootNodeDescription.shouldSerializeChildren &&
128
+ hasChildNodes(node)
129
+ ) {
130
+ pushChildIterator(
131
+ node,
132
+ serializedRootNode,
133
+ rootNodeDescription.childNodesOptions
134
+ )
108
135
  }
109
136
 
110
137
  return {
111
138
  serializedNode: serializedRootNode,
112
- isComplete: stack.length === 0,
113
- advance: function (deadline) {
114
- while (stack.length && getCurrentTime() < deadline) {
115
- var current = stack.pop()
139
+ isComplete:
140
+ stack.length === 0 && pendingStyleSheetTasks.length === 0,
141
+ processedNodeCount: 1,
142
+ approxBytes: approxBytes,
143
+ advance: function (deadline, maxNodeCount, maxApproxBytes) {
144
+ if (typeof maxNodeCount !== 'number') {
145
+ maxNodeCount = SERIALIZATION_MAX_NODE_COUNT
146
+ }
147
+ if (typeof maxApproxBytes !== 'number') {
148
+ maxApproxBytes = SERIALIZATION_MAX_APPROX_BYTES
149
+ }
150
+ if (
151
+ this.approxBytes > maxApproxBytes ||
152
+ ((stack.length > 0 || pendingStyleSheetTasks.length > 0) &&
153
+ this.approxBytes >= maxApproxBytes)
154
+ ) {
155
+ this.isComplete = false
156
+ this.isMaxApproxBytesReached = true
157
+ return false
158
+ }
159
+ while (
160
+ (stack.length || pendingStyleSheetTasks.length) &&
161
+ this.processedNodeCount < maxNodeCount &&
162
+ this.approxBytes < maxApproxBytes &&
163
+ !this.isMaxDepthReached &&
164
+ !this.isMaxNodeComplexityReached &&
165
+ getCurrentTime() < deadline
166
+ ) {
167
+ if (pendingStyleSheetTasks.length) {
168
+ var styleSheetTask = pendingStyleSheetTasks[0]
169
+ var previousStyleSheetApproxBytes = styleSheetTask.approxBytes
170
+ var styleSheetHardMaxApproxBytes =
171
+ previousStyleSheetApproxBytes +
172
+ Math.max(
173
+ STYLESHEET_SERIALIZATION_MAX_SNAPSHOT_BYTES -
174
+ styleSheetApproxBytes,
175
+ 0
176
+ )
177
+ var styleSheetMaxApproxBytes = Math.min(
178
+ maxApproxBytes -
179
+ this.approxBytes +
180
+ previousStyleSheetApproxBytes,
181
+ styleSheetHardMaxApproxBytes
182
+ )
183
+ var isFullSnapshotSerialization =
184
+ options.serializationContext.status ===
185
+ SerializationContextStatus.INITIAL_FULL_SNAPSHOT ||
186
+ options.serializationContext.status ===
187
+ SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT
188
+ var styleSheetCompleted = styleSheetTask.advance(
189
+ deadline,
190
+ styleSheetMaxApproxBytes,
191
+ isFullSnapshotSerialization
192
+ ? styleSheetHardMaxApproxBytes
193
+ : styleSheetMaxApproxBytes
194
+ )
195
+ var styleSheetApproxBytesDelta =
196
+ styleSheetTask.approxBytes - previousStyleSheetApproxBytes
197
+ this.approxBytes += styleSheetApproxBytesDelta
198
+ styleSheetApproxBytes += styleSheetApproxBytesDelta
199
+ serializedNodeApproxBytes.set(
200
+ serializedRootNode,
201
+ this.approxBytes
202
+ )
203
+ if (styleSheetTask.isMaxApproxBytesReached) {
204
+ this.isMaxApproxBytesReached = true
205
+ break
206
+ }
207
+ if (!styleSheetCompleted) {
208
+ break
209
+ }
210
+ pendingStyleSheetTasks.shift()
211
+ continue
212
+ }
213
+ var iterator = stack[stack.length - 1]
214
+ var childNode = getNextUnprocessedChild(iterator)
215
+ if (!childNode && iterator.shadowRoot) {
216
+ childNode = iterator.shadowRoot
217
+ iterator.shadowRoot = undefined
218
+ } else if (!childNode) {
219
+ stack.pop()
220
+ continue
221
+ }
222
+
116
223
  var childNodeDescription = describeSerializedNode(
117
- current.node,
118
- current.options
224
+ childNode,
225
+ iterator.options
119
226
  )
120
227
  if (!childNodeDescription) {
121
228
  continue
122
229
  }
230
+ if (childNodeDescription.isSerializationComplexityOverflow) {
231
+ this.isMaxNodeComplexityReached = true
232
+ break
233
+ }
123
234
 
124
235
  var serializedChildNode = assignSerializedNodeId(
125
- current.node,
236
+ childNode,
126
237
  childNodeDescription.serializedNode,
127
- current.options
238
+ iterator.options
128
239
  )
129
- current.parentSerializedNode.childNodes.push(serializedChildNode)
240
+ this.processedNodeCount += 1
241
+ this.approxBytes += estimateSerializedNodeShallowBytes(
242
+ serializedChildNode
243
+ )
244
+ serializedNodeApproxBytes.set(
245
+ serializedRootNode,
246
+ this.approxBytes
247
+ )
248
+ iterator.parentSerializedNode.childNodes.push(serializedChildNode)
130
249
 
131
- if (childNodeDescription.shouldSerializeChildren) {
132
- pushChildNodes(
133
- current.node,
134
- serializedChildNode,
135
- childNodeDescription.childNodesOptions
250
+ if (childNodeDescription.styleSheetTask) {
251
+ pendingStyleSheetTasks.push(
252
+ childNodeDescription.styleSheetTask
136
253
  )
137
254
  }
255
+
256
+ if (
257
+ childNodeDescription.shouldSerializeChildren &&
258
+ hasChildNodes(childNode)
259
+ ) {
260
+ if (
261
+ !pushChildIterator(
262
+ childNode,
263
+ serializedChildNode,
264
+ childNodeDescription.childNodesOptions
265
+ )
266
+ ) {
267
+ this.isMaxDepthReached = true
268
+ }
269
+ }
138
270
  }
139
- this.isComplete = stack.length === 0
271
+ this.isMaxApproxBytesReached =
272
+ Boolean(
273
+ pendingStyleSheetTasks.length &&
274
+ pendingStyleSheetTasks[0].isMaxApproxBytesReached
275
+ ) ||
276
+ this.approxBytes > maxApproxBytes ||
277
+ ((stack.length > 0 || pendingStyleSheetTasks.length > 0) &&
278
+ this.approxBytes >= maxApproxBytes)
279
+ this.isMaxNodeCountReached =
280
+ stack.length > 0 && this.processedNodeCount >= maxNodeCount
281
+ this.isComplete =
282
+ stack.length === 0 &&
283
+ pendingStyleSheetTasks.length === 0 &&
284
+ !this.isMaxApproxBytesReached &&
285
+ !this.isMaxDepthReached &&
286
+ !this.isMaxNodeComplexityReached
140
287
  return this.isComplete
141
288
  }
142
289
  }
143
290
 
144
- function pushChildNodes(parentNode, parentSerializedNode, childNodesOptions) {
145
- var childNodes = []
146
- forEachChildNodes(parentNode, function (childNode) {
147
- childNodes.push(childNode)
291
+ function pushChildIterator(
292
+ parentNode,
293
+ parentSerializedNode,
294
+ childNodesOptions
295
+ ) {
296
+ if (stack.length >= SERIALIZATION_MAX_DEPTH) {
297
+ return false
298
+ }
299
+ stack.push({
300
+ parentNode: parentNode,
301
+ nextChild: parentNode.firstChild,
302
+ lastProcessedChild: undefined,
303
+ shadowRoot: parentNode.shadowRoot || undefined,
304
+ options: childNodesOptions,
305
+ parentSerializedNode: parentSerializedNode
148
306
  })
149
- for (var i = childNodes.length - 1; i >= 0; i--) {
150
- stack.push({
151
- node: childNodes[i],
152
- options: childNodesOptions,
153
- parentSerializedNode: parentSerializedNode
154
- })
307
+ return true
308
+ }
309
+
310
+ function getNextUnprocessedChild(iterator) {
311
+ var childNode = iterator.nextChild
312
+ if (
313
+ (!childNode || childNode.parentNode !== iterator.parentNode) &&
314
+ iterator.lastProcessedChild &&
315
+ iterator.lastProcessedChild.parentNode === iterator.parentNode
316
+ ) {
317
+ childNode = iterator.lastProcessedChild.nextSibling
318
+ }
319
+ if (!childNode) {
320
+ iterator.nextChild = undefined
321
+ return
155
322
  }
323
+
324
+ iterator.lastProcessedChild = childNode
325
+ iterator.nextChild = childNode.nextSibling
326
+ return childNode
156
327
  }
157
328
  }
158
329
 
330
+ function createSerializationComplexityOverflowTask() {
331
+ return {
332
+ serializedNode: null,
333
+ isComplete: false,
334
+ processedNodeCount: 0,
335
+ approxBytes: 0,
336
+ isMaxNodeComplexityReached: true,
337
+ advance: function () {
338
+ return false
339
+ }
340
+ }
341
+ }
342
+
343
+ var SERIALIZATION_COMPLEXITY_OVERFLOW_DESCRIPTION = {
344
+ isSerializationComplexityOverflow: true
345
+ }
346
+
159
347
  function describeSerializedNode(node, options) {
160
348
  switch (node.nodeType) {
161
349
  case node.DOCUMENT_NODE:
@@ -195,12 +383,18 @@ export function serializeDocumentNode(document, options) {
195
383
  }
196
384
 
197
385
  function describeDocumentNode(document, options) {
386
+ var styleSheetTask = createStyleSheetsSerializerTask(
387
+ document.adoptedStyleSheets
388
+ )
198
389
  return {
199
390
  serializedNode: {
200
391
  type: NodeType.Document,
201
392
  childNodes: [],
202
- adoptedStyleSheets: serializeStyleSheets(document.adoptedStyleSheets)
393
+ adoptedStyleSheets: styleSheetTask
394
+ ? styleSheetTask.serializedStyleSheets
395
+ : undefined
203
396
  },
397
+ styleSheetTask: styleSheetTask,
204
398
  shouldSerializeChildren: true,
205
399
  childNodesOptions: options
206
400
  }
@@ -221,19 +415,37 @@ function serializeDocumentFragmentNode(element, options) {
221
415
 
222
416
  function describeDocumentFragmentNode(element, options) {
223
417
  var isShadowRoot = isNodeShadowRoot(element)
418
+ var shouldSerializeChildren = true
224
419
  if (isShadowRoot) {
225
- options.serializationContext.shadowRootsController.addShadowRoot(element)
420
+ var shadowRootsController =
421
+ options.serializationContext.shadowRootsController
422
+ var publicationToken = options.serializationContext.publicationToken
423
+ var registrationResult = publicationToken
424
+ ? shadowRootsController.addShadowRoot(element, publicationToken)
425
+ : shadowRootsController.addShadowRoot(element)
426
+ if (registrationResult === false) {
427
+ return SERIALIZATION_COMPLEXITY_OVERFLOW_DESCRIPTION
428
+ }
429
+ // A controller may defer its own setup, but that must never turn an open
430
+ // ShadowRoot into a permanently empty replay subtree. The default
431
+ // controller observes every registered root and only pages flush work.
432
+ shouldSerializeChildren = true
226
433
  }
434
+ var styleSheetTask =
435
+ isShadowRoot && shouldSerializeChildren
436
+ ? createStyleSheetsSerializerTask(element.adoptedStyleSheets)
437
+ : null
227
438
  return {
228
439
  serializedNode: {
229
440
  type: NodeType.DocumentFragment,
230
441
  childNodes: [],
231
442
  isShadowRoot: isShadowRoot,
232
- adoptedStyleSheets: isShadowRoot
233
- ? serializeStyleSheets(element.adoptedStyleSheets)
443
+ adoptedStyleSheets: styleSheetTask
444
+ ? styleSheetTask.serializedStyleSheets
234
445
  : undefined
235
446
  },
236
- shouldSerializeChildren: true,
447
+ styleSheetTask: styleSheetTask,
448
+ shouldSerializeChildren: shouldSerializeChildren,
237
449
  childNodesOptions: options
238
450
  }
239
451
  }
@@ -273,9 +485,8 @@ function describeElementNode(element, options) {
273
485
 
274
486
  if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
275
487
  var placeholderSize = getHiddenElementPlaceholderSize(element)
276
- var attributes = {
277
- [PRIVACY_ATTR_NAME]: PRIVACY_ATTR_VALUE_HIDDEN
278
- }
488
+ var attributes = {}
489
+ attributes[PRIVACY_ATTR_NAME] = PRIVACY_ATTR_VALUE_HIDDEN
279
490
  if (placeholderSize.width) {
280
491
  attributes.rr_width = placeholderSize.width
281
492
  }
@@ -304,10 +515,20 @@ function describeElementNode(element, options) {
304
515
  nodePrivacyLevel,
305
516
  options
306
517
  )
307
-
308
518
  var shouldSerializeChildren = false
309
519
  var childNodesSerializationOptions
310
- if (hasChildNodes(element) && tagName !== 'style') {
520
+ // Style children are normally replaced by the normalized `_cssText`
521
+ // attribute. If CSSOM cannot be read, keep the original text instead of
522
+ // emitting an empty style node and making the whole replay unstyled. The
523
+ // text serializer applies its explicit privacy-safe truncation marker if a
524
+ // single raw stylesheet cannot fit the node budget.
525
+ var shouldSerializeStyleFallback =
526
+ tagName === 'style' &&
527
+ !attributes._cssText
528
+ if (
529
+ hasChildNodes(element) &&
530
+ (tagName !== 'style' || shouldSerializeStyleFallback)
531
+ ) {
311
532
  // OBJECT POOLING OPTIMIZATION:
312
533
  // We should not create a new object systematically as it could impact performances. Try to reuse
313
534
  // the same object as much as possible, and clone it only if we need to.
@@ -366,7 +587,12 @@ function serializeTextNode(textNode, options) {
366
587
  }
367
588
  return {
368
589
  type: NodeType.Text,
369
- textContent: textContent
590
+ // Apply privacy before truncation. Taking a raw prefix first would leak
591
+ // text when a custom shouldMaskNode callback masks this node.
592
+ textContent: truncateSerializedValue(
593
+ textContent,
594
+ getMaxNodeSourceLength(options)
595
+ )
370
596
  // isStyle: parentTagName === 'STYLE' ? true : undefined
371
597
  }
372
598
  }
@@ -381,12 +607,14 @@ function serializeCDataNode() {
381
607
  export function serializeChildNodes(node, options) {
382
608
  var result = []
383
609
  forEachChildNodes(node, function (childNode) {
384
- var serializedChildNode = serializeNodeWithId(childNode, options)
385
- if (serializedChildNode) {
386
- result.push(serializedChildNode)
610
+ var serializerTask = createMutationSerializerTask(childNode, options)
611
+ if (
612
+ serializerTask &&
613
+ completeSerializerTaskSynchronously(serializerTask)
614
+ ) {
615
+ result.push(serializerTask.serializedNode)
387
616
  }
388
617
  })
389
- // node.childNodes.forEach()
390
618
  return result
391
619
  }
392
620
 
@@ -398,6 +626,9 @@ function assignSerializedNodeId(node, serializedNode, options) {
398
626
  if (options.serializedNodeIds) {
399
627
  options.serializedNodeIds.add(id)
400
628
  }
629
+ if (options.onSerializedNode) {
630
+ options.onSerializedNode(node, getParentNode(node))
631
+ }
401
632
  return serializedNodeWithId
402
633
  }
403
634
 
@@ -408,6 +639,71 @@ function getCurrentTime() {
408
639
  return Date.now()
409
640
  }
410
641
 
642
+ function completeSerializerTaskSynchronously(serializerTask) {
643
+ return serializerTask.advance(
644
+ getCurrentTime() + SERIALIZATION_MAX_SYNC_DURATION_MS,
645
+ SERIALIZATION_MAX_NODE_COUNT,
646
+ SERIALIZATION_MAX_APPROX_BYTES
647
+ )
648
+ }
649
+
650
+ export function getSerializedNodeApproxBytes(serializedNode) {
651
+ return serializedNodeApproxBytes.get(serializedNode)
652
+ }
653
+
654
+ function estimateSerializedNodeShallowBytes(serializedNode) {
655
+ var approxBytes = 2
656
+ var pendingValues = [serializedNode]
657
+ while (pendingValues.length) {
658
+ var value = pendingValues.pop()
659
+ if (typeof value === 'string') {
660
+ approxBytes += estimateJsonStringBytes(value)
661
+ } else if (typeof value === 'number') {
662
+ approxBytes += 16
663
+ } else if (typeof value === 'boolean') {
664
+ approxBytes += 5
665
+ } else if (value && typeof value === 'object') {
666
+ if (Array.isArray(value)) {
667
+ // childNodes are accounted for one node at a time by the serializer.
668
+ if (value !== serializedNode.childNodes) {
669
+ for (var index = 0; index < value.length; index += 1) {
670
+ pendingValues.push(value[index])
671
+ }
672
+ }
673
+ approxBytes += value.length + 2
674
+ } else {
675
+ Object.keys(value).forEach(function (key) {
676
+ if (key === 'childNodes' && value === serializedNode) {
677
+ return
678
+ }
679
+ approxBytes += estimateJsonStringBytes(key) + 2
680
+ pendingValues.push(value[key])
681
+ })
682
+ }
683
+ } else {
684
+ approxBytes += 4
685
+ }
686
+ }
687
+ return approxBytes
688
+ }
689
+
690
+ function estimateJsonStringBytes(value) {
691
+ if (value.length > SERIALIZATION_MAX_STRING_LENGTH) {
692
+ return SERIALIZATION_MAX_APPROX_BYTES + 1
693
+ }
694
+ var bytes = 4
695
+ for (var index = 0; index < value.length; index += 1) {
696
+ var characterCode = value.charCodeAt(index)
697
+ bytes +=
698
+ characterCode <= 0x1f ||
699
+ characterCode === 0x22 ||
700
+ characterCode === 0x5c
701
+ ? 12
702
+ : 2
703
+ }
704
+ return bytes
705
+ }
706
+
411
707
  export function serializeAttribute(
412
708
  element,
413
709
  nodePrivacyLevel,
@@ -475,6 +771,28 @@ export function serializeAttribute(
475
771
  return attributeValue
476
772
  }
477
773
 
774
+ /**
775
+ * Bounds a value after privacy/sanitization has been applied.
776
+ */
777
+ export function truncateSerializedValue(value, maxLength) {
778
+ if (
779
+ typeof value !== 'string' ||
780
+ typeof maxLength !== 'number' ||
781
+ value.length <= maxLength
782
+ ) {
783
+ return value
784
+ }
785
+ if (maxLength <= SERIALIZATION_TRUNCATION_MARK.length) {
786
+ return SERIALIZATION_TRUNCATION_MARK.slice(0, maxLength)
787
+ }
788
+ return (
789
+ value.slice(
790
+ 0,
791
+ maxLength - SERIALIZATION_TRUNCATION_MARK.length
792
+ ) + SERIALIZATION_TRUNCATION_MARK
793
+ )
794
+ }
795
+
478
796
  var _nextId = 1
479
797
  function generateNextId() {
480
798
  return _nextId++
@@ -527,10 +845,24 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
527
845
  var safeAttrs = {}
528
846
  var tagName = getValidTagName(element.tagName)
529
847
  var doc = element.ownerDocument
848
+ var serializedSourceLength = 0
849
+ var maxNodeSourceLength = getMaxNodeSourceLength(options)
530
850
 
531
- for (var i = 0; i < element.attributes.length; i += 1) {
851
+ for (
852
+ var i = 0;
853
+ i < element.attributes.length &&
854
+ i < SERIALIZATION_MAX_ATTRIBUTE_COUNT;
855
+ i += 1
856
+ ) {
532
857
  var attribute = element.attributes.item(i)
533
858
  var attributeName = attribute.name
859
+ var remainingSourceLength =
860
+ maxNodeSourceLength -
861
+ serializedSourceLength -
862
+ attributeName.length
863
+ if (remainingSourceLength <= 0) {
864
+ break
865
+ }
534
866
  var attributeValue = serializeAttribute(
535
867
  element,
536
868
  nodePrivacyLevel,
@@ -538,12 +870,30 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
538
870
  options.configuration
539
871
  )
540
872
  if (attributeValue !== null) {
541
- safeAttrs[attributeName] = transformAttribute(
873
+ // Privacy and data-url sanitization happen before either bound. The
874
+ // first bound prevents URL/CSS normalization from scanning an
875
+ // unbounded value; the second covers an absolute base URL added by the
876
+ // transform.
877
+ var boundedAttributeValue = truncateSerializedValue(
878
+ attributeValue,
879
+ remainingSourceLength
880
+ )
881
+ var transformedAttributeValue = transformAttribute(
542
882
  doc,
543
883
  tagName,
544
884
  attributeName,
545
- attributeValue
885
+ boundedAttributeValue
886
+ )
887
+ transformedAttributeValue = truncateSerializedValue(
888
+ transformedAttributeValue,
889
+ remainingSourceLength
546
890
  )
891
+ safeAttrs[attributeName] = transformedAttributeValue
892
+ serializedSourceLength +=
893
+ attributeName.length +
894
+ (typeof transformedAttributeValue === 'string'
895
+ ? transformedAttributeValue.length
896
+ : 8)
547
897
  }
548
898
  }
549
899
 
@@ -560,7 +910,16 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
560
910
  nodePrivacyLevel
561
911
  )
562
912
  if (formValue !== undefined) {
563
- safeAttrs.value = formValue
913
+ // getElementInputValue masks private input before truncation.
914
+ safeAttrs.value = truncateSerializedValue(
915
+ formValue,
916
+ Math.max(
917
+ maxNodeSourceLength -
918
+ serializedSourceLength -
919
+ 'value'.length,
920
+ SERIALIZATION_TRUNCATION_MARK.length
921
+ )
922
+ )
564
923
  }
565
924
  }
566
925
 
@@ -661,6 +1020,13 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
661
1020
  return safeAttrs
662
1021
  }
663
1022
 
1023
+ function getMaxNodeSourceLength(options) {
1024
+ return options.serializationContext.status ===
1025
+ SerializationContextStatus.MUTATION
1026
+ ? SERIALIZATION_MAX_MUTATION_SOURCE_LENGTH
1027
+ : SERIALIZATION_MAX_NODE_SOURCE_LENGTH
1028
+ }
1029
+
664
1030
  function getStyleSheetByHref(serializationContext, doc, href) {
665
1031
  if (!href) {
666
1032
  return undefined