@cloudcare/browser-rum 3.1.19 → 3.1.21

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 (161) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.js +11 -10
  4. package/cjs/boot/rum.js.map +1 -1
  5. package/cjs/domain/assembly.js.map +1 -1
  6. package/cjs/domain/contexts/pageStateHistory.js +4 -1
  7. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  8. package/cjs/domain/contexts/urlContexts.js +3 -1
  9. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  10. package/cjs/domain/contexts/viewContexts.js +9 -1
  11. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  12. package/cjs/domain/locationChangeObservable.js +6 -4
  13. package/cjs/domain/locationChangeObservable.js.map +1 -1
  14. package/cjs/domain/performanceCollection.js +40 -90
  15. package/cjs/domain/performanceCollection.js.map +1 -1
  16. package/cjs/domain/performanceObservable.js +113 -0
  17. package/cjs/domain/performanceObservable.js.map +1 -0
  18. package/cjs/domain/performanceUtils.js +20 -0
  19. package/cjs/domain/performanceUtils.js.map +1 -0
  20. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  21. package/cjs/domain/replay/record/observers.js +58 -54
  22. package/cjs/domain/replay/record/observers.js.map +1 -1
  23. package/cjs/domain/requestCollection.js +6 -2
  24. package/cjs/domain/requestCollection.js.map +1 -1
  25. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +3 -1
  26. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +5 -7
  28. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  29. package/cjs/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +4 -4
  30. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -0
  31. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +64 -66
  32. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +18 -14
  34. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  35. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +41 -0
  36. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -0
  37. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
  38. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  39. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +8 -5
  40. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  41. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  42. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  43. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +1 -1
  44. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  45. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js +2 -1
  46. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  47. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  48. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  49. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +3 -19
  50. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  51. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -1
  52. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  53. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +7 -7
  54. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  55. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js +50 -25
  56. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  57. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -22
  58. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  59. package/cjs/domain/rumEventsCollection/view/trackViews.js +1 -1
  60. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  61. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -0
  62. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  63. package/cjs/domain/waitPageActivityEnd.js +6 -5
  64. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  65. package/esm/boot/buildEnv.js +1 -1
  66. package/esm/boot/rum.js +11 -10
  67. package/esm/boot/rum.js.map +1 -1
  68. package/esm/domain/assembly.js.map +1 -1
  69. package/esm/domain/contexts/pageStateHistory.js +5 -2
  70. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  71. package/esm/domain/contexts/urlContexts.js +4 -2
  72. package/esm/domain/contexts/urlContexts.js.map +1 -1
  73. package/esm/domain/contexts/viewContexts.js +10 -2
  74. package/esm/domain/contexts/viewContexts.js.map +1 -1
  75. package/esm/domain/locationChangeObservable.js +7 -5
  76. package/esm/domain/locationChangeObservable.js.map +1 -1
  77. package/esm/domain/performanceCollection.js +41 -89
  78. package/esm/domain/performanceCollection.js.map +1 -1
  79. package/esm/domain/performanceObservable.js +105 -0
  80. package/esm/domain/performanceObservable.js.map +1 -0
  81. package/esm/domain/performanceUtils.js +14 -0
  82. package/esm/domain/performanceUtils.js.map +1 -0
  83. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  84. package/esm/domain/replay/record/observers.js +59 -55
  85. package/esm/domain/replay/record/observers.js.map +1 -1
  86. package/esm/domain/requestCollection.js +6 -2
  87. package/esm/domain/requestCollection.js.map +1 -1
  88. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  89. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  90. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +6 -8
  91. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  92. package/esm/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +5 -5
  93. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -0
  94. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +66 -68
  95. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  96. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +12 -9
  97. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  98. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +35 -0
  99. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -0
  100. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
  101. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  102. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +9 -7
  103. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  104. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  105. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  106. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +1 -1
  107. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  108. package/esm/domain/rumEventsCollection/view/trackFirstInput.js +2 -2
  109. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  110. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  111. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  112. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +2 -19
  113. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  114. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -2
  115. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  116. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +7 -7
  117. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  118. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +51 -26
  119. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  120. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -21
  121. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  122. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  123. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  124. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -0
  125. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  126. package/esm/domain/waitPageActivityEnd.js +7 -7
  127. package/esm/domain/waitPageActivityEnd.js.map +1 -1
  128. package/package.json +4 -4
  129. package/src/boot/rum.js +18 -9
  130. package/src/domain/assembly.js +0 -1
  131. package/src/domain/contexts/pageStateHistory.js +5 -5
  132. package/src/domain/contexts/urlContexts.js +4 -2
  133. package/src/domain/contexts/viewContexts.js +10 -3
  134. package/src/domain/locationChangeObservable.js +17 -7
  135. package/src/domain/performanceCollection.js +55 -138
  136. package/src/domain/performanceObservable.js +148 -0
  137. package/src/domain/performanceUtils.js +16 -0
  138. package/src/domain/replay/record/observers.js +39 -35
  139. package/src/domain/requestCollection.js +6 -2
  140. package/src/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  141. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +7 -8
  142. package/src/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +10 -4
  143. package/src/domain/rumEventsCollection/resource/resourceCollection.js +74 -117
  144. package/src/domain/rumEventsCollection/resource/resourceUtils.js +13 -11
  145. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +45 -0
  146. package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +2 -1
  147. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +24 -7
  148. package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +3 -2
  149. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +1 -1
  150. package/src/domain/rumEventsCollection/view/trackFirstInput.js +3 -3
  151. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  152. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +7 -19
  153. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +4 -3
  154. package/src/domain/rumEventsCollection/view/trackLoadingTime.js +8 -8
  155. package/src/domain/rumEventsCollection/view/trackNavigationTimings.js +66 -32
  156. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -24
  157. package/src/domain/rumEventsCollection/view/trackViews.js +1 -1
  158. package/src/domain/rumEventsCollection/view/viewCollection.js +4 -0
  159. package/src/domain/waitPageActivityEnd.js +16 -17
  160. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
  161. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
@@ -4,11 +4,14 @@ import {
4
4
  round,
5
5
  ONE_SECOND,
6
6
  LifeCycleEventType,
7
- isElementNode
7
+ isElementNode,
8
+ elapsed
8
9
  } from '@cloudcare/browser-core'
9
- import { supportPerformanceTimingEvent } from '../../performanceCollection'
10
10
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
11
-
11
+ import {
12
+ RumPerformanceEntryType,
13
+ supportPerformanceTimingEvent
14
+ } from '../../performanceObservable'
12
15
  /**
13
16
  * Track the cumulative layout shifts (CLS).
14
17
  * Layout shifts are grouped into session windows.
@@ -26,7 +29,12 @@ import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
26
29
  * https://web.dev/evolving-cls/
27
30
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getCLS.ts
28
31
  */
29
- export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
32
+ export function trackCumulativeLayoutShift(
33
+ configuration,
34
+ lifeCycle,
35
+ viewStart,
36
+ callback
37
+ ) {
30
38
  if (!isLayoutShiftSupported()) {
31
39
  return {
32
40
  stop: noop
@@ -36,6 +44,7 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
36
44
  var maxClsValue = 0
37
45
  // WeakRef is not supported in IE11 and Safari mobile, but so is the layout shift API, so this code won't be executed in these browsers
38
46
  var maxClsTarget
47
+ var maxClsStartTime
39
48
 
40
49
  // if no layout shift happen the value should be reported as 0
41
50
  callback({
@@ -47,13 +56,17 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
47
56
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
48
57
  (entries) => {
49
58
  for (var entry of entries) {
50
- if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
59
+ if (
60
+ entry.entryType === RumPerformanceEntryType.LAYOUT_SHIFT &&
61
+ !entry.hadRecentInput
62
+ ) {
51
63
  var _update = window.update(entry)
52
64
  var cumulatedValue = _update.cumulatedValue
53
65
  var isMaxValue = _update.isMaxValue
54
66
  if (isMaxValue) {
55
67
  var target = getTargetFromSource(entry.sources)
56
68
  maxClsTarget = target ? new WeakRef(target) : undefined
69
+ maxClsStartTime = elapsed(viewStart, entry.startTime)
57
70
  }
58
71
 
59
72
  if (cumulatedValue > maxClsValue) {
@@ -67,7 +80,8 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
67
80
  getSelectorFromElement(
68
81
  target,
69
82
  configuration.actionNameAttribute
70
- )
83
+ ),
84
+ time: maxClsStartTime
71
85
  })
72
86
  }
73
87
  }
@@ -128,5 +142,8 @@ function slidingSessionWindow() {
128
142
  * Check whether `layout-shift` is supported by the browser.
129
143
  */
130
144
  export function isLayoutShiftSupported() {
131
- return supportPerformanceTimingEvent('layout-shift')
145
+ return (
146
+ supportPerformanceTimingEvent(RumPerformanceEntryType.LAYOUT_SHIFT) &&
147
+ 'WeakRef' in window
148
+ )
132
149
  }
@@ -1,4 +1,5 @@
1
1
  import { find, LifeCycleEventType, ONE_MINUTE } from '@cloudcare/browser-core'
2
+ import { RumPerformanceEntryType } from '../../performanceObservable'
2
3
  export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE
3
4
  export function trackFirstContentfulPaint(lifeCycle, firstHidden, callback) {
4
5
  var subscribe = lifeCycle.subscribe(
@@ -6,9 +7,9 @@ export function trackFirstContentfulPaint(lifeCycle, firstHidden, callback) {
6
7
  function (entries) {
7
8
  var fcpEntry = find(entries, function (entry) {
8
9
  return (
9
- entry.entryType === 'paint' &&
10
+ entry.entryType === RumPerformanceEntryType.PAINT &&
10
11
  entry.name === 'first-contentful-paint' &&
11
- entry.startTime < firstHidden.geTimeStamp() &&
12
+ entry.startTime < firstHidden.getTimeStamp() &&
12
13
  entry.startTime < TIMING_MAXIMUM_DELAY
13
14
  )
14
15
  })
@@ -27,7 +27,7 @@ export function trackFirstHidden(eventTarget) {
27
27
  }
28
28
 
29
29
  return {
30
- geTimeStamp() {
30
+ getTimeStamp: function () {
31
31
  return timeStamp
32
32
  },
33
33
  stop: function () {
@@ -5,7 +5,7 @@ import {
5
5
  isElementNode
6
6
  } from '@cloudcare/browser-core'
7
7
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
8
-
8
+ import { RumPerformanceEntryType } from '../../performanceObservable'
9
9
  /**
10
10
  * Track the first input occurring during the initial View to return:
11
11
  * - First Input Delay
@@ -25,8 +25,8 @@ export function trackFirstInput(
25
25
  function (entries) {
26
26
  var firstInputEntry = find(entries, function (entry) {
27
27
  return (
28
- entry.entryType === 'first-input' &&
29
- entry.startTime < firstHidden.geTimeStamp()
28
+ entry.entryType === RumPerformanceEntryType.FIRST_INPUT &&
29
+ entry.startTime < firstHidden.getTimeStamp()
30
30
  )
31
31
  })
32
32
  if (firstInputEntry) {
@@ -14,7 +14,7 @@ export function trackInitialViewMetrics(
14
14
  ) {
15
15
  var initialViewMetrics = {}
16
16
  var _trackNavigationTimings = trackNavigationTimings(
17
- lifeCycle,
17
+ configuration,
18
18
  function (navigationTimings) {
19
19
  setLoadEvent(navigationTimings.loadEvent)
20
20
  initialViewMetrics.navigationTimings = navigationTimings
@@ -7,13 +7,15 @@ import {
7
7
  elapsed,
8
8
  isElementNode
9
9
  } from '@cloudcare/browser-core'
10
- import { supportPerformanceTimingEvent } from '../../performanceCollection'
11
10
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
12
11
  import {
13
12
  getInteractionCount,
14
13
  initInteractionCountPolyfill
15
14
  } from './interactionCountPolyfill'
16
-
15
+ import {
16
+ RumPerformanceEntryType,
17
+ supportPerformanceTimingEvent
18
+ } from '../../performanceObservable'
17
19
  // Arbitrary value to prevent unnecessary memory usage on views with lots of interactions.
18
20
  var MAX_INTERACTION_ENTRIES = 10
19
21
 
@@ -57,7 +59,8 @@ export function trackInteractionToNextPaint(
57
59
  function (entries) {
58
60
  for (var entry of entries) {
59
61
  if (
60
- (entry.entryType === 'event' || entry.entryType === 'first-input') &&
62
+ (entry.entryType === RumPerformanceEntryType.EVENT ||
63
+ entry.entryType === RumPerformanceEntryType.FIRST_INPUT) &&
61
64
  entry.interactionId &&
62
65
  entry.startTime >= viewStart &&
63
66
  entry.startTime <= viewEnd
@@ -72,22 +75,7 @@ export function trackInteractionToNextPaint(
72
75
  newInteraction.duration !== interactionToNextPaint
73
76
  ) {
74
77
  interactionToNextPaint = newInteraction.duration
75
- // if (interactionToNextPaint > 10 * ONE_MINUTE && !telemetryCollected) {
76
- // telemetryCollected = true
77
- // addTelemetryDebug('INP outlier', {
78
- // inp: interactionToNextPaint,
79
- // interaction: {
80
- // timeFromViewStart: elapsed(viewStart, newInteraction.startTime),
81
- // duration: newInteraction.duration,
82
- // startTime: newInteraction.startTime,
83
- // processingStart: newInteraction.processingStart,
84
- // processingEnd: newInteraction.processingEnd,
85
- // interactionId: newInteraction.interactionId,
86
- // name: newInteraction.name,
87
- // targetNodeName: newInteraction.target?.nodeName
88
- // }
89
- // })
90
- // }
78
+
91
79
  if (newInteraction.target && isElementNode(newInteraction.target)) {
92
80
  interactionToNextPaintTargetSelector = getSelectorFromElement(
93
81
  newInteraction.target,
@@ -6,7 +6,7 @@ import {
6
6
  ONE_MINUTE
7
7
  } from '@cloudcare/browser-core'
8
8
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
9
-
9
+ import { RumPerformanceEntryType } from '../../performanceObservable'
10
10
  /**
11
11
  * Track the largest contentful paint (LCP) occurring during the initial View. This can yield
12
12
  * multiple values, only the most recent one should be used.
@@ -41,9 +41,10 @@ export function trackLargestContentfulPaint(
41
41
  function (entries) {
42
42
  var lcpEntry = findLast(entries, function (entry) {
43
43
  return (
44
- entry.entryType === 'largest-contentful-paint' &&
44
+ entry.entryType ===
45
+ RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT &&
45
46
  entry.startTime < firstInteractionTimestamp &&
46
- entry.startTime < firstHidden.geTimeStamp() &&
47
+ entry.startTime < firstHidden.getTimeStamp() &&
47
48
  entry.startTime < LCP_MAXIMUM_DELAY &&
48
49
  // Ensure to get the LCP entry with the biggest size, see
49
50
  // https://bugs.chromium.org/p/chromium/issues/detail?id=1516655
@@ -1,5 +1,6 @@
1
1
  import { elapsed, ViewLoadingType } from '@cloudcare/browser-core'
2
2
  import { waitPageActivityEnd } from '../../waitPageActivityEnd'
3
+ import { trackFirstHidden } from './trackFirstHidden'
3
4
  export function trackLoadingTime(
4
5
  lifeCycle,
5
6
  domMutationObservable,
@@ -11,21 +12,20 @@ export function trackLoadingTime(
11
12
  var isWaitingForLoadEvent = loadType === ViewLoadingType.INITIAL_LOAD
12
13
  var isWaitingForActivityLoadingTime = true
13
14
  var loadingTimeCandidates = []
14
-
15
+ var firstHidden = trackFirstHidden()
15
16
  function invokeCallbackIfAllCandidatesAreReceived() {
16
17
  if (
17
18
  !isWaitingForActivityLoadingTime &&
18
19
  !isWaitingForLoadEvent &&
19
20
  loadingTimeCandidates.length > 0
20
21
  ) {
21
- callback(Math.max.apply(Math, loadingTimeCandidates))
22
- }
23
- }
24
- function stopEndCallback() {
25
- if (loadingTimeCandidates.length > 0) {
26
- callback(Math.max.apply(Math, loadingTimeCandidates))
22
+ var loadingTime = Math.max.apply(Math, loadingTimeCandidates)
23
+ if (loadingTime < firstHidden.getTimeStamp()) {
24
+ callback(loadingTime)
25
+ }
27
26
  }
28
27
  }
28
+
29
29
  var _waitPageActivityEnd = waitPageActivityEnd(
30
30
  lifeCycle,
31
31
  domMutationObservable,
@@ -52,7 +52,7 @@ export function trackLoadingTime(
52
52
  },
53
53
  stop: function () {
54
54
  stop()
55
- stopEndCallback()
55
+ firstHidden.stop()
56
56
  }
57
57
  }
58
58
  }
@@ -1,35 +1,69 @@
1
- import { LifeCycleEventType, relativeNow } from '@cloudcare/browser-core'
2
- export function trackNavigationTimings(lifeCycle, callback) {
3
- var subscribe = lifeCycle.subscribe(
4
- LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
5
- function (entries) {
6
- for (var i = 0; i < entries.length; i++) {
7
- var entry = entries[i]
8
- if (entry.entryType === 'navigation') {
9
- callback({
10
- fetchStart: entry.fetchStart,
11
- responseEnd: entry.responseEnd,
12
- domComplete: entry.domComplete,
13
- domContentLoaded: entry.domContentLoadedEventEnd,
14
- domInteractive: entry.domInteractive,
15
- loadEvent: entry.loadEventEnd,
16
- loadEventEnd: entry.loadEventEnd,
17
- loadEventStart: entry.loadEventStart,
18
- domContentLoadedEventEnd: entry.domContentLoadedEventEnd,
19
- domContentLoadedEventStart: entry.domContentLoadedEventStart,
20
- // In some cases the value reported is negative or is larger
21
- // than the current page time. Ignore these cases:
22
- // https://github.com/GoogleChrome/web-vitals/issues/137
23
- // https://github.com/GoogleChrome/web-vitals/issues/162
24
- firstByte:
25
- entry.responseStart >= 0 && entry.responseStart <= relativeNow()
26
- ? entry.responseStart
27
- : undefined
28
- })
29
- }
30
- }
1
+ import {
2
+ relativeNow,
3
+ each,
4
+ setTimeout,
5
+ noop,
6
+ runOnReadyState
7
+ } from '@cloudcare/browser-core'
8
+ import {
9
+ createPerformanceObservable,
10
+ RumPerformanceEntryType,
11
+ supportPerformanceTimingEvent
12
+ } from '../../performanceObservable'
13
+ import { computeRelativePerformanceTiming } from '../../performanceUtils'
14
+ export function trackNavigationTimings(configuration, callback) {
15
+ var processEntry = function (entry) {
16
+ if (!isIncompleteNavigation(entry)) {
17
+ callback(processNavigationEntry(entry))
31
18
  }
32
- )
19
+ }
20
+ var stop = noop
21
+ if (supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
22
+ var subscribe = createPerformanceObservable(configuration, {
23
+ type: RumPerformanceEntryType.NAVIGATION,
24
+ buffered: true
25
+ }).subscribe(function (entries) {
26
+ return each(entries, processEntry)
27
+ })
28
+ stop = subscribe.unsubscribe
29
+ } else {
30
+ retrieveNavigationTiming(configuration, processEntry)
31
+ }
33
32
 
34
- return { stop: subscribe.unsubscribe }
33
+ return { stop: stop }
34
+ }
35
+ function processNavigationEntry(entry) {
36
+ return {
37
+ fetchStart: entry.fetchStart,
38
+ responseEnd: entry.responseEnd,
39
+ domComplete: entry.domComplete,
40
+ domContentLoaded: entry.domContentLoadedEventEnd,
41
+ domInteractive: entry.domInteractive,
42
+ loadEvent: entry.loadEventEnd,
43
+ loadEventEnd: entry.loadEventEnd,
44
+ loadEventStart: entry.loadEventStart,
45
+ domContentLoadedEventEnd: entry.domContentLoadedEventEnd,
46
+ domContentLoadedEventStart: entry.domContentLoadedEventStart,
47
+ // In some cases the value reported is negative or is larger
48
+ // than the current page time. Ignore these cases:
49
+ // https://github.com/GoogleChrome/web-vitals/issues/137
50
+ // https://github.com/GoogleChrome/web-vitals/issues/162
51
+ firstByte:
52
+ entry.responseStart >= 0 && entry.responseStart <= relativeNow()
53
+ ? entry.responseStart
54
+ : undefined
55
+ }
56
+ }
57
+
58
+ function isIncompleteNavigation(entry) {
59
+ return entry.loadEventEnd <= 0
60
+ }
61
+
62
+ function retrieveNavigationTiming(configuration, callback) {
63
+ runOnReadyState('complete', function () {
64
+ // Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
65
+ setTimeout(function () {
66
+ callback(computeRelativePerformanceTiming())
67
+ })
68
+ })
35
69
  }
@@ -1,23 +1,5 @@
1
- import { ONE_MINUTE, setTimeout } from '@cloudcare/browser-core'
2
1
  import { trackEventCounts } from '../../trackEventCounts'
3
2
 
4
- // Some events are not being counted as they transcend views. To reduce the occurrence;
5
- // an arbitrary delay is added for stopping event counting after the view ends.
6
- //
7
- // Ideally, we would not stop and keep counting events until the end of the session.
8
- // But this might have a small performance impact if there are many many views:
9
- // we would need to go through each event to see if the related view matches.
10
- // So let's have a fairly short delay to avoid impacting performances too much.
11
- //
12
- // In the future, we could have views stored in a data structure similar to ContextHistory. Whenever
13
- // a child event is collected, we could look into this history to find the matching view and
14
- // increase the associated and increase its counter. Having a centralized data structure for it
15
- // would allow us to look for views more efficiently.
16
- //
17
- // For now, having a small cleanup delay will already improve the situation in most cases.
18
-
19
- export var KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
20
-
21
3
  export function trackViewEventCounts(lifeCycle, viewId, onChange) {
22
4
  var _trackEventCounts = trackEventCounts({
23
5
  lifeCycle: lifeCycle,
@@ -27,12 +9,7 @@ export function trackViewEventCounts(lifeCycle, viewId, onChange) {
27
9
  onChange: onChange
28
10
  })
29
11
  return {
30
- scheduleStop: function () {
31
- setTimeout(
32
- _trackEventCounts.stop,
33
- KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY
34
- )
35
- },
12
+ stop: _trackEventCounts.stop,
36
13
  eventCounts: _trackEventCounts.eventCounts
37
14
  }
38
15
  }
@@ -209,7 +209,7 @@ function newView(
209
209
  id,
210
210
  scheduleViewUpdate
211
211
  )
212
- var stopEventCountsTracking = _trackViewEventCounts.scheduleStop
212
+ var stopEventCountsTracking = _trackViewEventCounts.stop
213
213
  var eventCounts = _trackViewEventCounts.eventCounts
214
214
 
215
215
  // Session keep alive
@@ -125,6 +125,10 @@ function processViewUpdate(view, configuration, recorderApi, pageStateHistory) {
125
125
  view.commonViewMetrics,
126
126
  'cumulativeLayoutShift.value'
127
127
  ),
128
+ cumulative_layout_shift_time: findByPath(
129
+ view.commonViewMetrics,
130
+ 'cumulativeLayoutShift.time'
131
+ ),
128
132
  cumulative_layout_shift_target_selector: findByPath(
129
133
  view.commonViewMetrics,
130
134
  'cumulativeLayoutShift.targetSelector'
@@ -5,11 +5,14 @@ import {
5
5
  LifeCycleEventType,
6
6
  some,
7
7
  matchList,
8
- instrumentMethodAndCallOriginal,
8
+ instrumentMethod,
9
9
  setTimeout,
10
10
  clearTimeout
11
11
  } from '@cloudcare/browser-core'
12
-
12
+ import {
13
+ createPerformanceObservable,
14
+ RumPerformanceEntryType
15
+ } from '../domain/performanceObservable'
13
16
  // Delay to wait for a page activity to validate the tracking process
14
17
  export var PAGE_ACTIVITY_VALIDATION_DELAY = 100
15
18
  // Delay to wait after a page activity to end the tracking process
@@ -127,21 +130,17 @@ export function createPageActivityObservable(
127
130
 
128
131
  subscriptions.push(
129
132
  domMutationObservable.subscribe(notifyPageActivity),
130
- lifeCycle.subscribe(
131
- LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
132
- function (entries) {
133
- if (
134
- some(entries, function (entry) {
135
- return (
136
- entry.entryType === 'resource' &&
137
- !isExcludedUrl(configuration, entry.name)
138
- )
139
- })
140
- ) {
141
- notifyPageActivity()
142
- }
133
+ createPerformanceObservable(configuration, {
134
+ type: RumPerformanceEntryType.RESOURCE
135
+ }).subscribe(function (entries) {
136
+ if (
137
+ some(entries, function (entry) {
138
+ return !isExcludedUrl(configuration, entry.name)
139
+ })
140
+ ) {
141
+ notifyPageActivity()
143
142
  }
144
- ),
143
+ }),
145
144
  lifeCycle.subscribe(
146
145
  LifeCycleEventType.REQUEST_STARTED,
147
146
  function (startEvent) {
@@ -193,5 +192,5 @@ function isExcludedUrl(configuration, requestUrl) {
193
192
  }
194
193
 
195
194
  function trackWindowOpen(callback) {
196
- return instrumentMethodAndCallOriginal(window, 'open', { before: callback })
195
+ return instrumentMethod(window, 'open', callback)
197
196
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"matchRequestTiming.js","names":["_resourceUtils","require","_browserCore","alreadyMatchedEntries","WeakSet","matchRequestTiming","request","performance","sameNameEntries","getEntriesByName","url","length","candidates","filter","entry","has","isValidEntry","isBetween","startClocks","relative","endTime","startTime","duration","add","toJSON","timing","addDuration","start","end","errorMargin"],"sources":["../../../../src/domain/rumEventsCollection/resource/matchRequestTiming.js"],"sourcesContent":["import { isValidEntry } from './resourceUtils'\nimport { map, filter, addDuration, WeakSet } from '@cloudcare/browser-core'\n\nvar alreadyMatchedEntries = new WeakSet()\n/**\n * Look for corresponding timing in resource timing buffer\n *\n * Observations:\n * - Timing (start, end) are nested inside the request (start, end)\n * - Browsers generate a timing entry for OPTIONS request\n *\n * Strategy:\n * - from valid nested entries\n * - if a single timing match, return the timing\n * - if two following timings match (OPTIONS request), return the timing for the actual request\n * - otherwise we can't decide, return undefined\n */\nexport function matchRequestTiming(request) {\n if (!performance || !('getEntriesByName' in performance)) {\n return\n }\n var sameNameEntries = performance.getEntriesByName(request.url, 'resource')\n\n if (!sameNameEntries.length || !('toJSON' in sameNameEntries[0])) {\n return\n }\n var candidates = filter(sameNameEntries, function (entry) {\n return !alreadyMatchedEntries.has(entry)\n })\n\n candidates = filter(candidates, function (entry) {\n return isValidEntry(entry)\n })\n candidates = filter(candidates, function (entry) {\n return isBetween(\n entry,\n request.startClocks.relative,\n endTime({\n startTime: request.startClocks.relative,\n duration: request.duration\n })\n )\n })\n\n if (candidates.length === 1) {\n alreadyMatchedEntries.add(candidates[0])\n return candidates[0].toJSON()\n }\n return\n}\n\nfunction endTime(timing) {\n return addDuration(timing.startTime, timing.duration)\n}\n\nfunction isBetween(timing, start, end) {\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n var errorMargin = 1\n return (\n timing.startTime >= start - errorMargin &&\n endTime(timing) <= addDuration(end, errorMargin)\n )\n}\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAIE,qBAAqB,GAAG,IAAIC,oBAAO,CAAC,CAAC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAACC,OAAO,EAAE;EAC1C,IAAI,CAACC,WAAW,IAAI,EAAE,kBAAkB,IAAIA,WAAW,CAAC,EAAE;IACxD;EACF;EACA,IAAIC,eAAe,GAAGD,WAAW,CAACE,gBAAgB,CAACH,OAAO,CAACI,GAAG,EAAE,UAAU,CAAC;EAE3E,IAAI,CAACF,eAAe,CAACG,MAAM,IAAI,EAAE,QAAQ,IAAIH,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE;IAChE;EACF;EACA,IAAII,UAAU,GAAG,IAAAC,mBAAM,EAACL,eAAe,EAAE,UAAUM,KAAK,EAAE;IACxD,OAAO,CAACX,qBAAqB,CAACY,GAAG,CAACD,KAAK,CAAC;EAC1C,CAAC,CAAC;EAEFF,UAAU,GAAG,IAAAC,mBAAM,EAACD,UAAU,EAAE,UAAUE,KAAK,EAAE;IAC/C,OAAO,IAAAE,2BAAY,EAACF,KAAK,CAAC;EAC5B,CAAC,CAAC;EACFF,UAAU,GAAG,IAAAC,mBAAM,EAACD,UAAU,EAAE,UAAUE,KAAK,EAAE;IAC/C,OAAOG,SAAS,CACdH,KAAK,EACLR,OAAO,CAACY,WAAW,CAACC,QAAQ,EAC5BC,OAAO,CAAC;MACNC,SAAS,EAAEf,OAAO,CAACY,WAAW,CAACC,QAAQ;MACvCG,QAAQ,EAAEhB,OAAO,CAACgB;IACpB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;EAEF,IAAIV,UAAU,CAACD,MAAM,KAAK,CAAC,EAAE;IAC3BR,qBAAqB,CAACoB,GAAG,CAACX,UAAU,CAAC,CAAC,CAAC,CAAC;IACxC,OAAOA,UAAU,CAAC,CAAC,CAAC,CAACY,MAAM,CAAC,CAAC;EAC/B;EACA;AACF;AAEA,SAASJ,OAAOA,CAACK,MAAM,EAAE;EACvB,OAAO,IAAAC,wBAAW,EAACD,MAAM,CAACJ,SAAS,EAAEI,MAAM,CAACH,QAAQ,CAAC;AACvD;AAEA,SAASL,SAASA,CAACQ,MAAM,EAAEE,KAAK,EAAEC,GAAG,EAAE;EACrC;EACA,IAAIC,WAAW,GAAG,CAAC;EACnB,OACEJ,MAAM,CAACJ,SAAS,IAAIM,KAAK,GAAGE,WAAW,IACvCT,OAAO,CAACK,MAAM,CAAC,IAAI,IAAAC,wBAAW,EAACE,GAAG,EAAEC,WAAW,CAAC;AAEpD","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"matchRequestTiming.js","names":["isValidEntry","map","filter","addDuration","WeakSet","alreadyMatchedEntries","matchRequestTiming","request","performance","sameNameEntries","getEntriesByName","url","length","candidates","entry","has","isBetween","startClocks","relative","endTime","startTime","duration","add","toJSON","timing","start","end","errorMargin"],"sources":["../../../../src/domain/rumEventsCollection/resource/matchRequestTiming.js"],"sourcesContent":["import { isValidEntry } from './resourceUtils'\nimport { map, filter, addDuration, WeakSet } from '@cloudcare/browser-core'\n\nvar alreadyMatchedEntries = new WeakSet()\n/**\n * Look for corresponding timing in resource timing buffer\n *\n * Observations:\n * - Timing (start, end) are nested inside the request (start, end)\n * - Browsers generate a timing entry for OPTIONS request\n *\n * Strategy:\n * - from valid nested entries\n * - if a single timing match, return the timing\n * - if two following timings match (OPTIONS request), return the timing for the actual request\n * - otherwise we can't decide, return undefined\n */\nexport function matchRequestTiming(request) {\n if (!performance || !('getEntriesByName' in performance)) {\n return\n }\n var sameNameEntries = performance.getEntriesByName(request.url, 'resource')\n\n if (!sameNameEntries.length || !('toJSON' in sameNameEntries[0])) {\n return\n }\n var candidates = filter(sameNameEntries, function (entry) {\n return !alreadyMatchedEntries.has(entry)\n })\n\n candidates = filter(candidates, function (entry) {\n return isValidEntry(entry)\n })\n candidates = filter(candidates, function (entry) {\n return isBetween(\n entry,\n request.startClocks.relative,\n endTime({\n startTime: request.startClocks.relative,\n duration: request.duration\n })\n )\n })\n\n if (candidates.length === 1) {\n alreadyMatchedEntries.add(candidates[0])\n return candidates[0].toJSON()\n }\n return\n}\n\nfunction endTime(timing) {\n return addDuration(timing.startTime, timing.duration)\n}\n\nfunction isBetween(timing, start, end) {\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n var errorMargin = 1\n return (\n timing.startTime >= start - errorMargin &&\n endTime(timing) <= addDuration(end, errorMargin)\n )\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAQ,yBAAyB;AAE3E,IAAIC,qBAAqB,GAAG,IAAID,OAAO,CAAC,CAAC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,kBAAkBA,CAACC,OAAO,EAAE;EAC1C,IAAI,CAACC,WAAW,IAAI,EAAE,kBAAkB,IAAIA,WAAW,CAAC,EAAE;IACxD;EACF;EACA,IAAIC,eAAe,GAAGD,WAAW,CAACE,gBAAgB,CAACH,OAAO,CAACI,GAAG,EAAE,UAAU,CAAC;EAE3E,IAAI,CAACF,eAAe,CAACG,MAAM,IAAI,EAAE,QAAQ,IAAIH,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE;IAChE;EACF;EACA,IAAII,UAAU,GAAGX,MAAM,CAACO,eAAe,EAAE,UAAUK,KAAK,EAAE;IACxD,OAAO,CAACT,qBAAqB,CAACU,GAAG,CAACD,KAAK,CAAC;EAC1C,CAAC,CAAC;EAEFD,UAAU,GAAGX,MAAM,CAACW,UAAU,EAAE,UAAUC,KAAK,EAAE;IAC/C,OAAOd,YAAY,CAACc,KAAK,CAAC;EAC5B,CAAC,CAAC;EACFD,UAAU,GAAGX,MAAM,CAACW,UAAU,EAAE,UAAUC,KAAK,EAAE;IAC/C,OAAOE,SAAS,CACdF,KAAK,EACLP,OAAO,CAACU,WAAW,CAACC,QAAQ,EAC5BC,OAAO,CAAC;MACNC,SAAS,EAAEb,OAAO,CAACU,WAAW,CAACC,QAAQ;MACvCG,QAAQ,EAAEd,OAAO,CAACc;IACpB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;EAEF,IAAIR,UAAU,CAACD,MAAM,KAAK,CAAC,EAAE;IAC3BP,qBAAqB,CAACiB,GAAG,CAACT,UAAU,CAAC,CAAC,CAAC,CAAC;IACxC,OAAOA,UAAU,CAAC,CAAC,CAAC,CAACU,MAAM,CAAC,CAAC;EAC/B;EACA;AACF;AAEA,SAASJ,OAAOA,CAACK,MAAM,EAAE;EACvB,OAAOrB,WAAW,CAACqB,MAAM,CAACJ,SAAS,EAAEI,MAAM,CAACH,QAAQ,CAAC;AACvD;AAEA,SAASL,SAASA,CAACQ,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAE;EACrC;EACA,IAAIC,WAAW,GAAG,CAAC;EACnB,OACEH,MAAM,CAACJ,SAAS,IAAIK,KAAK,GAAGE,WAAW,IACvCR,OAAO,CAACK,MAAM,CAAC,IAAIrB,WAAW,CAACuB,GAAG,EAAEC,WAAW,CAAC;AAEpD","ignoreList":[]}