@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
@@ -38,12 +38,36 @@ export function startRecording(
38
38
  ? recordOverride || record
39
39
  : record
40
40
  var cleanupTasks = []
41
+ var replayMemoryBudget = {
42
+ $rRecord: function () {
43
+ return 0
44
+ },
45
+ $rSegment: function () {
46
+ return 0
47
+ }
48
+ }
41
49
  var isRecordingStopped = false
42
50
  var isRecordingReady = false
43
51
  var pendingStopRequested = false
44
52
  var pendingStopReason
45
53
  var stoppedNotificationSent = false
46
54
  var flushRecorderBeforePageExit = function () {}
55
+ var emitReplayTimeAnchor = function () {}
56
+ var finalReplayTimeAnchorRequested = false
57
+ var hasSegmentCollection = false
58
+ function emitFinalReplayTimeAnchor() {
59
+ if (
60
+ finalReplayTimeAnchorRequested ||
61
+ document.visibilityState !== 'visible'
62
+ ) {
63
+ return true
64
+ }
65
+ var admissionResult = emitReplayTimeAnchor()
66
+ if (admissionResult === true) {
67
+ finalReplayTimeAnchorRequested = true
68
+ }
69
+ return admissionResult
70
+ }
47
71
  var replayResetRequestedBeforeRecorder = false
48
72
  var requestReplayReset = function () {
49
73
  replayResetRequestedBeforeRecorder = true
@@ -71,6 +95,16 @@ export function startRecording(
71
95
  pendingStopReason = flushReason
72
96
  return
73
97
  }
98
+ if (!hasSegmentCollection) {
99
+ try {
100
+ emitFinalReplayTimeAnchor()
101
+ } catch (error) {
102
+ addTelemetryDebug('Session Replay final time anchor failed.', {
103
+ reason: flushReason,
104
+ error: String(error)
105
+ })
106
+ }
107
+ }
74
108
  isRecordingStopped = true
75
109
  var firstCleanupError
76
110
  cleanupTasks
@@ -129,10 +163,12 @@ export function startRecording(
129
163
  var beginMandatoryFullSnapshotRecovery = function () {}
130
164
  var discardMandatoryFullSnapshotRecovery = function () {}
131
165
  var wasLastEmitBackpressured = function () {}
166
+ var replayTimeAnchorsEnabled = true
132
167
  if (!canUseEventBridge()) {
133
168
  const session = sessionManager.findTrackedSession()
134
169
  let isRecordErrorSessionReplay =
135
170
  session && session.errorSessionReplayAllowed && !session.sessionHasError
171
+ replayTimeAnchorsEnabled = !isRecordErrorSessionReplay
136
172
  var segmentCollection = startSegmentCollection(
137
173
  lifeCycle,
138
174
  configuration,
@@ -143,7 +179,7 @@ export function startRecording(
143
179
  isRecordErrorSessionReplay,
144
180
  {
145
181
  beforePageExitFlush: function (pageExitEvent) {
146
- flushRecorderBeforePageExit(pageExitEvent)
182
+ return flushRecorderBeforePageExit(pageExitEvent)
147
183
  },
148
184
  onReplayResetNeeded: function (reason) {
149
185
  if (__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
@@ -155,6 +191,7 @@ export function startRecording(
155
191
  onReplayResetExhausted: function (reason) {
156
192
  stopRecording(reason || 'full_snapshot_failure_limit')
157
193
  },
194
+ memoryBudget: replayMemoryBudget,
158
195
  onSegmentFlushed: __BUILD_ENV__REPLAY_DEBUG_ENABLED__
159
196
  ? function (segmentFlush) {
160
197
  replaySegmentFlushCount += 1
@@ -176,6 +213,7 @@ export function startRecording(
176
213
  : undefined
177
214
  }
178
215
  )
216
+ hasSegmentCollection = true
179
217
  addRecord = segmentCollection.addRecord
180
218
  addBaselineRecords = segmentCollection.$rAddBaselineRecords
181
219
  wasLastEmitBackpressured =
@@ -203,7 +241,12 @@ export function startRecording(
203
241
  ({ previousState, newState }) => {
204
242
  if (!previousState.hasError && newState.hasError) {
205
243
  isRecordErrorSessionReplay = false
244
+ replayTimeAnchorsEnabled = true
206
245
  unlockSegment()
246
+ // Error-only recordings do not need periodic anchor-only
247
+ // segments while their buffer is locked. Establish the live
248
+ // timeline immediately when the first error unlocks it.
249
+ emitReplayTimeAnchor()
207
250
  }
208
251
  }
209
252
  )
@@ -248,6 +291,10 @@ export function startRecording(
248
291
  beginMandatoryFullSnapshotRecovery,
249
292
  $rOnMandatoryFullSnapshotAbandoned:
250
293
  discardMandatoryFullSnapshotRecovery,
294
+ $rShouldEmitTimeAnchor: function () {
295
+ return replayTimeAnchorsEnabled
296
+ },
297
+ $rMemoryBudget: replayMemoryBudget,
251
298
  onFullSnapshotFailure: stopRecording
252
299
  })
253
300
  } else {
@@ -262,12 +309,18 @@ export function startRecording(
262
309
  beginMandatoryFullSnapshotRecovery,
263
310
  $rOnMandatoryFullSnapshotAbandoned:
264
311
  discardMandatoryFullSnapshotRecovery,
312
+ $rShouldEmitTimeAnchor: function () {
313
+ return replayTimeAnchorsEnabled
314
+ },
315
+ $rMemoryBudget: replayMemoryBudget,
265
316
  onFullSnapshotFailure: stopRecording
266
317
  })
267
318
  }
268
319
  if (!_record || typeof _record.stop !== 'function') {
269
320
  throw new Error('Session Replay recorder failed to initialize.')
270
321
  }
322
+ emitReplayTimeAnchor =
323
+ _record.$rEmitTimeAnchor || emitReplayTimeAnchor
271
324
  var stopRecorder = _record.stop
272
325
  if (stopSegmentCollection) {
273
326
  // Remove the provisional entry and restore the intended successful-stop
@@ -311,6 +364,12 @@ export function startRecording(
311
364
  // mutations are never attached to the stale pre-overflow snapshot.
312
365
  _record.flushMutations()
313
366
  flushCanvasCommands()
367
+ if (
368
+ pageExitEvent.reason === PageExitReason.HIDDEN ||
369
+ document.visibilityState === 'visible'
370
+ ) {
371
+ return emitReplayTimeAnchor()
372
+ }
314
373
  return
315
374
  }
316
375
  if (!flushScheduledFullSnapshot()) {
@@ -324,6 +383,7 @@ export function startRecording(
324
383
  // still writable here, including the second unload pass after synchronous
325
384
  // encoder backpressure is released.
326
385
  flushCanvasCommands()
386
+ return emitFinalReplayTimeAnchor()
327
387
  }
328
388
  requestReplayReset = createReplayResetScheduler(
329
389
  takeSubsequentFullSnapshot,
@@ -5,7 +5,8 @@ import {
5
5
  isEmptyObject,
6
6
  LifeCycleEventType,
7
7
  RumEventType,
8
- deviceInfo,
8
+ createBoundedBuffer,
9
+ getDeviceInfoWithHighEntropyValues,
9
10
  currentDrift,
10
11
  createEventRateLimiter,
11
12
  limitModification,
@@ -41,7 +42,8 @@ export function startRumAssembly(
41
42
  actionContexts,
42
43
  displayContext,
43
44
  getCommonContext,
44
- reportError
45
+ reportError,
46
+ getDeviceInfoImp = getDeviceInfoWithHighEntropyValues
45
47
  ) {
46
48
  modifiableFieldPathsByEvent[RumEventType.VIEW] = assign(
47
49
  {},
@@ -90,9 +92,21 @@ export function startRumAssembly(
90
92
  configuration.eventRateLimiterThreshold,
91
93
  reportError
92
94
  )
95
+ var pendingRawEvents = createBoundedBuffer()
96
+ var resolvedDeviceInfo
97
+ getDeviceInfoImp(function (deviceInfo) {
98
+ resolvedDeviceInfo = deviceInfo
99
+ pendingRawEvents.drain()
100
+ })
93
101
  lifeCycle.subscribe(
94
102
  LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
95
- function (data) {
103
+ function assemble(data) {
104
+ if (!resolvedDeviceInfo) {
105
+ pendingRawEvents.add(function () {
106
+ assemble(data)
107
+ })
108
+ return
109
+ }
96
110
  var startTime = data.startTime
97
111
  var rawRumEvent = data.rawRumEvent
98
112
  var savedCommonContext = data.savedCommonContext
@@ -133,7 +147,7 @@ export function startRumAssembly(
133
147
  application: {
134
148
  id: configuration.applicationId
135
149
  },
136
- device: deviceInfo,
150
+ device: resolvedDeviceInfo,
137
151
  env: configuration.env || '',
138
152
  service: viewContext.service || configuration.service || 'browser',
139
153
  version: viewContext.version || configuration.version || '',
@@ -230,6 +230,10 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
230
230
  {
231
231
  applicationId: initConfiguration.applicationId,
232
232
  actionNameAttribute: initConfiguration.actionNameAttribute,
233
+ enablePrivacyForActionName: isNullUndefinedDefaultValue(
234
+ initConfiguration.enablePrivacyForActionName,
235
+ false
236
+ ),
233
237
  sessionReplaySampleRate: isNullUndefinedDefaultValue(
234
238
  initConfiguration.sessionReplaySampleRate,
235
239
  100
@@ -0,0 +1,356 @@
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
+ }
@@ -1405,7 +1405,8 @@ function processChildListMutations(
1405
1405
  parent
1406
1406
  )
1407
1407
  if (pendingRootTask) {
1408
- if (isNodePublished(node)) {
1408
+ var pendingRootNodeWasPublished = isNodePublished(node)
1409
+ if (pendingRootNodeWasPublished) {
1409
1410
  mutationTasksController.markPendingRootTaskPublishedDependency(
1410
1411
  pendingRootTask
1411
1412
  )
@@ -1417,18 +1418,27 @@ function processChildListMutations(
1417
1418
  // Several descendants can be removed in one batch. Rebuild the
1418
1419
  // unpublished root once after normalization instead of once per node.
1419
1420
  pendingRootTasksToRefresh.add(pendingRootTask)
1421
+ if (!pendingRootNodeWasPublished) {
1422
+ continue
1423
+ }
1424
+ // A published descendant can also be serialized under a newly added
1425
+ // ancestor in its current destination. It still needs a remove for
1426
+ // the old replay-tree parent; otherwise the player builds a duplicate
1427
+ // same-id node and later Canvas mutations have an ambiguous target.
1428
+ // Refresh the destination add above, then fall through and emit the
1429
+ // paired published removal below.
1430
+ } else {
1431
+ pendingRootTasksToRefresh.delete(pendingRootTask)
1432
+ if (
1433
+ !mutationTasksController.handlePendingRootRemoval(
1434
+ pendingRootTask,
1435
+ node
1436
+ )
1437
+ ) {
1438
+ pendingRootRemovalOverflowed = true
1439
+ }
1420
1440
  continue
1421
1441
  }
1422
- pendingRootTasksToRefresh.delete(pendingRootTask)
1423
- if (
1424
- !mutationTasksController.handlePendingRootRemoval(
1425
- pendingRootTask,
1426
- node
1427
- )
1428
- ) {
1429
- pendingRootRemovalOverflowed = true
1430
- }
1431
- continue
1432
1442
  }
1433
1443
  if (hasSerializedNode(node) && isNodePublished(node)) {
1434
1444
  var removeMutation = {