@cloudcare/browser-rum 2.2.9 → 2.2.11

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 (22) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +10 -25
  4. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +5 -20
  5. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +24 -39
  6. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +4 -19
  7. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +16 -31
  8. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +7 -22
  9. package/esm/boot/buildEnv.js +1 -1
  10. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +2 -1
  11. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +2 -1
  12. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +3 -1
  13. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +3 -1
  14. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +3 -1
  15. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +3 -1
  16. package/package.json +3 -3
  17. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +48 -19
  18. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +52 -21
  19. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +4 -4
  20. package/src/domain/rumEventsCollection/resource/resourceCollection.js +2 -1
  21. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +29 -28
  22. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +56 -29
@@ -60,7 +60,8 @@ export function trackNavigationTimings(lifeCycle, callback) {
60
60
  var subscribe = lifeCycle.subscribe(
61
61
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
62
62
  function (entries) {
63
- for (var entry of entries) {
63
+ for (var i = 0; i < entries.length; i++) {
64
+ var entry = entries[i]
64
65
  if (entry.entryType === 'navigation') {
65
66
  callback({
66
67
  fetchStart: entry.fetchStart,
@@ -76,7 +77,6 @@ export function trackNavigationTimings(lifeCycle, callback) {
76
77
  })
77
78
  }
78
79
  }
79
-
80
80
  }
81
81
  )
82
82
 
@@ -88,18 +88,17 @@ export function trackFirstContentfulPaint(lifeCycle, callback) {
88
88
  var subscribe = lifeCycle.subscribe(
89
89
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
90
90
  function (entries) {
91
- var fcpEntry = find(
92
- entries,
93
- function(entry) {
94
- return entry.entryType === 'paint' &&
95
- entry.name === 'first-contentful-paint' &&
96
- entry.startTime < firstHidden.timeStamp &&
97
- entry.startTime < TIMING_MAXIMUM_DELAY
98
- }
91
+ var fcpEntry = find(entries, function (entry) {
92
+ return (
93
+ entry.entryType === 'paint' &&
94
+ entry.name === 'first-contentful-paint' &&
95
+ entry.startTime < firstHidden.timeStamp &&
96
+ entry.startTime < TIMING_MAXIMUM_DELAY
99
97
  )
100
- if (fcpEntry) {
101
- callback(fcpEntry.startTime)
102
- }
98
+ })
99
+ if (fcpEntry) {
100
+ callback(fcpEntry.startTime)
101
+ }
103
102
  }
104
103
  )
105
104
  return { stop: subscribe.unsubscribe }
@@ -130,15 +129,14 @@ export function trackLargestContentfulPaint(lifeCycle, emitter, callback) {
130
129
  var subscribe = lifeCycle.subscribe(
131
130
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
132
131
  function (entries) {
133
- var lcpEntry = findLast(
134
- entries,
135
- function(entry) {
136
- return entry.entryType === 'largest-contentful-paint' &&
132
+ var lcpEntry = findLast(entries, function (entry) {
133
+ return (
134
+ entry.entryType === 'largest-contentful-paint' &&
137
135
  entry.startTime < firstInteractionTimestamp &&
138
136
  entry.startTime < firstHidden.timeStamp &&
139
137
  entry.startTime < TIMING_MAXIMUM_DELAY
140
- }
141
- )
138
+ )
139
+ })
142
140
  if (lcpEntry) {
143
141
  callback(lcpEntry.startTime)
144
142
  }
@@ -166,20 +164,23 @@ export function trackFirstInputTimings(lifeCycle, callback) {
166
164
  var firstHidden = trackFirstHidden()
167
165
  var subscribe = lifeCycle.subscribe(
168
166
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
169
- function(entries) {
170
- var firstInputEntry = find(
171
- entries,
172
- function(entry) {
173
- return entry.entryType === 'first-input' && entry.startTime < firstHidden.timeStamp
174
- }
175
- )
167
+ function (entries) {
168
+ var firstInputEntry = find(entries, function (entry) {
169
+ return (
170
+ entry.entryType === 'first-input' &&
171
+ entry.startTime < firstHidden.timeStamp
172
+ )
173
+ })
176
174
  if (firstInputEntry) {
177
- var firstInputDelay = elapsed(firstInputEntry.startTime, firstInputEntry.processingStart)
175
+ var firstInputDelay = elapsed(
176
+ firstInputEntry.startTime,
177
+ firstInputEntry.processingStart
178
+ )
178
179
  callback({
179
180
  // Ensure firstInputDelay to be positive, see
180
181
  // https://bugs.chromium.org/p/chromium/issues/detail?id=1185815
181
182
  firstInputDelay: firstInputDelay >= 0 ? firstInputDelay : 0,
182
- firstInputTime: firstInputEntry.startTime,
183
+ firstInputTime: firstInputEntry.startTime
183
184
  })
184
185
  }
185
186
  }
@@ -9,7 +9,14 @@ import {
9
9
  import { supportPerformanceTimingEvent } from '../../performanceCollection'
10
10
  import { trackEventCounts } from '../../trackEventCounts'
11
11
  import { waitPageActivityEnd } from '../../waitPageActivityEnd'
12
- export function trackViewMetrics(lifeCycle,domMutationObservable, configuration, scheduleViewUpdate, loadingType, viewStart) {
12
+ export function trackViewMetrics(
13
+ lifeCycle,
14
+ domMutationObservable,
15
+ configuration,
16
+ scheduleViewUpdate,
17
+ loadingType,
18
+ viewStart
19
+ ) {
13
20
  var viewMetrics = {
14
21
  eventCounts: {
15
22
  errorCount: 0,
@@ -34,7 +41,7 @@ export function trackViewMetrics(lifeCycle,domMutationObservable, configuration,
34
41
  configuration,
35
42
  loadingType,
36
43
  viewStart,
37
- function(newLoadingTime) {
44
+ function (newLoadingTime) {
38
45
  viewMetrics.loadingTime = newLoadingTime
39
46
  scheduleViewUpdate()
40
47
  }
@@ -44,10 +51,13 @@ export function trackViewMetrics(lifeCycle,domMutationObservable, configuration,
44
51
  var stopCLSTracking
45
52
  if (isLayoutShiftSupported()) {
46
53
  viewMetrics.cumulativeLayoutShift = 0
47
- var _trackLayoutShift = trackCumulativeLayoutShift(lifeCycle, function (cumulativeLayoutShift) {
48
- viewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
49
- scheduleViewUpdate()
50
- })
54
+ var _trackLayoutShift = trackCumulativeLayoutShift(
55
+ lifeCycle,
56
+ function (cumulativeLayoutShift) {
57
+ viewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
58
+ scheduleViewUpdate()
59
+ }
60
+ )
51
61
  stopCLSTracking = _trackLayoutShift.stop
52
62
  } else {
53
63
  stopCLSTracking = noop
@@ -63,31 +73,42 @@ export function trackViewMetrics(lifeCycle,domMutationObservable, configuration,
63
73
  }
64
74
  }
65
75
 
66
- function trackLoadingTime(lifeCycle,
76
+ function trackLoadingTime(
77
+ lifeCycle,
67
78
  domMutationObservable,
68
79
  configuration,
69
80
  loadType,
70
81
  viewStart,
71
- callback) {
72
- var isWaitingForLoadEvent = loadType === ViewLoadingType.INITIAL_LOAD
82
+ callback
83
+ ) {
84
+ var isWaitingForLoadEvent = loadType === ViewLoadingType.INITIAL_LOAD
73
85
  var isWaitingForActivityLoadingTime = true
74
86
  var loadingTimeCandidates = []
75
87
 
76
88
  function invokeCallbackIfAllCandidatesAreReceived() {
77
- if (!isWaitingForActivityLoadingTime && !isWaitingForLoadEvent && loadingTimeCandidates.length > 0) {
89
+ if (
90
+ !isWaitingForActivityLoadingTime &&
91
+ !isWaitingForLoadEvent &&
92
+ loadingTimeCandidates.length > 0
93
+ ) {
78
94
  callback(Math.max.apply(Math, loadingTimeCandidates))
79
95
  }
80
96
  }
81
97
 
82
- var _waitPageActivityEnd = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function(event) {
83
- if (isWaitingForActivityLoadingTime) {
84
- isWaitingForActivityLoadingTime = false
85
- if (event.hadActivity) {
86
- loadingTimeCandidates.push(elapsed(viewStart.timeStamp, event.end))
98
+ var _waitPageActivityEnd = waitPageActivityEnd(
99
+ lifeCycle,
100
+ domMutationObservable,
101
+ configuration,
102
+ function (event) {
103
+ if (isWaitingForActivityLoadingTime) {
104
+ isWaitingForActivityLoadingTime = false
105
+ if (event.hadActivity) {
106
+ loadingTimeCandidates.push(elapsed(viewStart.timeStamp, event.end))
107
+ }
108
+ invokeCallbackIfAllCandidatesAreReceived()
87
109
  }
88
- invokeCallbackIfAllCandidatesAreReceived()
89
110
  }
90
- })
111
+ )
91
112
  var stop = _waitPageActivityEnd.stop
92
113
  return {
93
114
  setLoadEvent: function (loadEvent) {
@@ -118,23 +139,27 @@ function trackLoadingTime(lifeCycle,
118
139
  * https://web.dev/evolving-cls/
119
140
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getCLS.ts
120
141
  */
121
- function trackCumulativeLayoutShift(lifeCycle, callback) {
142
+ function trackCumulativeLayoutShift(lifeCycle, callback) {
122
143
  var maxClsValue = 0
123
144
  var window = slidingSessionWindow()
124
- var _subscribe = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, function(entries){
125
- for (var entry of entries) {
126
- if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
127
- window.update(entry)
128
- if (window.value() > maxClsValue) {
129
- maxClsValue = window.value()
130
- callback(round(maxClsValue, 4))
145
+ var _subscribe = lifeCycle.subscribe(
146
+ LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
147
+ function (entries) {
148
+ for (var i = 0; i < entries.length; i++) {
149
+ var entry = entries[i]
150
+ if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
151
+ window.update(entry)
152
+ if (window.value() > maxClsValue) {
153
+ maxClsValue = window.value()
154
+ callback(round(maxClsValue, 4))
155
+ }
131
156
  }
132
157
  }
133
158
  }
134
- })
159
+ )
135
160
  var stop = _subscribe.unsubscribe
136
161
  return {
137
- stop:stop
162
+ stop: stop
138
163
  }
139
164
  }
140
165
 
@@ -143,7 +168,7 @@ function slidingSessionWindow() {
143
168
  var startTime
144
169
  var endTime
145
170
  return {
146
- update: function(entry) {
171
+ update: function (entry) {
147
172
  var shouldCreateNewWindow =
148
173
  startTime === undefined ||
149
174
  entry.startTime - endTime >= ONE_SECOND ||
@@ -156,7 +181,9 @@ function slidingSessionWindow() {
156
181
  endTime = entry.startTime
157
182
  }
158
183
  },
159
- value: function() {return value}
184
+ value: function () {
185
+ return value
186
+ }
160
187
  }
161
188
  }
162
189