@cloudcare/browser-rum 3.2.18 → 3.2.19

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 (87) hide show
  1. package/README.md +4 -0
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/boot/rum.js +1 -1
  5. package/cjs/boot/rum.js.map +1 -1
  6. package/cjs/boot/startRecording.js +39 -2
  7. package/cjs/boot/startRecording.js.map +1 -1
  8. package/cjs/domain/assembly.js +10 -2
  9. package/cjs/domain/assembly.js.map +1 -1
  10. package/cjs/domain/configuration.js +13 -3
  11. package/cjs/domain/configuration.js.map +1 -1
  12. package/cjs/domain/deflate/deflateWorker.js +1 -1
  13. package/cjs/domain/performanceObservable.js +2 -1
  14. package/cjs/domain/performanceObservable.js.map +1 -1
  15. package/cjs/domain/replay/record/mutationObserver.js +2 -2
  16. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  17. package/cjs/domain/replay/record/observers.js +26 -26
  18. package/cjs/domain/replay/record/observers.js.map +1 -1
  19. package/cjs/domain/replay/record/privacy.js +4 -3
  20. package/cjs/domain/replay/record/privacy.js.map +1 -1
  21. package/cjs/domain/replay/record/serializationUtils.js +2 -2
  22. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  23. package/cjs/domain/replay/record/serialize.js +3 -3
  24. package/cjs/domain/replay/record/serialize.js.map +1 -1
  25. package/cjs/domain/replay/record/shadowRootsController.js +1 -1
  26. package/cjs/domain/replay/record/shadowRootsController.js.map +1 -1
  27. package/cjs/domain/replay/replayStats.js +1 -0
  28. package/cjs/domain/replay/replayStats.js.map +1 -1
  29. package/cjs/domain/replay/segmentCollection/segmentCollection.js +39 -13
  30. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  31. package/cjs/domain/rumEventsCollection/error/errorCollection.js +12 -1
  32. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +27 -10
  34. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  35. package/cjs/domain/rumSessionManager.js +90 -26
  36. package/cjs/domain/rumSessionManager.js.map +1 -1
  37. package/esm/boot/buildEnv.js +1 -1
  38. package/esm/boot/rum.js +1 -1
  39. package/esm/boot/rum.js.map +1 -1
  40. package/esm/boot/startRecording.js +38 -3
  41. package/esm/boot/startRecording.js.map +1 -1
  42. package/esm/domain/assembly.js +10 -2
  43. package/esm/domain/assembly.js.map +1 -1
  44. package/esm/domain/configuration.js +13 -3
  45. package/esm/domain/configuration.js.map +1 -1
  46. package/esm/domain/deflate/deflateWorker.js +1 -1
  47. package/esm/domain/performanceObservable.js +2 -1
  48. package/esm/domain/performanceObservable.js.map +1 -1
  49. package/esm/domain/replay/record/mutationObserver.js +2 -2
  50. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  51. package/esm/domain/replay/record/observers.js +26 -26
  52. package/esm/domain/replay/record/observers.js.map +1 -1
  53. package/esm/domain/replay/record/privacy.js +4 -3
  54. package/esm/domain/replay/record/privacy.js.map +1 -1
  55. package/esm/domain/replay/record/serializationUtils.js +2 -2
  56. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  57. package/esm/domain/replay/record/serialize.js +3 -3
  58. package/esm/domain/replay/record/serialize.js.map +1 -1
  59. package/esm/domain/replay/record/shadowRootsController.js +1 -1
  60. package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
  61. package/esm/domain/replay/replayStats.js +1 -1
  62. package/esm/domain/replay/replayStats.js.map +1 -1
  63. package/esm/domain/replay/segmentCollection/segmentCollection.js +39 -13
  64. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  65. package/esm/domain/rumEventsCollection/error/errorCollection.js +12 -1
  66. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  67. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +28 -11
  68. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  69. package/esm/domain/rumSessionManager.js +89 -26
  70. package/esm/domain/rumSessionManager.js.map +1 -1
  71. package/package.json +4 -4
  72. package/src/boot/rum.js +1 -0
  73. package/src/boot/startRecording.js +45 -5
  74. package/src/domain/assembly.js +20 -3
  75. package/src/domain/configuration.js +36 -3
  76. package/src/domain/performanceObservable.js +2 -1
  77. package/src/domain/replay/record/mutationObserver.js +12 -2
  78. package/src/domain/replay/record/observers.js +43 -28
  79. package/src/domain/replay/record/privacy.js +8 -2
  80. package/src/domain/replay/record/serializationUtils.js +2 -2
  81. package/src/domain/replay/record/serialize.js +9 -2
  82. package/src/domain/replay/record/shadowRootsController.js +1 -1
  83. package/src/domain/replay/replayStats.js +1 -1
  84. package/src/domain/replay/segmentCollection/segmentCollection.js +47 -20
  85. package/src/domain/rumEventsCollection/error/errorCollection.js +12 -0
  86. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +31 -22
  87. package/src/domain/rumSessionManager.js +125 -34
@@ -61,31 +61,39 @@ export function initObservers(o) {
61
61
  o.configuration,
62
62
  o.shadowRootsController
63
63
  )
64
- var mousemoveHandler = initMoveObserver(o.mousemoveCb)
64
+ var mousemoveHandler = initMoveObserver(o.mousemoveCb, o.configuration)
65
65
  var mouseInteractionHandler = initMouseInteractionObserver(
66
66
  o.mouseInteractionCb,
67
- o.configuration.defaultPrivacyLevel
67
+ o.configuration
68
68
  )
69
69
  var scrollHandler = initScrollObserver(
70
70
  o.scrollCb,
71
- o.configuration.defaultPrivacyLevel,
71
+ o.configuration,
72
72
  o.elementsScrollPositions
73
73
  )
74
- var viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb)
75
- var inputHandler = initInputObserver(
76
- o.inputCb,
77
- o.configuration.defaultPrivacyLevel
74
+ var viewportResizeHandler = initViewportResizeObserver(
75
+ o.viewportResizeCb,
76
+ o.configuration
78
77
  )
78
+ var inputHandler = initInputObserver(o.inputCb, o.configuration)
79
79
  var mediaInteractionHandler = initMediaInteractionObserver(
80
80
  o.mediaInteractionCb,
81
- o.configuration.defaultPrivacyLevel
81
+ o.configuration
82
+ )
83
+ var styleSheetObserver = initStyleSheetObserver(
84
+ o.styleSheetCb,
85
+ o.configuration
82
86
  )
83
- var styleSheetObserver = initStyleSheetObserver(o.styleSheetCb)
84
- var focusHandler = initFocusObserver(o.focusCb)
87
+ var focusHandler = initFocusObserver(o.focusCb, o.configuration)
85
88
  var visualViewportResizeHandler = initVisualViewportResizeObserver(
86
- o.visualViewportResizeCb
89
+ o.visualViewportResizeCb,
90
+ o.configuration
91
+ )
92
+ var frustrationHandler = initFrustrationObserver(
93
+ o.lifeCycle,
94
+ o.frustrationCb,
95
+ o.configuration
87
96
  )
88
- var frustrationHandler = initFrustrationObserver(o.lifeCycle, o.frustrationCb)
89
97
 
90
98
  return {
91
99
  flush: function () {
@@ -116,7 +124,7 @@ export function initMutationObserver(cb, configuration, shadowRootsController) {
116
124
  )
117
125
  }
118
126
 
119
- export function initMoveObserver(cb) {
127
+ export function initMoveObserver(cb, configuration) {
120
128
  var _updatePosition = throttle(
121
129
  function (event) {
122
130
  var target = getEventTarget(event)
@@ -184,11 +192,11 @@ var eventTypeToMouseInteraction = {
184
192
  [DOM_EVENT.TOUCH_START]: MouseInteractionType.TouchStart,
185
193
  [DOM_EVENT.TOUCH_END]: MouseInteractionType.TouchEnd
186
194
  }
187
- export function initMouseInteractionObserver(cb, defaultPrivacyLevel) {
195
+ export function initMouseInteractionObserver(cb, configuration) {
188
196
  var handler = function (event) {
189
197
  var target = getEventTarget(event)
190
198
  if (
191
- getNodePrivacyLevel(target, defaultPrivacyLevel) ===
199
+ getNodePrivacyLevel(target, configuration.defaultPrivacyLevel) ===
192
200
  NodePrivacyLevel.HIDDEN ||
193
201
  !hasSerializedNode(target)
194
202
  ) {
@@ -247,12 +255,12 @@ function tryToComputeCoordinates(event) {
247
255
  return { x: x, y: y }
248
256
  }
249
257
 
250
- function initScrollObserver(cb, defaultPrivacyLevel, elementsScrollPositions) {
258
+ function initScrollObserver(cb, configuration, elementsScrollPositions) {
251
259
  var _updatePosition = throttle(function (event) {
252
260
  var target = getEventTarget(event)
253
261
  if (
254
262
  !target ||
255
- getNodePrivacyLevel(target, defaultPrivacyLevel) ===
263
+ getNodePrivacyLevel(target, configuration.defaultPrivacyLevel) ===
256
264
  NodePrivacyLevel.HIDDEN ||
257
265
  !hasSerializedNode(target)
258
266
  ) {
@@ -290,11 +298,11 @@ function initScrollObserver(cb, defaultPrivacyLevel, elementsScrollPositions) {
290
298
  }
291
299
  }
292
300
 
293
- function initViewportResizeObserver(cb) {
301
+ function initViewportResizeObserver(cb, configuration) {
294
302
  return initViewportObservable().subscribe(cb).unsubscribe
295
303
  }
296
304
 
297
- export function initInputObserver(cb, defaultPrivacyLevel, target) {
305
+ export function initInputObserver(cb, configuration, target) {
298
306
  if (target === undefined) {
299
307
  target = document
300
308
  }
@@ -351,7 +359,10 @@ export function initInputObserver(cb, defaultPrivacyLevel, target) {
351
359
  }
352
360
 
353
361
  function onElementChange(target) {
354
- var nodePrivacyLevel = getNodePrivacyLevel(target, defaultPrivacyLevel)
362
+ var nodePrivacyLevel = getNodePrivacyLevel(
363
+ target,
364
+ configuration.defaultPrivacyLevel
365
+ )
355
366
  if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
356
367
  return
357
368
  }
@@ -360,12 +371,12 @@ export function initInputObserver(cb, defaultPrivacyLevel, target) {
360
371
 
361
372
  let inputState
362
373
  if (type === 'radio' || type === 'checkbox') {
363
- if (shouldMaskNode(target, nodePrivacyLevel)) {
374
+ if (shouldMaskNode(configuration, target, nodePrivacyLevel)) {
364
375
  return
365
376
  }
366
377
  inputState = { isChecked: target.checked }
367
378
  } else {
368
- var value = getElementInputValue(target, nodePrivacyLevel)
379
+ var value = getElementInputValue(configuration, target, nodePrivacyLevel)
369
380
  if (value === undefined) {
370
381
  return
371
382
  }
@@ -417,7 +428,7 @@ export function initInputObserver(cb, defaultPrivacyLevel, target) {
417
428
  }
418
429
  }
419
430
 
420
- export function initStyleSheetObserver(cb) {
431
+ export function initStyleSheetObserver(cb, configuration) {
421
432
  function checkStyleSheetAndCallback(styleSheet, callback) {
422
433
  if (styleSheet && hasSerializedNode(styleSheet.ownerNode)) {
423
434
  callback(getSerializedNodeId(styleSheet.ownerNode))
@@ -488,12 +499,12 @@ export function initStyleSheetObserver(cb) {
488
499
  }
489
500
  }
490
501
 
491
- function initMediaInteractionObserver(mediaInteractionCb, defaultPrivacyLevel) {
502
+ function initMediaInteractionObserver(mediaInteractionCb, configuration) {
492
503
  var handler = function (event) {
493
504
  var target = getEventTarget(event)
494
505
  if (
495
506
  !target ||
496
- getNodePrivacyLevel(target, defaultPrivacyLevel) ===
507
+ getNodePrivacyLevel(target, configuration.defaultPrivacyLevel) ===
497
508
  NodePrivacyLevel.HIDDEN ||
498
509
  !hasSerializedNode(target)
499
510
  ) {
@@ -515,7 +526,7 @@ function initMediaInteractionObserver(mediaInteractionCb, defaultPrivacyLevel) {
515
526
  ).stop
516
527
  }
517
528
 
518
- function initFocusObserver(focusCb) {
529
+ function initFocusObserver(focusCb, configuration) {
519
530
  return addEventListeners(
520
531
  window,
521
532
  [DOM_EVENT.FOCUS, DOM_EVENT.BLUR],
@@ -525,7 +536,7 @@ function initFocusObserver(focusCb) {
525
536
  ).stop
526
537
  }
527
538
 
528
- function initVisualViewportResizeObserver(cb) {
539
+ function initVisualViewportResizeObserver(cb, configuration) {
529
540
  if (!window.visualViewport) {
530
541
  return noop
531
542
  }
@@ -554,7 +565,11 @@ function initVisualViewportResizeObserver(cb) {
554
565
  }
555
566
  }
556
567
 
557
- export function initFrustrationObserver(lifeCycle, frustrationCb) {
568
+ export function initFrustrationObserver(
569
+ lifeCycle,
570
+ frustrationCb,
571
+ configuration
572
+ ) {
558
573
  return lifeCycle.subscribe(
559
574
  LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
560
575
  function (data) {
@@ -151,7 +151,12 @@ export function getNodeSelfPrivacyLevel(node) {
151
151
  * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
152
152
  * node if it is ignored or hidden? it doesn't matter since it won't be serialized).
153
153
  */
154
- export function shouldMaskNode(node, privacyLevel) {
154
+ export function shouldMaskNode(configuration, node, privacyLevel) {
155
+ if (
156
+ configuration.shouldMaskNode &&
157
+ configuration.shouldMaskNode(node, privacyLevel) === true
158
+ )
159
+ return true
155
160
  switch (privacyLevel) {
156
161
  case NodePrivacyLevel.MASK:
157
162
  case NodePrivacyLevel.HIDDEN:
@@ -192,6 +197,7 @@ export var censorText = function (text) {
192
197
  }
193
198
 
194
199
  export function getTextContent(
200
+ configuration,
195
201
  textNode,
196
202
  ignoreWhiteSpace,
197
203
  parentNodePrivacyLevel
@@ -216,7 +222,7 @@ export function getTextContent(
216
222
  } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
217
223
  // Should never occur, but just in case, we set to CENSORED_MARK.
218
224
  textContent = CENSORED_STRING_MARK
219
- } else if (shouldMaskNode(textNode, nodePrivacyLevel)) {
225
+ } else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
220
226
  if (
221
227
  // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
222
228
  parentTagName === 'DATALIST' ||
@@ -37,7 +37,7 @@ export function setSerializedNodeId(node, serializeNodeId) {
37
37
  * the input privacy mode of the element.
38
38
  * PERFROMANCE OPTIMIZATION: Assumes that privacy level `HIDDEN` is never encountered because of earlier checks.
39
39
  */
40
- export function getElementInputValue(element, nodePrivacyLevel) {
40
+ export function getElementInputValue(configuration, element, nodePrivacyLevel) {
41
41
  /*
42
42
  BROWSER SPEC NOTE: <input>, <select>
43
43
  For some <input> elements, the `value` is an exceptional property/attribute that has the
@@ -46,7 +46,7 @@ export function getElementInputValue(element, nodePrivacyLevel) {
46
46
  */
47
47
  var tagName = element.tagName
48
48
  var value = element.value
49
- if (shouldMaskNode(element, nodePrivacyLevel)) {
49
+ if (shouldMaskNode(configuration, element, nodePrivacyLevel)) {
50
50
  var type = element.type
51
51
  if (
52
52
  tagName === 'INPUT' &&
@@ -228,6 +228,7 @@ function serializeTextNode(textNode, options) {
228
228
  // So just let it be undefined which is ok in this use case.
229
229
  // var parentTagName = textNode.parentElement && textNode.parentElement.tagName
230
230
  var textContent = getTextContent(
231
+ options.configuration,
231
232
  textNode,
232
233
  options.ignoreWhiteSpace || false,
233
234
  options.parentNodePrivacyLevel
@@ -407,7 +408,11 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
407
408
  tagName === 'option' ||
408
409
  tagName === 'input')
409
410
  ) {
410
- var formValue = getElementInputValue(element, nodePrivacyLevel)
411
+ var formValue = getElementInputValue(
412
+ options.configuration,
413
+ element,
414
+ nodePrivacyLevel
415
+ )
411
416
  if (formValue !== undefined) {
412
417
  safeAttrs.value = formValue
413
418
  }
@@ -459,7 +464,9 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
459
464
  ) {
460
465
  if (nodePrivacyLevel === NodePrivacyLevel.ALLOW) {
461
466
  safeAttrs.checked = !!inputElement.checked
462
- } else if (shouldMaskNode(inputElement, nodePrivacyLevel)) {
467
+ } else if (
468
+ shouldMaskNode(options.configuration, inputElement, nodePrivacyLevel)
469
+ ) {
463
470
  delete safeAttrs.checked
464
471
  }
465
472
  }
@@ -23,7 +23,7 @@ export var initShadowRootsController = function (configuration, data) {
23
23
  // the change event no do bubble up across the shadow root, we have to listen on the shadow root
24
24
  var stopInputObserver = initInputObserver(
25
25
  inputCb,
26
- configuration.defaultPrivacyLevel,
26
+ configuration,
27
27
  shadowRoot
28
28
  )
29
29
  controllerByShadowRoot.set(shadowRoot, {
@@ -48,7 +48,7 @@ function getOrCreateReplayStats(viewId) {
48
48
  return replayStats
49
49
  }
50
50
 
51
- function deleteOldestStats() {
51
+ export function deleteOldestStats() {
52
52
  if (!statsPerView) {
53
53
  return
54
54
  }
@@ -46,7 +46,8 @@ export function startSegmentCollection(
46
46
  sessionManager,
47
47
  viewContexts,
48
48
  httpRequest,
49
- encoder
49
+ encoder,
50
+ isLocked = false
50
51
  ) {
51
52
  return doStartSegmentCollection(
52
53
  lifeCycle,
@@ -54,7 +55,8 @@ export function startSegmentCollection(
54
55
  return computeSegmentContext(configuration, sessionManager, viewContexts)
55
56
  },
56
57
  httpRequest,
57
- encoder
58
+ encoder,
59
+ isLocked
58
60
  )
59
61
  }
60
62
 
@@ -68,11 +70,13 @@ export function doStartSegmentCollection(
68
70
  lifeCycle,
69
71
  getSegmentContext,
70
72
  httpRequest,
71
- encoder
73
+ encoder,
74
+ isLocked
72
75
  ) {
73
76
  var state = {
74
77
  status: SegmentCollectionStatus.WaitingForInitialRecord,
75
- nextSegmentCreationReason: 'init'
78
+ nextSegmentCreationReason: 'init',
79
+ isLocked: isLocked
76
80
  }
77
81
  var subscribeViewCreated = lifeCycle.subscribe(
78
82
  LifeCycleEventType.VIEW_CREATED,
@@ -88,33 +92,46 @@ export function doStartSegmentCollection(
88
92
  }
89
93
  )
90
94
  var unsubscribePageExited = subscribePageExited.unsubscribe
91
-
92
- function flushSegment(flushReason) {
95
+ const lockedFlushReason = ['view_change', 'buffer_checkout']
96
+ function flushSegment(flushReason, callback) {
97
+ const isLocked = state.isLocked
93
98
  if (state.status === SegmentCollectionStatus.SegmentPending) {
94
- state.segment.flush(function (metadata, encoderResult) {
95
- var payload = buildReplayPayload(
96
- encoderResult.output,
97
- metadata,
98
- encoderResult.rawBytesCount
99
- )
100
-
101
- if (isPageExitReason(flushReason)) {
102
- httpRequest.sendOnExit(payload)
103
- } else {
104
- httpRequest.send(payload)
99
+ if (isLocked && lockedFlushReason.includes(flushReason)) {
100
+ state.segment.flush(() => {
101
+ if (callback) callback()
102
+ })
103
+ } else {
104
+ // if the segment is locked, we don't send it
105
+ if (isLocked) {
106
+ return
105
107
  }
106
- })
108
+ state.segment.flush(function (metadata, encoderResult) {
109
+ var payload = buildReplayPayload(
110
+ encoderResult.output,
111
+ metadata,
112
+ encoderResult.rawBytesCount
113
+ )
114
+
115
+ if (isPageExitReason(flushReason)) {
116
+ httpRequest.sendOnExit(payload)
117
+ } else {
118
+ httpRequest.send(payload)
119
+ }
120
+ })
121
+ }
107
122
  clearTimeout(state.expirationTimeoutId)
108
123
  }
109
124
 
110
125
  if (flushReason !== 'stop') {
111
126
  state = {
112
127
  status: SegmentCollectionStatus.WaitingForInitialRecord,
113
- nextSegmentCreationReason: flushReason
128
+ nextSegmentCreationReason: flushReason,
129
+ isLocked: state.isLocked
114
130
  }
115
131
  } else {
116
132
  state = {
117
- status: SegmentCollectionStatus.Stopped
133
+ status: SegmentCollectionStatus.Stopped,
134
+ isLocked: false
118
135
  }
119
136
  }
120
137
  }
@@ -138,6 +155,7 @@ export function doStartSegmentCollection(
138
155
  context: context,
139
156
  creationReason: state.nextSegmentCreationReason
140
157
  }),
158
+ isLocked: state.isLocked,
141
159
  expirationTimeoutId: setTimeout(function () {
142
160
  flushSegment('segment_duration_limit')
143
161
  }, SEGMENT_DURATION_LIMIT)
@@ -151,6 +169,15 @@ export function doStartSegmentCollection(
151
169
  })
152
170
  },
153
171
 
172
+ unlockSegment: function () {
173
+ state.isLocked = false
174
+ },
175
+ flushBufferSegment: function (callback) {
176
+ flushSegment('buffer_checkout', callback)
177
+ },
178
+ isLocked: function () {
179
+ return state.isLocked
180
+ },
154
181
  stop: function () {
155
182
  flushSegment('stop')
156
183
  unsubscribeViewCreated()
@@ -18,6 +18,7 @@ import { PageState } from '../../contexts/pageStateHistory'
18
18
  export function startErrorCollection(
19
19
  lifeCycle,
20
20
  configuration,
21
+ sessionManager,
21
22
  pageStateHistory
22
23
  ) {
23
24
  var errorObservable = new Observable()
@@ -25,8 +26,19 @@ export function startErrorCollection(
25
26
  trackConsoleError(errorObservable)
26
27
  trackRuntimeError(errorObservable)
27
28
  trackReportError(configuration, errorObservable)
29
+ var session = sessionManager.findTrackedSession()
30
+ let hasError = session.isErrorSession && session.sessionHasError
31
+ if (session.isErrorSession) {
32
+ lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
33
+ hasError = false
34
+ })
35
+ }
28
36
 
29
37
  errorObservable.subscribe(function (error) {
38
+ if (session.isErrorSession && !hasError) {
39
+ sessionManager.setErrorForSession()
40
+ hasError = true
41
+ }
30
42
  lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error })
31
43
  })
32
44
 
@@ -1,37 +1,46 @@
1
- import { DOM_EVENT, addEventListeners } from '@cloudcare/browser-core'
2
-
1
+ import { DOM_EVENT, addEventListeners, noop } from '@cloudcare/browser-core'
2
+ import {
3
+ supportPerformanceTimingEvent,
4
+ RumPerformanceEntryType
5
+ } from '../../../domain/performanceObservable.js'
3
6
  export function trackFirstHidden(eventTarget) {
4
7
  if (typeof eventTarget === 'undefined') {
5
8
  eventTarget = window
6
9
  }
7
- var timeStamp
8
- var stopListeners
9
10
  if (document.visibilityState === 'hidden') {
10
- timeStamp = 0
11
- } else {
12
- timeStamp = Infinity
13
- var stopListeners = addEventListeners(
14
- eventTarget,
15
- [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE],
16
- function (event) {
17
- if (
18
- event.type === DOM_EVENT.PAGE_HIDE ||
19
- document.visibilityState === 'hidden'
20
- ) {
21
- timeStamp = event.timeStamp
22
- stopListeners()
23
- }
24
- },
25
- { capture: true }
26
- ).stop
11
+ return { getTimeStamp: () => 0, stop: noop }
12
+ }
13
+ if (supportPerformanceTimingEvent(RumPerformanceEntryType.VISIBILITY_STATE)) {
14
+ const firstHiddenEntry = performance
15
+ .getEntriesByType(RumPerformanceEntryType.VISIBILITY_STATE)
16
+ .find((entry) => entry.name === 'hidden')
17
+ if (firstHiddenEntry) {
18
+ return { getTimeStamp: () => firstHiddenEntry.startTime, stop: noop }
19
+ }
27
20
  }
21
+ let timeStamp = Infinity
22
+
23
+ const { stop } = addEventListeners(
24
+ eventTarget,
25
+ [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE],
26
+ (event) => {
27
+ if (
28
+ event.type === DOM_EVENT.PAGE_HIDE ||
29
+ document.visibilityState === 'hidden'
30
+ ) {
31
+ timeStamp = event.timeStamp
32
+ stop()
33
+ }
34
+ },
35
+ { capture: true }
36
+ )
28
37
 
29
38
  return {
30
39
  getTimeStamp: function () {
31
40
  return timeStamp
32
41
  },
33
42
  stop: function () {
34
- stopListeners && stopListeners()
43
+ stop()
35
44
  }
36
45
  }
37
46
  }