@cloudcare/browser-rum 3.3.24 → 3.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +33 -0
  2. package/README.zh.md +30 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/disabledRumPublicApi.js +5 -0
  6. package/cjs/boot/disabledRumPublicApi.js.map +1 -1
  7. package/cjs/boot/initCallbacks.js +25 -0
  8. package/cjs/boot/initCallbacks.js.map +1 -0
  9. package/cjs/boot/perStartRum.js +99 -50
  10. package/cjs/boot/perStartRum.js.map +1 -1
  11. package/cjs/boot/recorderApi.js +36 -1
  12. package/cjs/boot/recorderApi.js.map +1 -1
  13. package/cjs/boot/rum.js +8 -9
  14. package/cjs/boot/rum.js.map +1 -1
  15. package/cjs/boot/rumPublicApi.js +6 -7
  16. package/cjs/boot/rumPublicApi.js.map +1 -1
  17. package/cjs/boot/startRecording.js +2 -0
  18. package/cjs/boot/startRecording.js.map +1 -1
  19. package/cjs/domain/configuration.js +15 -2
  20. package/cjs/domain/configuration.js.map +1 -1
  21. package/cjs/domain/contexts/urlContexts.js +32 -21
  22. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  23. package/cjs/domain/contexts/viewContexts.js +1 -1
  24. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  25. package/cjs/domain/deflate/deflateWorker.js +39 -27
  26. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  27. package/cjs/domain/privacy.js +79 -107
  28. package/cjs/domain/privacy.js.map +1 -1
  29. package/cjs/domain/replay/record/canvasCommandCapture.js +87 -179
  30. package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
  31. package/cjs/domain/replay/record/canvasCommandObserver.js +10 -6
  32. package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
  33. package/cjs/domain/replay/record/canvasCommandObserverStub.js +24 -0
  34. package/cjs/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  35. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +3 -2
  36. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  37. package/cjs/domain/replay/record/canvasContext.js +15 -0
  38. package/cjs/domain/replay/record/canvasContext.js.map +1 -1
  39. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  40. package/cjs/domain/replay/record/canvasObserver.js +3 -0
  41. package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
  42. package/cjs/domain/replay/record/canvasWebGLPluginHost.js +5 -1
  43. package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  44. package/cjs/domain/replay/record/mutationObserver.js +3 -12
  45. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  46. package/cjs/domain/replay/record/observers.js +3 -7
  47. package/cjs/domain/replay/record/observers.js.map +1 -1
  48. package/cjs/domain/replay/record/record.js +15 -2
  49. package/cjs/domain/replay/record/record.js.map +1 -1
  50. package/cjs/domain/replay/record/serializationUtils.js +8 -23
  51. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  52. package/cjs/domain/replay/record/serialize.js +19 -33
  53. package/cjs/domain/replay/record/serialize.js.map +1 -1
  54. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +21 -6
  55. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  56. package/cjs/domain/replay/segmentCollection/segmentCollection.js +91 -143
  57. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  58. package/cjs/domain/replayCanvasSupported.js +8 -0
  59. package/cjs/domain/replayCanvasSupported.js.map +1 -0
  60. package/cjs/domain/requestCollection.js +38 -39
  61. package/cjs/domain/requestCollection.js.map +1 -1
  62. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  63. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  64. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js +143 -0
  65. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  66. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  67. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  68. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +91 -66
  69. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js +11 -9
  71. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  72. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +35 -50
  73. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  74. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +7 -1
  75. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  76. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  77. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  78. package/cjs/domain/rumEventsCollection/view/trackViews.js +3 -0
  79. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  80. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
  81. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  82. package/cjs/domain/tracing/skywalkingTracer.js +4 -50
  83. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  84. package/cjs/domain/tracing/tracer.js +26 -3
  85. package/cjs/domain/tracing/tracer.js.map +1 -1
  86. package/esm/boot/buildEnv.js +1 -1
  87. package/esm/boot/disabledRumPublicApi.js +1 -1
  88. package/esm/boot/disabledRumPublicApi.js.map +1 -1
  89. package/esm/boot/initCallbacks.js +2 -0
  90. package/esm/boot/initCallbacks.js.map +1 -0
  91. package/esm/boot/perStartRum.js +1 -1
  92. package/esm/boot/perStartRum.js.map +1 -1
  93. package/esm/boot/recorderApi.js +1 -1
  94. package/esm/boot/recorderApi.js.map +1 -1
  95. package/esm/boot/rum.js +1 -1
  96. package/esm/boot/rum.js.map +1 -1
  97. package/esm/boot/rumPublicApi.js +1 -1
  98. package/esm/boot/rumPublicApi.js.map +1 -1
  99. package/esm/boot/startRecording.js +1 -1
  100. package/esm/boot/startRecording.js.map +1 -1
  101. package/esm/domain/configuration.js +1 -1
  102. package/esm/domain/configuration.js.map +1 -1
  103. package/esm/domain/contexts/urlContexts.js +1 -1
  104. package/esm/domain/contexts/urlContexts.js.map +1 -1
  105. package/esm/domain/contexts/viewContexts.js +1 -1
  106. package/esm/domain/contexts/viewContexts.js.map +1 -1
  107. package/esm/domain/deflate/deflateWorker.js +1 -1
  108. package/esm/domain/deflate/deflateWorker.js.map +1 -1
  109. package/esm/domain/privacy.js +1 -1
  110. package/esm/domain/privacy.js.map +1 -1
  111. package/esm/domain/replay/record/canvasCommandCapture.js +1 -1
  112. package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
  113. package/esm/domain/replay/record/canvasCommandObserver.js +1 -1
  114. package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
  115. package/esm/domain/replay/record/canvasCommandObserverStub.js +2 -0
  116. package/esm/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  117. package/esm/domain/replay/record/canvasCommandSerializeArgs.js +1 -1
  118. package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  119. package/esm/domain/replay/record/canvasContext.js +1 -1
  120. package/esm/domain/replay/record/canvasContext.js.map +1 -1
  121. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  122. package/esm/domain/replay/record/canvasObserver.js +1 -1
  123. package/esm/domain/replay/record/canvasObserver.js.map +1 -1
  124. package/esm/domain/replay/record/canvasWebGLPluginHost.js +1 -1
  125. package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  126. package/esm/domain/replay/record/mutationObserver.js +1 -1
  127. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  128. package/esm/domain/replay/record/observers.js +1 -1
  129. package/esm/domain/replay/record/observers.js.map +1 -1
  130. package/esm/domain/replay/record/record.js +1 -1
  131. package/esm/domain/replay/record/record.js.map +1 -1
  132. package/esm/domain/replay/record/serializationUtils.js +1 -1
  133. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  134. package/esm/domain/replay/record/serialize.js +1 -1
  135. package/esm/domain/replay/record/serialize.js.map +1 -1
  136. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  137. package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  138. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  139. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  140. package/esm/domain/replayCanvasSupported.js +2 -0
  141. package/esm/domain/replayCanvasSupported.js.map +1 -0
  142. package/esm/domain/requestCollection.js +1 -1
  143. package/esm/domain/requestCollection.js.map +1 -1
  144. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  145. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  146. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js +2 -0
  147. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  148. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +1 -1
  149. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  150. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  151. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  152. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +1 -1
  153. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  154. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +1 -1
  155. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  156. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +1 -1
  157. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  158. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  159. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  160. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  161. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  162. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
  163. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  164. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  165. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  166. package/esm/domain/tracing/tracer.js +1 -1
  167. package/esm/domain/tracing/tracer.js.map +1 -1
  168. package/package.json +7 -7
  169. package/src/boot/disabledRumPublicApi.js +5 -0
  170. package/src/boot/initCallbacks.js +16 -0
  171. package/src/boot/perStartRum.js +102 -59
  172. package/src/boot/recorderApi.js +51 -2
  173. package/src/boot/rum.js +12 -18
  174. package/src/boot/rumPublicApi.js +6 -8
  175. package/src/boot/startRecording.js +2 -0
  176. package/src/domain/configuration.js +13 -2
  177. package/src/domain/contexts/urlContexts.js +34 -27
  178. package/src/domain/contexts/viewContexts.js +2 -2
  179. package/src/domain/deflate/deflateWorker.js +35 -21
  180. package/src/domain/privacy.js +93 -157
  181. package/src/domain/replay/record/canvasCommandCapture.js +102 -239
  182. package/src/domain/replay/record/canvasCommandObserver.js +11 -18
  183. package/src/domain/replay/record/canvasCommandObserverStub.js +11 -0
  184. package/src/domain/replay/record/canvasCommandSerializeArgs.js +2 -2
  185. package/src/domain/replay/record/canvasContext.js +18 -0
  186. package/src/domain/replay/record/canvasObserver.js +5 -1
  187. package/src/domain/replay/record/canvasWebGLPluginHost.js +4 -1
  188. package/src/domain/replay/record/mutationObserver.js +6 -22
  189. package/src/domain/replay/record/observers.js +4 -8
  190. package/src/domain/replay/record/record.js +20 -5
  191. package/src/domain/replay/record/serializationUtils.js +10 -33
  192. package/src/domain/replay/record/serialize.js +30 -38
  193. package/src/domain/replay/segmentCollection/buildReplayPayload.js +24 -14
  194. package/src/domain/replay/segmentCollection/segmentCollection.js +97 -227
  195. package/src/domain/replayCanvasSupported.js +1 -0
  196. package/src/domain/requestCollection.js +39 -51
  197. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +8 -2
  198. package/src/domain/rumEventsCollection/resource/fetchTimingRegistry.js +138 -0
  199. package/src/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  200. package/src/domain/rumEventsCollection/resource/resourceCollection.js +103 -88
  201. package/src/domain/rumEventsCollection/resource/resourceTrackerManager.js +10 -10
  202. package/src/domain/rumEventsCollection/resource/resourceUtils.js +41 -69
  203. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +8 -2
  204. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  205. package/src/domain/rumEventsCollection/view/trackViews.js +3 -0
  206. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -3
  207. package/src/domain/tracing/skywalkingTracer.js +14 -91
  208. package/src/domain/tracing/tracer.js +28 -4
  209. package/types/index.d.ts +9 -0
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ONE_SECOND,
3
+ SDKMap,
3
4
  LifeCycleEventType,
4
5
  isPageExitReason,
5
6
  PageExitReason,
@@ -23,11 +24,6 @@ export var SEGMENT_DURATION_LIMIT = 5 * ONE_SECOND
23
24
  * ensure that we leave room for logs, rum and potential other users
24
25
  */
25
26
  export var SEGMENT_BYTES_LIMIT = 60000
26
- // buildReplayPayload() exposes the compressed segment size, but sendBeacon
27
- // accounts for the multipart boundaries, headers, and metadata fields too.
28
- // Reserve a conservative envelope per segment so several small unload
29
- // segments cannot collectively overrun the browser's exit delivery queue.
30
- var SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD = 2 * 1024
31
27
  var SEGMENT_PENDING_RAW_BYTES_LIMIT = 4 * 1024 * 1024
32
28
  var LOCKED_SEGMENTS_LIMIT = 12
33
29
  var REPLAY_MEMORY_BUDGET_BYTES = 48 * 1024 * 1024
@@ -114,7 +110,7 @@ export function doStartSegmentCollection(
114
110
  : SEGMENT_PENDING_RAW_BYTES_LIMIT
115
111
  var lockedSegments = []
116
112
  var memoryBudget = options.memoryBudget
117
- var lockedBufferGeneration = 0
113
+ var firstLockedSequence = 0
118
114
  var reportedDropReasons = {}
119
115
  var lastCanvasFlushAt = -Infinity
120
116
  var canvasFlushTimeoutId
@@ -126,13 +122,10 @@ export function doStartSegmentCollection(
126
122
  var nextBaselineGeneration = 0
127
123
  var baselineGenerationStates = {}
128
124
  var transportGenerationStates = {}
129
- var baselineGenerationInFlightCounts = {}
130
- var pendingSegmentResultsByGeneration = {}
131
125
  var consecutiveFullSnapshotFailures = 0
132
126
  var replayRecoveryExhausted = false
133
127
  var lifecycleSubscriptionsStopped = false
134
- var nextSegmentFlushSequence = 0
135
- var inFlightSegmentFlushes = new Set()
128
+ var nextSegmentSequence = 0
136
129
  var lastAddRecordWasBackpressured = false
137
130
  var backpressuredSerializedRecordData = new WeakMap()
138
131
  var unloadingTransportLatched = false
@@ -191,7 +184,7 @@ export function doStartSegmentCollection(
191
184
  state.$rLocked &&
192
185
  pageExitEvent.reason === PageExitReason.UNLOADING
193
186
  ) {
194
- lockedBufferGeneration += 1
187
+ firstLockedSequence = nextSegmentSequence + 1
195
188
  lockedSegments = []
196
189
  }
197
190
  flushSegment(pageExitEvent.reason)
@@ -293,12 +286,10 @@ export function doStartSegmentCollection(
293
286
  replayRecoveryExhausted = true
294
287
  clearReplayResetNeeded()
295
288
  clearCanvasFlushTimeout()
296
- lockedBufferGeneration += 1
289
+ firstLockedSequence = nextSegmentSequence + 1
297
290
  lockedSegments = []
298
291
  baselineGenerationStates = {}
299
292
  transportGenerationStates = {}
300
- baselineGenerationInFlightCounts = {}
301
- pendingSegmentResultsByGeneration = {}
302
293
  if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
303
294
  // A dependent segment can already exist when the asynchronous failure
304
295
  // of the third replacement baseline arrives. Finalize-discard its
@@ -324,7 +315,6 @@ export function doStartSegmentCollection(
324
315
  ) {
325
316
  if (baselineGeneration > 0) {
326
317
  baselineGenerationStates[baselineGeneration] = 'invalid'
327
- delete pendingSegmentResultsByGeneration[baselineGeneration]
328
318
  }
329
319
  if (baselineGeneration !== activeBaselineGeneration) {
330
320
  tryCleanupBaselineGeneration(baselineGeneration)
@@ -344,34 +334,12 @@ export function doStartSegmentCollection(
344
334
  markReplayResetNeeded(reason, true)
345
335
  }
346
336
 
347
- function retainBaselineGeneration(baselineGeneration) {
348
- if (baselineGeneration <= 0) {
349
- return
350
- }
351
- baselineGenerationInFlightCounts[baselineGeneration] =
352
- (baselineGenerationInFlightCounts[baselineGeneration] || 0) + 1
353
- }
354
-
355
- function releaseBaselineGeneration(baselineGeneration) {
356
- if (
357
- baselineGeneration <= 0 ||
358
- !baselineGenerationInFlightCounts[baselineGeneration]
359
- ) {
360
- return
361
- }
362
- baselineGenerationInFlightCounts[baselineGeneration] -= 1
363
- if (!baselineGenerationInFlightCounts[baselineGeneration]) {
364
- delete baselineGenerationInFlightCounts[baselineGeneration]
365
- }
366
- tryCleanupBaselineGeneration(baselineGeneration)
367
- }
368
-
369
337
  function tryCleanupBaselineGeneration(baselineGeneration) {
370
338
  if (
371
339
  baselineGeneration <= 0 ||
372
340
  baselineGeneration === activeBaselineGeneration ||
373
- baselineGenerationInFlightCounts[baselineGeneration] ||
374
- pendingSegmentResultsByGeneration[baselineGeneration]
341
+ (transportGenerationStates[baselineGeneration] &&
342
+ transportGenerationStates[baselineGeneration].$rPendingFlushes.size)
375
343
  ) {
376
344
  return
377
345
  }
@@ -381,7 +349,10 @@ export function doStartSegmentCollection(
381
349
 
382
350
  function getTransportGenerationState(baselineGeneration) {
383
351
  if (!transportGenerationStates[baselineGeneration]) {
384
- transportGenerationStates[baselineGeneration] = { $rValid: true }
352
+ transportGenerationStates[baselineGeneration] = {
353
+ $rFirstDroppedSequence: Infinity,
354
+ $rPendingFlushes: new SDKMap()
355
+ }
385
356
  }
386
357
  return transportGenerationStates[baselineGeneration]
387
358
  }
@@ -408,21 +379,9 @@ export function doStartSegmentCollection(
408
379
  }
409
380
  drainRetryPayloadsForUnload()
410
381
  }
411
- inFlightSegmentFlushes.forEach(function (transport) {
412
- transport.$rExit = exitState
413
- })
414
- // A dependent segment can finish encoding before its Full Snapshot and is
415
- // then removed from inFlightSegmentFlushes while waiting for the baseline
416
- // generation to be confirmed. Preserve the page-exit transport intent on
417
- // those completed results as well. UNLOADING still uses the shared latch
418
- // and aggregate delivery budget in sendSegment().
419
- Object.keys(pendingSegmentResultsByGeneration).forEach(function (
420
- baselineGeneration
421
- ) {
422
- pendingSegmentResultsByGeneration[baselineGeneration].forEach(function (
423
- segmentResult
424
- ) {
425
- segmentResult.$rExit = exitState
382
+ Object.keys(transportGenerationStates).forEach(function (generation) {
383
+ transportGenerationStates[generation].$rPendingFlushes.forEach(function (transport) {
384
+ transport.$rExit = exitState
426
385
  })
427
386
  })
428
387
  }
@@ -440,32 +399,30 @@ export function doStartSegmentCollection(
440
399
  return
441
400
  }
442
401
  unloadingRetryPayloadsDrained = true
443
- if (typeof httpRequest.$rDrainOnExit !== 'function') {
444
- return
445
- }
402
+ flushOnUnload()
403
+ }
446
404
 
447
- var deliveryResult = httpRequest.$rDrainOnExit(
448
- unloadingDeliveryBytesRemaining
449
- )
450
- if (
451
- deliveryResult &&
452
- typeof deliveryResult.$rBytesCount === 'number' &&
453
- isFinite(deliveryResult.$rBytesCount) &&
454
- deliveryResult.$rBytesCount >= 0
455
- ) {
456
- unloadingDeliveryBytesRemaining = Math.max(
457
- unloadingDeliveryBytesRemaining - deliveryResult.$rBytesCount,
458
- 0
459
- )
460
- if (
461
- deliveryResult.$rAllPayloadsSent === false &&
462
- !deliveryResult.$rPending
463
- ) {
464
- // Replay segments are ordered. If an older queued payload does not fit,
465
- // no current tail may overtake it.
466
- unloadingDeliveryBudgetExhausted = true
405
+ function flushOnUnload(payload, estimatedBytes) {
406
+ var usedBytes
407
+ if (httpRequest.$rFlushOnExit) {
408
+ usedBytes = httpRequest.$rFlushOnExit(unloadingDeliveryBytesRemaining, payload)
409
+ } else {
410
+ // Older injected transports can reject a suffix instead of retaining it.
411
+ var result
412
+ if (payload) result = httpRequest.sendOnExit(payload, unloadingDeliveryBytesRemaining)
413
+ else if (httpRequest.$rDrainOnExit) result = httpRequest.$rDrainOnExit(unloadingDeliveryBytesRemaining)
414
+ if (result && typeof result.$rBytesCount === 'number' && isFinite(result.$rBytesCount) && result.$rBytesCount >= 0) {
415
+ usedBytes = result.$rBytesCount
416
+ var refused = payload ? !result.$rCurrentPayloadSent : result.$rAllPayloadsSent === false
417
+ if (refused && !result.$rPending && !result.$rUnconfirmed) {
418
+ unloadingDeliveryBudgetExhausted = true
419
+ if (payload) reportDroppedRecord('page_exit_delivery_budget', estimatedBytes)
420
+ }
421
+ } else {
422
+ usedBytes = estimatedBytes || 0
467
423
  }
468
424
  }
425
+ unloadingDeliveryBytesRemaining = Math.max(0, unloadingDeliveryBytesRemaining - usedBytes)
469
426
  }
470
427
 
471
428
  function flushPendingSegmentEncodingsForUnload(flushReason) {
@@ -475,14 +432,10 @@ export function doStartSegmentCollection(
475
432
  )
476
433
  }
477
434
 
478
- function removeInFlightSegmentFlush(transport) {
479
- inFlightSegmentFlushes.delete(transport)
480
- }
481
-
482
435
  function handlePermanentTransportDrop(segmentResult, reason) {
483
- // Invalidate the transport chain even after the recorder itself stopped;
484
- // older queued dependents must never be promoted past the missing segment.
485
- segmentResult.$rTransportGeneration.$rValid = false
436
+ // Keep earlier segments valid even if they are still encoding or queued.
437
+ var generation = segmentResult.$rTransportGeneration
438
+ generation.$rFirstDroppedSequence = Math.min(generation.$rFirstDroppedSequence, segmentResult.$rSequence)
486
439
  if (
487
440
  state.$rStatus === SegmentCollectionStatus.Stopped ||
488
441
  replayRecoveryExhausted
@@ -491,16 +444,16 @@ export function doStartSegmentCollection(
491
444
  }
492
445
  var dropReason = 'transport_' + reason
493
446
  reportDroppedRecord(dropReason, 0)
494
- // Once a segment is permanently rejected, every later incremental in its
495
- // generation may depend on replay state the player will never receive.
496
- // Retire the generation and gate admission until a replacement Full
497
- // Snapshot establishes a new chain. A transport failure is not evidence
498
- // that Full Snapshot serialization itself is permanently broken.
499
- failBaselineGeneration(segmentResult.$rGeneration, dropReason, false)
500
- scheduleReplayResetNotification()
447
+ if (segmentResult.$rGeneration === activeBaselineGeneration) {
448
+ markReplayResetNeeded(dropReason, true)
449
+ }
501
450
  }
502
451
 
503
452
  function sendSegment(segmentResult) {
453
+ function isValid() {
454
+ return segmentResult.$rSequence < segmentResult.$rTransportGeneration.$rFirstDroppedSequence
455
+ }
456
+ if (!isValid()) return
504
457
  const metadata = segmentResult.$rMetadata
505
458
  const encoderResult = segmentResult.$rEncoder
506
459
  if (
@@ -522,35 +475,17 @@ export function doStartSegmentCollection(
522
475
  !segmentResult.$rRegular &&
523
476
  (segmentResult.$rExit === true ||
524
477
  unloadingTransportLatched)
525
- var estimatedDeliveryBytesCount =
526
- encoderResult.outputBytesCount +
527
- SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD
528
- if (shouldUseExitTransport && unloadingTransportLatched) {
529
- if (unloadingDeliveryBudgetExhausted) {
530
- unloadingDeliveryBudgetExhausted = true
531
- reportDroppedRecord(
532
- 'page_exit_delivery_budget',
533
- estimatedDeliveryBytesCount
534
- )
535
- return
536
- }
478
+ var payload = buildReplayPayload(encoderResult.output, metadata, encoderResult.rawBytesCount)
479
+ var estimatedDeliveryBytesCount = payload.$rExitBytesCount
480
+ if (shouldUseExitTransport && unloadingTransportLatched && unloadingDeliveryBudgetExhausted) {
481
+ reportDroppedRecord('page_exit_delivery_budget', estimatedDeliveryBytesCount)
482
+ return
537
483
  }
538
484
 
539
- var payload = buildReplayPayload(
540
- encoderResult.output,
541
- metadata,
542
- encoderResult.rawBytesCount
543
- )
544
- payload.$rExitBytesCount = estimatedDeliveryBytesCount
545
485
  payload.$rEnforceOrder = true
546
- payload.$rKeepalive = Boolean(
547
- !shouldUseExitTransport &&
548
- segmentResult.$rExit === PageExitReason.HIDDEN &&
549
- estimatedDeliveryBytesCount <= SEGMENT_BYTES_LIMIT
550
- )
551
- payload.$rIsValid = function () {
552
- return segmentResult.$rTransportGeneration.$rValid
553
- }
486
+ payload.$rPageHidden = !shouldUseExitTransport && segmentResult.$rExit === PageExitReason.HIDDEN
487
+ payload.$rKeepalive = payload.$rPageHidden && estimatedDeliveryBytesCount <= SEGMENT_BYTES_LIMIT
488
+ payload.$rIsValid = isValid
554
489
  payload.$rOnPermanentDrop = function (reason) {
555
490
  handlePermanentTransportDrop(segmentResult, reason)
556
491
  }
@@ -559,44 +494,10 @@ export function doStartSegmentCollection(
559
494
  // generation metadata.
560
495
  segmentResult.$rEncoder = undefined
561
496
 
562
- if (shouldUseExitTransport) {
563
- var exitDeliveryResult = httpRequest.sendOnExit(
564
- payload,
565
- unloadingTransportLatched
566
- ? unloadingDeliveryBytesRemaining
567
- : undefined
568
- )
569
- if (unloadingTransportLatched) {
570
- if (
571
- exitDeliveryResult &&
572
- typeof exitDeliveryResult.$rBytesCount === 'number' &&
573
- isFinite(exitDeliveryResult.$rBytesCount) &&
574
- exitDeliveryResult.$rBytesCount >= 0
575
- ) {
576
- unloadingDeliveryBytesRemaining = Math.max(
577
- unloadingDeliveryBytesRemaining -
578
- exitDeliveryResult.$rBytesCount,
579
- 0
580
- )
581
- if (
582
- !exitDeliveryResult.$rCurrentPayloadSent &&
583
- !exitDeliveryResult.$rPending
584
- ) {
585
- unloadingDeliveryBudgetExhausted = true
586
- reportDroppedRecord(
587
- 'page_exit_delivery_budget',
588
- estimatedDeliveryBytesCount
589
- )
590
- }
591
- } else {
592
- // Preserve compatibility with injected transports that predate the
593
- // aggregate-budget result contract.
594
- unloadingDeliveryBytesRemaining = Math.max(
595
- unloadingDeliveryBytesRemaining - estimatedDeliveryBytesCount,
596
- 0
597
- )
598
- }
599
- }
497
+ if (shouldUseExitTransport && unloadingTransportLatched) {
498
+ flushOnUnload(payload, estimatedDeliveryBytesCount)
499
+ } else if (shouldUseExitTransport) {
500
+ httpRequest.sendOnExit(payload)
600
501
  } else {
601
502
  httpRequest.send(payload)
602
503
  }
@@ -611,19 +512,11 @@ export function doStartSegmentCollection(
611
512
  // A valid replacement snapshot clears the reset before delivery.
612
513
  return
613
514
  }
614
- lockedSegments.push(segmentResult)
615
-
616
- var latestFullSnapshotIndex = -1
617
- for (var index = lockedSegments.length - 1; index >= 0; index -= 1) {
618
- if (lockedSegments[index].$rMetadata.has_full_snapshot) {
619
- latestFullSnapshotIndex = index
620
- break
621
- }
622
- }
623
-
624
- if (latestFullSnapshotIndex > 0) {
625
- lockedSegments.splice(0, latestFullSnapshotIndex)
515
+ if (segmentResult.$rMetadata.has_full_snapshot) {
516
+ firstLockedSequence = segmentResult.$rSequence
517
+ lockedSegments = []
626
518
  }
519
+ lockedSegments.push(segmentResult)
627
520
 
628
521
  if (
629
522
  lockedSegments.length > LOCKED_SEGMENTS_LIMIT ||
@@ -635,7 +528,7 @@ export function doStartSegmentCollection(
635
528
  // deleting a middle segment can leave later records referencing nodes the
636
529
  // player never received. Retire the whole lock generation and admit no
637
530
  // more incrementals until a replacement full snapshot starts a new chain.
638
- lockedBufferGeneration += 1
531
+ firstLockedSequence = nextSegmentSequence + 1
639
532
  lockedSegments = []
640
533
  markReplayResetNeeded('locked_buffer_capacity')
641
534
  // Records already admitted to the current segment still belong to the
@@ -694,7 +587,7 @@ export function doStartSegmentCollection(
694
587
  return
695
588
  }
696
589
  if (
697
- segmentResult.$rLockGeneration !== lockedBufferGeneration ||
590
+ segmentResult.$rSequence < firstLockedSequence ||
698
591
  segmentResult.$rReason === 'buffer_checkout' ||
699
592
  segmentResult.$rReason === 'stop' ||
700
593
  segmentResult.$rReason === PageExitReason.UNLOADING
@@ -710,13 +603,6 @@ export function doStartSegmentCollection(
710
603
  }
711
604
  }
712
605
 
713
- function retainPendingSegmentResult(baselineGeneration, segmentResult) {
714
- if (!pendingSegmentResultsByGeneration[baselineGeneration]) {
715
- pendingSegmentResultsByGeneration[baselineGeneration] = []
716
- }
717
- pendingSegmentResultsByGeneration[baselineGeneration].push(segmentResult)
718
- }
719
-
720
606
  function confirmBaselineGeneration(baselineGeneration, segmentResult) {
721
607
  if (
722
608
  replayRecoveryExhausted ||
@@ -729,21 +615,13 @@ export function doStartSegmentCollection(
729
615
  baselineGeneration === activeBaselineGeneration &&
730
616
  (!replayResetNeeded ||
731
617
  !segmentResult.$rLocked ||
732
- segmentResult.$rLockGeneration === lockedBufferGeneration)
618
+ segmentResult.$rSequence >= firstLockedSequence)
733
619
  ) {
734
620
  consecutiveFullSnapshotFailures = 0
735
621
  clearReplayResetNeeded()
736
622
  }
737
623
 
738
624
  deliverSegmentResult(segmentResult)
739
- var pendingSegmentResults =
740
- pendingSegmentResultsByGeneration[baselineGeneration] || []
741
- delete pendingSegmentResultsByGeneration[baselineGeneration]
742
- pendingSegmentResults.sort(function (first, second) {
743
- return first.$rSequence - second.$rSequence
744
- })
745
- pendingSegmentResults.forEach(deliverSegmentResult)
746
- tryCleanupBaselineGeneration(baselineGeneration)
747
625
  }
748
626
 
749
627
  function handleSuccessfulSegment(baselineGeneration, segmentResult) {
@@ -759,9 +637,8 @@ export function doStartSegmentCollection(
759
637
  var baselineState = baselineGenerationStates[baselineGeneration]
760
638
  if (baselineState === 'confirmed') {
761
639
  deliverSegmentResult(segmentResult)
762
- } else if (baselineState === 'pending') {
763
- retainPendingSegmentResult(baselineGeneration, segmentResult)
764
640
  } else if (
641
+ baselineState !== 'invalid' &&
765
642
  baselineGeneration === activeBaselineGeneration &&
766
643
  !replayRecoveryExhausted
767
644
  ) {
@@ -792,7 +669,6 @@ export function doStartSegmentCollection(
792
669
  function handleFlushedSegment(
793
670
  flushReason,
794
671
  wasLocked,
795
- lockedGeneration,
796
672
  baselineGeneration,
797
673
  metadata,
798
674
  encoderResult,
@@ -802,14 +678,16 @@ export function doStartSegmentCollection(
802
678
  if (replayRecoveryExhausted) {
803
679
  return
804
680
  }
681
+ const generation = getTransportGenerationState(baselineGeneration)
682
+ if (transport.$rSequence >= generation.$rFirstDroppedSequence) return
805
683
  if (encoderResult.error) {
684
+ generation.$rFirstDroppedSequence = transport.$rSequence
806
685
  reportDroppedRecord('encoder_error', 0)
807
- failBaselineGeneration(
808
- baselineGeneration,
809
- 'encoder_error',
810
- metadata.has_full_snapshot
811
- )
812
- scheduleReplayResetNotification()
686
+ if (metadata.has_full_snapshot) {
687
+ failBaselineGeneration(baselineGeneration, 'encoder_error', true)
688
+ } else if (baselineGeneration === activeBaselineGeneration) {
689
+ markReplayResetNeeded('encoder_error', true)
690
+ }
813
691
  return
814
692
  }
815
693
  // SEGMENT_BYTES_LIMIT is a rolling target and a beacon budget, not a hard
@@ -824,18 +702,14 @@ export function doStartSegmentCollection(
824
702
  $rReason: flushReason,
825
703
  $rExit: transport.$rExit,
826
704
  $rLocked: wasLocked,
827
- $rLockGeneration: lockedGeneration,
828
705
  $rGeneration: baselineGeneration,
829
- $rTransportGeneration: getTransportGenerationState(
830
- baselineGeneration
831
- ),
706
+ $rTransportGeneration: generation,
832
707
  $rSequence: transport.$rSequence
833
708
  }
834
709
  if (__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
835
710
  segmentResult.$rCounts = recordCountsByType
836
711
  }
837
712
  handleSuccessfulSegment(baselineGeneration, segmentResult)
838
- scheduleReplayResetNotification()
839
713
  }
840
714
 
841
715
  function flushSegment(flushReason, callback, isStopping) {
@@ -868,42 +742,38 @@ export function doStartSegmentCollection(
868
742
  if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
869
743
  const segmentState = state
870
744
  const wasLocked = segmentState.$rLocked
871
- const lockedGeneration = segmentState.$rLockGeneration
872
745
  const baselineGeneration = state.$rGeneration
873
746
  const transport = {
874
747
  $rExit:
875
748
  flushReason === PageExitReason.HIDDEN
876
749
  ? PageExitReason.HIDDEN
877
750
  : isPageExitReason(flushReason),
878
- $rSequence: ++nextSegmentFlushSequence
751
+ $rSequence: segmentState.$rSequence
879
752
  }
880
753
  clearTimeout(state.$rExpiration)
881
754
  resetState(isStopping ? 'stop' : flushReason)
882
755
  if (!segmentState.$rSegment.isEmpty()) {
883
- inFlightSegmentFlushes.add(transport)
884
- retainBaselineGeneration(baselineGeneration)
885
- segmentState.$rSegment.flush(function (
886
- metadata,
887
- encoderResult,
888
- recordCountsByType
889
- ) {
890
- removeInFlightSegmentFlush(transport)
756
+ const pending = getTransportGenerationState(baselineGeneration).$rPendingFlushes
757
+ pending.set(transport.$rSequence, transport)
758
+ segmentState.$rSegment.flush(function (metadata, encoderResult, recordCountsByType) {
759
+ transport.$rFinish = function () {
760
+ handleFlushedSegment(flushReason, wasLocked, baselineGeneration,
761
+ metadata, encoderResult, recordCountsByType, transport)
762
+ // Even a discarded suffix can release the last pending raw bytes.
763
+ scheduleReplayResetNotification()
764
+ if (callback) callback()
765
+ }
766
+ // A dependent encoding may finish first. Release completed entries
767
+ // in capture order; independent snapshots have their own generation.
768
+ const entries = pending.values()
769
+ let head
891
770
  try {
892
- handleFlushedSegment(
893
- flushReason,
894
- wasLocked,
895
- lockedGeneration,
896
- baselineGeneration,
897
- metadata,
898
- encoderResult,
899
- recordCountsByType,
900
- transport
901
- )
771
+ while ((head = entries.next().value) && head.$rFinish) {
772
+ pending.delete(head.$rSequence)
773
+ head.$rFinish()
774
+ }
902
775
  } finally {
903
- releaseBaselineGeneration(baselineGeneration)
904
- }
905
- if (callback) {
906
- callback()
776
+ tryCleanupBaselineGeneration(baselineGeneration)
907
777
  }
908
778
  })
909
779
  return
@@ -932,7 +802,7 @@ export function doStartSegmentCollection(
932
802
  creationReason: state.$rNextReason
933
803
  }),
934
804
  $rLocked: state.$rLocked,
935
- $rLockGeneration: lockedBufferGeneration,
805
+ $rSequence: ++nextSegmentSequence,
936
806
  $rGeneration: activeBaselineGeneration,
937
807
  $rHasSnapshot: false,
938
808
  $rMandatoryRecoveryHold: mandatoryRecoveryPending,
@@ -1435,7 +1305,7 @@ export function doStartSegmentCollection(
1435
1305
  return false
1436
1306
  }
1437
1307
  bufferCheckoutPending = true
1438
- lockedBufferGeneration += 1
1308
+ firstLockedSequence = nextSegmentSequence + 1
1439
1309
  lockedSegments = []
1440
1310
  var callbackWasInvoked = false
1441
1311
  flushSegment('buffer_checkout', function () {
@@ -1474,7 +1344,7 @@ export function doStartSegmentCollection(
1474
1344
  }
1475
1345
  },
1476
1346
  stop: function (flushReason) {
1477
- lockedBufferGeneration += 1
1347
+ firstLockedSequence = nextSegmentSequence + 1
1478
1348
  lockedSegments = []
1479
1349
  bufferCheckoutPending = false
1480
1350
  clearCanvasFlushTimeout()
@@ -0,0 +1 @@
1
+ export const replayCanvasSupported = true