@cloudcare/browser-rum 3.3.12 → 3.3.14

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 (83) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +22 -2
  4. package/cjs/boot/recorderApi.js.map +1 -1
  5. package/cjs/boot/startRecording.js +54 -1
  6. package/cjs/boot/startRecording.js.map +1 -1
  7. package/cjs/domain/assembly.js +15 -2
  8. package/cjs/domain/assembly.js.map +1 -1
  9. package/cjs/domain/configuration.js +1 -0
  10. package/cjs/domain/configuration.js.map +1 -1
  11. package/cjs/domain/deflate/deflateWorker.js +1 -1
  12. package/cjs/domain/privacy.js +278 -0
  13. package/cjs/domain/privacy.js.map +1 -0
  14. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  15. package/cjs/domain/replay/record/mutationObserver.js +16 -6
  16. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  17. package/cjs/domain/replay/record/privacy.js +11 -272
  18. package/cjs/domain/replay/record/privacy.js.map +1 -1
  19. package/cjs/domain/replay/record/record.js +94 -8
  20. package/cjs/domain/replay/record/record.js.map +1 -1
  21. package/cjs/domain/replay/segmentCollection/segmentCollection.js +45 -17
  22. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  23. package/cjs/domain/replay/timeAnchor.js +27 -0
  24. package/cjs/domain/replay/timeAnchor.js.map +1 -0
  25. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +81 -19
  26. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  28. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  29. package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -7
  30. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  31. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
  32. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  33. package/cjs/domain/rumSessionManager.js +2 -2
  34. package/cjs/domain/rumSessionManager.js.map +1 -1
  35. package/esm/boot/buildEnv.js +1 -1
  36. package/esm/boot/recorderApi.js +23 -3
  37. package/esm/boot/recorderApi.js.map +1 -1
  38. package/esm/boot/startRecording.js +54 -1
  39. package/esm/boot/startRecording.js.map +1 -1
  40. package/esm/domain/assembly.js +16 -3
  41. package/esm/domain/assembly.js.map +1 -1
  42. package/esm/domain/configuration.js +1 -0
  43. package/esm/domain/configuration.js.map +1 -1
  44. package/esm/domain/deflate/deflateWorker.js +1 -1
  45. package/esm/domain/privacy.js +266 -0
  46. package/esm/domain/privacy.js.map +1 -0
  47. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  48. package/esm/domain/replay/record/mutationObserver.js +16 -6
  49. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  50. package/esm/domain/replay/record/privacy.js +1 -266
  51. package/esm/domain/replay/record/privacy.js.map +1 -1
  52. package/esm/domain/replay/record/record.js +78 -9
  53. package/esm/domain/replay/record/record.js.map +1 -1
  54. package/esm/domain/replay/segmentCollection/segmentCollection.js +45 -17
  55. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  56. package/esm/domain/replay/timeAnchor.js +20 -0
  57. package/esm/domain/replay/timeAnchor.js.map +1 -0
  58. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +80 -18
  59. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  60. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  61. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  62. package/esm/domain/rumEventsCollection/view/trackViews.js +46 -8
  63. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  64. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
  65. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  66. package/esm/domain/rumSessionManager.js +2 -2
  67. package/esm/domain/rumSessionManager.js.map +1 -1
  68. package/package.json +4 -4
  69. package/src/boot/recorderApi.js +25 -3
  70. package/src/boot/startRecording.js +61 -1
  71. package/src/domain/assembly.js +18 -4
  72. package/src/domain/configuration.js +4 -0
  73. package/src/domain/privacy.js +356 -0
  74. package/src/domain/replay/record/mutationObserver.js +21 -11
  75. package/src/domain/replay/record/privacy.js +1 -356
  76. package/src/domain/replay/record/record.js +129 -8
  77. package/src/domain/replay/segmentCollection/segmentCollection.js +83 -18
  78. package/src/domain/replay/timeAnchor.js +33 -0
  79. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +148 -21
  80. package/src/domain/rumEventsCollection/actions/trackClickActions.js +19 -5
  81. package/src/domain/rumEventsCollection/view/trackViews.js +83 -12
  82. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
  83. package/src/domain/rumSessionManager.js +2 -2
@@ -1,356 +1 @@
1
- import {
2
- isElementNode,
3
- getParentNode,
4
- isTextNode
5
- } from '@cloudcare/browser-core'
6
-
7
- import {
8
- NodePrivacyLevel,
9
- PRIVACY_ATTR_NAME,
10
- PRIVACY_ATTR_VALUE_ALLOW,
11
- PRIVACY_ATTR_VALUE_MASK,
12
- PRIVACY_ATTR_VALUE_MASK_USER_INPUT,
13
- PRIVACY_ATTR_VALUE_HIDDEN,
14
- PRIVACY_CLASS_ALLOW,
15
- PRIVACY_CLASS_MASK,
16
- PRIVACY_CLASS_MASK_USER_INPUT,
17
- PRIVACY_CLASS_HIDDEN,
18
- FORM_PRIVATE_TAG_NAMES,
19
- CENSORED_STRING_MARK
20
- } from '../../../constants'
21
-
22
- export var MAX_ATTRIBUTE_VALUE_CHAR_LENGTH = 100_000
23
-
24
- var TEXT_MASKING_CHAR = 'x'
25
- export var MAX_PRIVACY_ANCESTOR_DEPTH = 1000
26
-
27
- /**
28
- * Get node privacy level by iterating over its ancestors. When the direct parent privacy level is
29
- * know, it is best to use something like:
30
- *
31
- * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
32
- */
33
- export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
34
- if (cache && cache.has(node)) {
35
- return cache.get(node)
36
- }
37
-
38
- // Resolve ancestors iteratively so an adversarially deep DOM cannot grow the
39
- // JavaScript stack. If the watermark is crossed, fail closed: hiding the
40
- // branch is safer than spending unbounded time resolving its privacy chain.
41
- var unresolvedNodes = []
42
- var currentNode = node
43
- var inheritedPrivacyLevel
44
- while (currentNode) {
45
- if (cache && cache.has(currentNode)) {
46
- inheritedPrivacyLevel = cache.get(currentNode)
47
- break
48
- }
49
- if (unresolvedNodes.length >= MAX_PRIVACY_ANCESTOR_DEPTH) {
50
- inheritedPrivacyLevel = NodePrivacyLevel.HIDDEN
51
- break
52
- }
53
- unresolvedNodes.push(currentNode)
54
- currentNode = getParentNode(currentNode)
55
- }
56
- if (inheritedPrivacyLevel === undefined) {
57
- inheritedPrivacyLevel = defaultPrivacyLevel
58
- }
59
-
60
- while (unresolvedNodes.length) {
61
- var unresolvedNode = unresolvedNodes.pop()
62
- inheritedPrivacyLevel = reducePrivacyLevel(
63
- getNodeSelfPrivacyLevel(unresolvedNode),
64
- inheritedPrivacyLevel
65
- )
66
- if (cache) {
67
- cache.set(unresolvedNode, inheritedPrivacyLevel)
68
- }
69
- }
70
- return inheritedPrivacyLevel
71
- }
72
-
73
- /**
74
- * Reduces the next privacy level based on self + parent privacy levels
75
- */
76
- export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
77
- switch (parentNodePrivacyLevel) {
78
- // These values cannot be overridden
79
- case NodePrivacyLevel.HIDDEN:
80
- case NodePrivacyLevel.IGNORE:
81
- return parentNodePrivacyLevel
82
- }
83
- switch (childPrivacyLevel) {
84
- case NodePrivacyLevel.ALLOW:
85
- case NodePrivacyLevel.MASK:
86
- case NodePrivacyLevel.MASK_USER_INPUT:
87
- case NodePrivacyLevel.HIDDEN:
88
- case NodePrivacyLevel.IGNORE:
89
- return childPrivacyLevel
90
- default:
91
- return parentNodePrivacyLevel
92
- }
93
- }
94
-
95
- /**
96
- * Determines the node's own privacy level without checking for ancestors.
97
- */
98
- export function getNodeSelfPrivacyLevel(node) {
99
- // Only Element types can have a privacy level set
100
- if (!isElementNode(node)) {
101
- return
102
- }
103
-
104
- var privAttr = node.getAttribute(PRIVACY_ATTR_NAME)
105
-
106
- // Overrules for replay purpose
107
- if (node.tagName === 'BASE') {
108
- return NodePrivacyLevel.ALLOW
109
- }
110
-
111
- // Overrules to enforce end-user protection
112
- if (node.tagName === 'INPUT') {
113
- var inputElement = node
114
- if (
115
- inputElement.type === 'password' ||
116
- inputElement.type === 'email' ||
117
- inputElement.type === 'tel'
118
- ) {
119
- return NodePrivacyLevel.MASK
120
- }
121
- if (inputElement.type === 'hidden') {
122
- return NodePrivacyLevel.MASK
123
- }
124
- var autocomplete = inputElement.getAttribute('autocomplete')
125
- // Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
126
- if (autocomplete && autocomplete.indexOf('cc-') === 0) {
127
- return NodePrivacyLevel.MASK
128
- }
129
- }
130
-
131
- // Check HTML privacy attributes and classes
132
- if (
133
- privAttr === PRIVACY_ATTR_VALUE_HIDDEN ||
134
- node.classList.contains(PRIVACY_CLASS_HIDDEN)
135
- ) {
136
- return NodePrivacyLevel.HIDDEN
137
- }
138
-
139
- if (
140
- privAttr === PRIVACY_ATTR_VALUE_MASK ||
141
- node.classList.contains(PRIVACY_CLASS_MASK)
142
- ) {
143
- return NodePrivacyLevel.MASK
144
- }
145
-
146
- if (
147
- privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT ||
148
- node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)
149
- ) {
150
- return NodePrivacyLevel.MASK_USER_INPUT
151
- }
152
-
153
- if (
154
- privAttr === PRIVACY_ATTR_VALUE_ALLOW ||
155
- node.classList.contains(PRIVACY_CLASS_ALLOW)
156
- ) {
157
- return NodePrivacyLevel.ALLOW
158
- }
159
-
160
- if (shouldIgnoreElement(node)) {
161
- return NodePrivacyLevel.IGNORE
162
- }
163
- }
164
-
165
- /**
166
- * Helper aiming to unify `mask` and `mask-user-input` privacy levels:
167
- *
168
- * In the `mask` case, it is trivial: we should mask the element.
169
- *
170
- * In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
171
- * direct parent is a form element for text nodes).
172
- *
173
- * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
174
- * node if it is ignored or hidden? it doesn't matter since it won't be serialized).
175
- */
176
- export function shouldMaskNode(configuration, node, privacyLevel) {
177
- if (
178
- configuration.shouldMaskNode &&
179
- configuration.shouldMaskNode(node, privacyLevel) === true
180
- )
181
- return true
182
- switch (privacyLevel) {
183
- case NodePrivacyLevel.MASK:
184
- case NodePrivacyLevel.HIDDEN:
185
- case NodePrivacyLevel.IGNORE:
186
- return true
187
- case NodePrivacyLevel.MASK_USER_INPUT:
188
- return isTextNode(node)
189
- ? isFormElement(node.parentNode)
190
- : isFormElement(node)
191
- default:
192
- return false
193
- }
194
- }
195
-
196
- function isFormElement(node) {
197
- if (!node || node.nodeType !== node.ELEMENT_NODE) {
198
- return false
199
- }
200
- var element = node
201
- if (element.tagName === 'INPUT') {
202
- switch (element.type) {
203
- case 'button':
204
- case 'color':
205
- case 'reset':
206
- case 'submit':
207
- return false
208
- }
209
- }
210
- return !!FORM_PRIVATE_TAG_NAMES[element.tagName]
211
- }
212
-
213
- /**
214
- * Text censoring non-destructively maintains whitespace characters in order to preserve text shape
215
- * during replay.
216
- */
217
- export var censorText = function (text) {
218
- return text.replace(/\S/g, TEXT_MASKING_CHAR)
219
- }
220
-
221
- export function getTextContent(
222
- configuration,
223
- textNode,
224
- ignoreWhiteSpace,
225
- parentNodePrivacyLevel
226
- ) {
227
- // The parent node may not be a html element which has a tagName attribute.
228
- // So just let it be undefined which is ok in this use case.
229
- var parentTagName = textNode.parentElement && textNode.parentElement.tagName
230
- var textContent = textNode.textContent || ''
231
-
232
- if (ignoreWhiteSpace && !textContent.trim()) {
233
- return
234
- }
235
-
236
- var nodePrivacyLevel = parentNodePrivacyLevel
237
-
238
- // var isStyle = parentTagName === 'STYLE' ? true : undefined
239
- var isScript = parentTagName === 'SCRIPT'
240
-
241
- if (isScript) {
242
- // For perf reasons, we don't record script (heuristic)
243
- textContent = CENSORED_STRING_MARK
244
- } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
245
- // Should never occur, but just in case, we set to CENSORED_MARK.
246
- textContent = CENSORED_STRING_MARK
247
- } else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
248
- if (
249
- // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
250
- parentTagName === 'DATALIST' ||
251
- parentTagName === 'SELECT' ||
252
- parentTagName === 'OPTGROUP'
253
- ) {
254
- if (!textContent.trim()) {
255
- return
256
- }
257
- } else if (parentTagName === 'OPTION') {
258
- // <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
259
- textContent = CENSORED_STRING_MARK
260
- } else {
261
- textContent = censorText(textContent)
262
- }
263
- }
264
- // else if (isStyle && textContent) {
265
- // try {
266
- // // try to read style sheet
267
- // if (textNode.nextSibling || textNode.previousSibling) {
268
- // // This is not the only child of the stylesheet.
269
- // // We can't read all of the sheet's .cssRules and expect them
270
- // // to _only_ include the current rule(s) added by the text node.
271
- // // So we'll be conservative and keep textContent as-is.
272
- // } else if (
273
- // textNode.parentNode &&
274
- // textNode.parentNode.sheet &&
275
- // textNode.parentNode.sheet.cssRules
276
- // ) {
277
- // textContent = getCssRulesString(textNode.parentNode.sheet)
278
- // }
279
- // } catch (err) {}
280
- // textContent = switchToAbsoluteUrl(textContent, getHref())
281
- // }
282
- return textContent
283
- }
284
-
285
- /**
286
- * We don't need this logic on the recorder side.
287
- * For security related meta's, customer can mask themmanually given they
288
- * are easy to identify in the HEAD tag.
289
- */
290
- export function shouldIgnoreElement(element) {
291
- if (element.nodeName === 'SCRIPT') {
292
- return true
293
- }
294
-
295
- if (element.nodeName === 'LINK') {
296
- var relAttribute = getLowerCaseAttribute('rel')
297
- return (
298
- // Link as script - Ignore only when rel=preload, modulepreload or prefetch
299
- (/preload|prefetch/i.test(relAttribute) &&
300
- getLowerCaseAttribute('as') === 'script') ||
301
- // Favicons
302
- relAttribute === 'shortcut icon' ||
303
- relAttribute === 'icon'
304
- )
305
- }
306
-
307
- if (element.nodeName === 'META') {
308
- var nameAttribute = getLowerCaseAttribute('name')
309
- var relAttribute = getLowerCaseAttribute('rel')
310
- var propertyAttribute = getLowerCaseAttribute('property')
311
- return (
312
- // Favicons
313
- /^msapplication-tile(image|color)$/.test(nameAttribute) ||
314
- nameAttribute === 'application-name' ||
315
- relAttribute === 'icon' ||
316
- relAttribute === 'apple-touch-icon' ||
317
- relAttribute === 'shortcut icon' ||
318
- // Description
319
- nameAttribute === 'keywords' ||
320
- nameAttribute === 'description' ||
321
- // Social
322
- /^(og|twitter|fb):/.test(propertyAttribute) ||
323
- /^(og|twitter):/.test(nameAttribute) ||
324
- nameAttribute === 'pinterest' ||
325
- // Robots
326
- nameAttribute === 'robots' ||
327
- nameAttribute === 'googlebot' ||
328
- nameAttribute === 'bingbot' ||
329
- // Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
330
- // X-Translated-By
331
- element.hasAttribute('http-equiv') ||
332
- // Authorship
333
- nameAttribute === 'author' ||
334
- nameAttribute === 'generator' ||
335
- nameAttribute === 'framework' ||
336
- nameAttribute === 'publisher' ||
337
- nameAttribute === 'progid' ||
338
- /^article:/.test(propertyAttribute) ||
339
- /^product:/.test(propertyAttribute) ||
340
- // Verification
341
- nameAttribute === 'google-site-verification' ||
342
- nameAttribute === 'yandex-verification' ||
343
- nameAttribute === 'csrf-token' ||
344
- nameAttribute === 'p:domain_verify' ||
345
- nameAttribute === 'verify-v1' ||
346
- nameAttribute === 'verification' ||
347
- nameAttribute === 'shopify-checkout-api-token'
348
- )
349
- }
350
-
351
- function getLowerCaseAttribute(name) {
352
- return (element.getAttribute(name) || '').toLowerCase()
353
- }
354
-
355
- return false
356
- }
1
+ export * from '../../privacy'
@@ -4,9 +4,22 @@ import {
4
4
  getScrollY,
5
5
  assign,
6
6
  addTelemetryDebug,
7
- getParentNode
7
+ getParentNode,
8
+ setInterval,
9
+ clearInterval
8
10
  } from '@cloudcare/browser-core'
9
11
  import { getViewportDimension } from '../../initViewportObservable'
12
+ import {
13
+ SESSION_REPLAY_TIME_ANCHOR_INTERVAL,
14
+ SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE,
15
+ SESSION_REPLAY_TIME_ANCHOR_TAG
16
+ } from '../timeAnchor'
17
+
18
+ export {
19
+ SESSION_REPLAY_TIME_ANCHOR_INTERVAL,
20
+ SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE,
21
+ SESSION_REPLAY_TIME_ANCHOR_TAG
22
+ } from '../timeAnchor'
10
23
 
11
24
  import { RecordType, IncrementalSource } from '../../../types'
12
25
  import { NodePrivacyLevel } from '../../../constants'
@@ -78,6 +91,8 @@ var FULL_SNAPSHOT_MAX_RESTART_COUNT = 3
78
91
  var FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS = 1000
79
92
  var FULL_SNAPSHOT_MAX_WALL_DURATION_MS = 30000
80
93
  var FULL_SNAPSHOT_MUTATION_QUIET_DELAY_MS = 250
94
+ var REPLAY_MEMORY_BUDGET_BYTES = 48 * 1024 * 1024
95
+ var REPLAY_MEMORY_HIGH_WATERMARK_BYTES = 32 * 1024 * 1024
81
96
  export var MAX_FULL_SNAPSHOT_CANVAS_BASELINE_COUNT = 64
82
97
  var FULL_SNAPSHOT_CANVAS_BASELINE_TOTAL_TIMEOUT_MS = 2000
83
98
  var FULL_SNAPSHOT_CANVAS_BASELINE_ITEM_TIMEOUT_MS = 1000
@@ -508,6 +523,74 @@ export function record(options) {
508
523
  var pendingFullSnapshotBaselineRecords
509
524
  var pendingFullSnapshotBaselineMutationVersion
510
525
  var fullSnapshotWasPublished = false
526
+ var replayMemoryBudget = options.$rMemoryBudget
527
+ if (replayMemoryBudget) {
528
+ replayMemoryBudget.$rRecord = function () {
529
+ return pendingMutationAdmissionApproxBytes
530
+ }
531
+ }
532
+
533
+ var lastReplayTimeAnchorTimestamp
534
+ function emitReplayTimeAnchor() {
535
+ if (
536
+ !fullSnapshotWasPublished ||
537
+ recordStopping ||
538
+ recordStopped ||
539
+ (options.$rShouldEmitTimeAnchor &&
540
+ !options.$rShouldEmitTimeAnchor())
541
+ ) {
542
+ return
543
+ }
544
+ // A time anchor carries no replay state and is safe to drop. Do not put it
545
+ // on the shared deferred queue: `true` must mean that the segment layer
546
+ // actually admitted it, especially for the final stop boundary.
547
+ if (
548
+ suppressRecordsUntilFullSnapshot ||
549
+ mutationPublicationBarrier ||
550
+ deferredRecords.length ||
551
+ deferredRecordAdmissionTimeout !== undefined ||
552
+ pendingMutationPayload ||
553
+ pendingMutationAdmissionQueue.length ||
554
+ mutationAdmissionEmitInProgress ||
555
+ mutationSourceFlushInProgress
556
+ ) {
557
+ return false
558
+ }
559
+ var timestamp = timeStampNow()
560
+ if (timestamp === lastReplayTimeAnchorTimestamp) {
561
+ return true
562
+ }
563
+ lastEmitWasLocallyBackpressured = false
564
+ var accepted = rawEmit({
565
+ type: SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE,
566
+ timestamp: timestamp,
567
+ data: {
568
+ tag: SESSION_REPLAY_TIME_ANCHOR_TAG,
569
+ payload: {}
570
+ }
571
+ })
572
+ if (accepted === false) {
573
+ return false
574
+ }
575
+ lastReplayTimeAnchorTimestamp = timestamp
576
+ return true
577
+ }
578
+ function emitPeriodicReplayTimeAnchor() {
579
+ // Keep the explicit page-exit anchor as the hidden boundary, but do not let
580
+ // the background timer extend the replay timeline while the Session is no
581
+ // longer renewed by visible-page activity.
582
+ if (document.visibilityState !== 'visible') {
583
+ return
584
+ }
585
+ emitReplayTimeAnchor()
586
+ }
587
+ var replayTimeAnchorIntervalId = setInterval(
588
+ emitPeriodicReplayTimeAnchor,
589
+ SESSION_REPLAY_TIME_ANCHOR_INTERVAL
590
+ )
591
+ registerInitializationCleanup(function () {
592
+ clearInterval(replayTimeAnchorIntervalId)
593
+ })
511
594
  var domMutationVersion = 0
512
595
  var mutationActivityTargets = new Set()
513
596
  var mutationActivityFlushScheduled = false
@@ -650,9 +733,14 @@ export function record(options) {
650
733
  ) {
651
734
  return true
652
735
  }
653
- if (!pendingPublicationToken.$rCanceled) {
654
- return false
655
- }
736
+ // Serializing a newly added ancestor can stage an already-published
737
+ // descendant before the paired remove is normalized. This is the
738
+ // common DOM shape used by Cocos Creator when it inserts a wrapper and
739
+ // moves its existing GameCanvas into it. Until the destination add is
740
+ // queued, the node still belongs to the previously published replay
741
+ // tree and must remain eligible for the atomic remove + add transition.
742
+ // A genuinely new node has no previous publication token and therefore
743
+ // still falls through to false below.
656
744
  }
657
745
  var publicationToken = publicationTokenByNode.get(node)
658
746
  return Boolean(
@@ -1125,7 +1213,10 @@ export function record(options) {
1125
1213
  )
1126
1214
  }
1127
1215
 
1128
- function tryMergePendingPureAddMutationAdmission(entry) {
1216
+ function tryMergePendingPureAddMutationAdmission(
1217
+ entry,
1218
+ admissionBytesLimit
1219
+ ) {
1129
1220
  var previousEntry =
1130
1221
  pendingMutationAdmissionQueue[
1131
1222
  pendingMutationAdmissionQueue.length - 1
@@ -1139,7 +1230,7 @@ export function record(options) {
1139
1230
  !isPureAddMutationPayload(mutationPayload) ||
1140
1231
  previousEntry[1] + entry[1] > MAX_MUTATION_EMIT_APPROX_BYTES ||
1141
1232
  pendingMutationAdmissionApproxBytes + entry[1] >
1142
- MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES
1233
+ admissionBytesLimit
1143
1234
  ) {
1144
1235
  return false
1145
1236
  }
@@ -1171,16 +1262,27 @@ export function record(options) {
1171
1262
  })
1172
1263
  return
1173
1264
  }
1265
+ var admissionBytesLimit = replayMemoryBudget
1266
+ ? Math.min(
1267
+ MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES,
1268
+ REPLAY_MEMORY_BUDGET_BYTES - replayMemoryBudget.$rSegment()
1269
+ )
1270
+ : MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES
1174
1271
  for (var entryIndex = 0; entryIndex < mutationEntries.length; entryIndex += 1) {
1175
1272
  var entry = mutationEntries[entryIndex]
1176
- if (tryMergePendingPureAddMutationAdmission(entry)) {
1273
+ if (
1274
+ tryMergePendingPureAddMutationAdmission(
1275
+ entry,
1276
+ admissionBytesLimit
1277
+ )
1278
+ ) {
1177
1279
  continue
1178
1280
  }
1179
1281
  if (
1180
1282
  pendingMutationAdmissionQueue.length + 1 >
1181
1283
  MAX_PENDING_MUTATION_ADMISSION_PAYLOADS ||
1182
1284
  pendingMutationAdmissionApproxBytes + entry[1] >
1183
- MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES
1285
+ admissionBytesLimit
1184
1286
  ) {
1185
1287
  var rejectedTail = mutationEntries.slice(entryIndex)
1186
1288
  rejectedTail.forEach(function (rejectedEntry) {
@@ -1743,6 +1845,20 @@ export function record(options) {
1743
1845
  }
1744
1846
 
1745
1847
  function snapshotCanvasIfActive(canvas, snapshotOptions) {
1848
+ if (
1849
+ replayMemoryBudget &&
1850
+ pendingMutationAdmissionApproxBytes +
1851
+ replayMemoryBudget.$rSegment() >=
1852
+ REPLAY_MEMORY_HIGH_WATERMARK_BYTES &&
1853
+ snapshotOptions &&
1854
+ (snapshotOptions.scheduler === 'continuous_snapshot' ||
1855
+ snapshotOptions.scheduler === 'webgl_snapshot')
1856
+ ) {
1857
+ return Promise.resolve({
1858
+ ok: false,
1859
+ reason: 'memory_pressure'
1860
+ })
1861
+ }
1746
1862
  if (isNodeIgnored(canvas)) {
1747
1863
  return Promise.resolve({
1748
1864
  ok: false,
@@ -3523,6 +3639,9 @@ export function record(options) {
3523
3639
  }
3524
3640
  recordStopped = true
3525
3641
  ;[
3642
+ function () {
3643
+ clearInterval(replayTimeAnchorIntervalId)
3644
+ },
3526
3645
  discardPendingMutationAdmissions,
3527
3646
  cancelMutationSourceFlushContinuation,
3528
3647
  cancelScheduledFullSnapshot,
@@ -3563,6 +3682,7 @@ export function record(options) {
3563
3682
 
3564
3683
  var recorder = {
3565
3684
  stop: stopRecording,
3685
+ $rEmitTimeAnchor: emitReplayTimeAnchor,
3566
3686
  $rFlushCanvasCommands: function () {
3567
3687
  // A previous boundary pass may have preserved the exact Canvas record
3568
3688
  // after transient segment/encoder backpressure. Retry that object before
@@ -3629,6 +3749,7 @@ function createInactiveRecorder() {
3629
3749
  var noop = function () {}
3630
3750
  var recorder = {
3631
3751
  stop: noop,
3752
+ $rEmitTimeAnchor: noop,
3632
3753
  $rFlushCanvasCommands: noop,
3633
3754
  snapshotCanvas: noop,
3634
3755
  getSerializedNodeIdForDebug: noop,