@cloudcare/browser-rum 3.1.19 → 3.1.20

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 (151) 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/trackFirstInput.js +2 -1
  44. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  45. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  46. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  47. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +3 -19
  48. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  49. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -1
  50. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  51. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js +49 -25
  52. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  53. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -22
  54. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  55. package/cjs/domain/rumEventsCollection/view/trackViews.js +1 -1
  56. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  57. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -0
  58. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  59. package/cjs/domain/waitPageActivityEnd.js +6 -5
  60. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  61. package/esm/boot/buildEnv.js +1 -1
  62. package/esm/boot/rum.js +11 -10
  63. package/esm/boot/rum.js.map +1 -1
  64. package/esm/domain/assembly.js.map +1 -1
  65. package/esm/domain/contexts/pageStateHistory.js +5 -2
  66. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  67. package/esm/domain/contexts/urlContexts.js +4 -2
  68. package/esm/domain/contexts/urlContexts.js.map +1 -1
  69. package/esm/domain/contexts/viewContexts.js +10 -2
  70. package/esm/domain/contexts/viewContexts.js.map +1 -1
  71. package/esm/domain/locationChangeObservable.js +7 -5
  72. package/esm/domain/locationChangeObservable.js.map +1 -1
  73. package/esm/domain/performanceCollection.js +41 -89
  74. package/esm/domain/performanceCollection.js.map +1 -1
  75. package/esm/domain/performanceObservable.js +105 -0
  76. package/esm/domain/performanceObservable.js.map +1 -0
  77. package/esm/domain/performanceUtils.js +14 -0
  78. package/esm/domain/performanceUtils.js.map +1 -0
  79. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  80. package/esm/domain/replay/record/observers.js +59 -55
  81. package/esm/domain/replay/record/observers.js.map +1 -1
  82. package/esm/domain/requestCollection.js +6 -2
  83. package/esm/domain/requestCollection.js.map +1 -1
  84. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  85. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  86. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +6 -8
  87. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  88. package/esm/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +5 -5
  89. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -0
  90. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +66 -68
  91. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  92. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +12 -9
  93. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  94. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +35 -0
  95. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -0
  96. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
  97. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  98. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +9 -7
  99. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  100. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  101. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  102. package/esm/domain/rumEventsCollection/view/trackFirstInput.js +2 -2
  103. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  104. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  105. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  106. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +2 -19
  107. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  108. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -2
  109. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  110. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +50 -26
  111. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  112. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -21
  113. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  114. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  115. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  116. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -0
  117. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  118. package/esm/domain/waitPageActivityEnd.js +7 -7
  119. package/esm/domain/waitPageActivityEnd.js.map +1 -1
  120. package/package.json +4 -4
  121. package/src/boot/rum.js +18 -9
  122. package/src/domain/assembly.js +0 -1
  123. package/src/domain/contexts/pageStateHistory.js +5 -5
  124. package/src/domain/contexts/urlContexts.js +4 -2
  125. package/src/domain/contexts/viewContexts.js +10 -3
  126. package/src/domain/locationChangeObservable.js +17 -7
  127. package/src/domain/performanceCollection.js +55 -138
  128. package/src/domain/performanceObservable.js +148 -0
  129. package/src/domain/performanceUtils.js +16 -0
  130. package/src/domain/replay/record/observers.js +39 -35
  131. package/src/domain/requestCollection.js +6 -2
  132. package/src/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  133. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +7 -8
  134. package/src/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +10 -4
  135. package/src/domain/rumEventsCollection/resource/resourceCollection.js +74 -117
  136. package/src/domain/rumEventsCollection/resource/resourceUtils.js +13 -11
  137. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +45 -0
  138. package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +2 -1
  139. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +24 -7
  140. package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  141. package/src/domain/rumEventsCollection/view/trackFirstInput.js +2 -2
  142. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  143. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +7 -19
  144. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +3 -2
  145. package/src/domain/rumEventsCollection/view/trackNavigationTimings.js +65 -32
  146. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -24
  147. package/src/domain/rumEventsCollection/view/trackViews.js +1 -1
  148. package/src/domain/rumEventsCollection/view/viewCollection.js +4 -0
  149. package/src/domain/waitPageActivityEnd.js +16 -17
  150. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
  151. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
@@ -2,7 +2,7 @@ import {
2
2
  LifeCycleEventType,
3
3
  SESSION_TIME_OUT_DELAY,
4
4
  relativeNow,
5
- ContextHistory,
5
+ createValueHistory,
6
6
  replaceNumberCharByPath,
7
7
  getQueryParamsFromUrl,
8
8
  isHashAnAnchor,
@@ -22,7 +22,9 @@ export function startUrlContexts(
22
22
  locationChangeObservable,
23
23
  location
24
24
  ) {
25
- var urlContextHistory = new ContextHistory(URL_CONTEXT_TIME_OUT_DELAY)
25
+ var urlContextHistory = createValueHistory({
26
+ expireDelay: URL_CONTEXT_TIME_OUT_DELAY
27
+ })
26
28
 
27
29
  var previousViewUrl
28
30
 
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  SESSION_TIME_OUT_DELAY,
3
- ContextHistory,
3
+ createValueHistory,
4
4
  LifeCycleEventType
5
5
  } from '@cloudcare/browser-core'
6
6
 
7
7
  export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY
8
8
 
9
9
  export function startViewContexts(lifeCycle) {
10
- var viewContextHistory = new ContextHistory(VIEW_CONTEXT_TIME_OUT_DELAY)
10
+ var viewContextHistory = createValueHistory({
11
+ expireDelay: VIEW_CONTEXT_TIME_OUT_DELAY
12
+ })
11
13
 
12
14
  lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, function (view) {
13
15
  viewContextHistory.add(buildViewContext(view), view.startClocks.relative)
@@ -16,7 +18,12 @@ export function startViewContexts(lifeCycle) {
16
18
  lifeCycle.subscribe(LifeCycleEventType.AFTER_VIEW_ENDED, function (data) {
17
19
  viewContextHistory.closeActive(data.endClocks.relative)
18
20
  })
19
-
21
+ lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, function (viewUpdate) {
22
+ var currentView = viewContextHistory.find(viewUpdate.startClocks.relative)
23
+ if (currentView && viewUpdate.name) {
24
+ currentView.name = viewUpdate.name
25
+ }
26
+ })
20
27
  lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
21
28
  viewContextHistory.reset()
22
29
  })
@@ -3,7 +3,7 @@ import {
3
3
  DOM_EVENT,
4
4
  Observable,
5
5
  shallowClone,
6
- instrumentMethodAndCallOriginal
6
+ instrumentMethod
7
7
  } from '@cloudcare/browser-core'
8
8
 
9
9
  export function createLocationChangeObservable(location) {
@@ -31,12 +31,22 @@ export function createLocationChangeObservable(location) {
31
31
 
32
32
  function trackHistory(onHistoryChange) {
33
33
  // eslint-disable-next-line @typescript-eslint/unbound-method
34
- var pushState = instrumentMethodAndCallOriginal(history, 'pushState', {
35
- after: onHistoryChange
36
- })
37
- var replaceState = instrumentMethodAndCallOriginal(history, 'replaceState', {
38
- after: onHistoryChange
39
- })
34
+ var pushState = instrumentMethod(
35
+ History.prototype,
36
+ 'pushState',
37
+ function (params) {
38
+ var onPostCall = params.onPostCall
39
+ onPostCall(onHistoryChange)
40
+ }
41
+ )
42
+ var replaceState = instrumentMethod(
43
+ History.prototype,
44
+ 'replaceState',
45
+ function (params) {
46
+ var onPostCall = params.onPostCall
47
+ onPostCall(onHistoryChange)
48
+ }
49
+ )
40
50
  var popState = addEventListener(window, DOM_EVENT.POP_STATE, onHistoryChange)
41
51
 
42
52
  return {
@@ -1,70 +1,56 @@
1
1
  import {
2
2
  addEventListeners,
3
- getRelativeTime,
4
- isNumber,
5
- includes,
6
3
  each,
7
- extend,
8
- filter,
9
4
  dateNow,
10
5
  relativeNow,
11
6
  DOM_EVENT,
12
7
  LifeCycleEventType,
13
- runOnReadyState,
14
8
  setTimeout,
15
9
  addEventListener,
16
10
  monitor,
17
- assign
11
+ objectHasValue
18
12
  } from '@cloudcare/browser-core'
13
+
19
14
  import {
20
- FAKE_INITIAL_DOCUMENT,
21
- isAllowedRequestUrl
22
- } from './rumEventsCollection/resource/resourceUtils'
15
+ RumPerformanceEntryType,
16
+ supportPerformanceTimingEvent
17
+ } from './performanceObservable'
23
18
  function supportPerformanceObject() {
24
19
  return window.performance !== undefined && 'getEntries' in performance
25
20
  }
26
21
 
27
- export function supportPerformanceTimingEvent(entryType) {
28
- return (
29
- window.PerformanceObserver &&
30
- PerformanceObserver.supportedEntryTypes !== undefined &&
31
- includes(PerformanceObserver.supportedEntryTypes, entryType)
32
- )
33
- }
34
22
  export function startPerformanceCollection(lifeCycle, configuration) {
35
- retrieveInitialDocumentResourceTiming(function (timing) {
36
- handleRumPerformanceEntries(lifeCycle, configuration, [timing])
37
- })
38
-
23
+ var cleanupTasks = []
39
24
  if (supportPerformanceObject()) {
40
25
  var performanceEntries = performance.getEntries()
41
26
  // Because the performance entry list can be quite large
42
27
  // delay the computation to prevent the SDK from blocking the main thread on init
43
28
  setTimeout(function () {
44
- handleRumPerformanceEntries(lifeCycle, configuration, performanceEntries)
29
+ handleRumPerformanceEntries(lifeCycle, performanceEntries)
45
30
  })
46
31
  }
47
32
  if (window.PerformanceObserver) {
48
33
  var handlePerformanceEntryList = monitor(function (entries) {
49
- handleRumPerformanceEntries(
50
- lifeCycle,
51
- configuration,
52
- entries.getEntries()
53
- )
34
+ handleRumPerformanceEntries(lifeCycle, entries.getEntries())
54
35
  })
55
- var mainEntries = ['resource', 'navigation', 'longtask', 'paint']
36
+ var mainEntries = [
37
+ RumPerformanceEntryType.LONG_TASK,
38
+ RumPerformanceEntryType.PAINT
39
+ ]
56
40
  var experimentalEntries = [
57
- 'largest-contentful-paint',
58
- 'first-input',
59
- 'layout-shift',
60
- 'event'
41
+ RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT,
42
+ RumPerformanceEntryType.FIRST_INPUT,
43
+ RumPerformanceEntryType.LAYOUT_SHIFT,
44
+ RumPerformanceEntryType.EVENT
61
45
  ]
62
46
  try {
63
47
  // Experimental entries are not retrieved by performance.getEntries()
64
48
  // use a single PerformanceObserver with buffered flag by type
65
49
  // to get values that could happen before SDK init
66
50
  each(experimentalEntries, function (type) {
67
- var observer = new PerformanceObserver(handlePerformanceEntryList)
51
+ var observer = new window.PerformanceObserver(
52
+ handlePerformanceEntryList
53
+ )
68
54
  observer.observe({
69
55
  type: type,
70
56
  buffered: true,
@@ -72,6 +58,9 @@ export function startPerformanceCollection(lifeCycle, configuration) {
72
58
  // cf: https://github.com/GoogleChrome/web-vitals/blob/3806160ffbc93c3c4abf210a167b81228172b31c/src/onINP.ts#L209
73
59
  durationThreshold: 40
74
60
  })
61
+ cleanupTasks.push(function () {
62
+ observer.disconnect()
63
+ })
75
64
  })
76
65
  } catch (e) {
77
66
  // Some old browser versions (ex: chrome 67) don't support the PerformanceObserver type and buffered options
@@ -81,72 +70,39 @@ export function startPerformanceCollection(lifeCycle, configuration) {
81
70
  })
82
71
  }
83
72
  var mainObserver = new PerformanceObserver(handlePerformanceEntryList)
84
- mainObserver.observe({ entryTypes: mainEntries })
73
+ // mainObserver.observe({ entryTypes: mainEntries })
74
+ try {
75
+ mainObserver.observe({ entryTypes: mainEntries })
76
+ cleanupTasks.push(function () {
77
+ mainObserver.disconnect()
78
+ })
79
+ } catch {}
85
80
  if (supportPerformanceObject() && 'addEventListener' in performance) {
86
81
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
87
- addEventListener(performance, 'resourcetimingbufferfull', function () {
88
- performance.clearResourceTimings()
89
- })
82
+ var resourncetimingbufferfullListener = addEventListener(
83
+ performance,
84
+ 'resourcetimingbufferfull',
85
+ function () {
86
+ performance.clearResourceTimings()
87
+ }
88
+ )
89
+ cleanupTasks.push(resourncetimingbufferfullListener.stop)
90
90
  }
91
91
  }
92
- if (!supportPerformanceTimingEvent('navigation')) {
93
- retrieveNavigationTiming(function (timing) {
94
- handleRumPerformanceEntries(lifeCycle, configuration, [timing])
95
- })
96
- }
97
- if (!supportPerformanceTimingEvent('first-input')) {
98
- retrieveFirstInputTiming(function (timing) {
99
- return handleRumPerformanceEntries(lifeCycle, configuration, [timing])
92
+
93
+ if (!supportPerformanceTimingEvent(RumPerformanceEntryType.FIRST_INPUT)) {
94
+ var _retrieveFirstInputTiming = retrieveFirstInputTiming(function (timing) {
95
+ return handleRumPerformanceEntries(lifeCycle, [timing])
100
96
  })
97
+ cleanupTasks.push(_retrieveFirstInputTiming.stop)
101
98
  }
102
- }
103
-
104
- export function retrieveInitialDocumentResourceTiming(callback) {
105
- runOnReadyState('interactive', function () {
106
- var timing
107
-
108
- var forcedAttributes = {
109
- entryType: 'resource',
110
- initiatorType: FAKE_INITIAL_DOCUMENT,
111
- traceId: '',
112
- toJSON: function () {
113
- return assign({}, timing, { toJSON: undefined })
114
- }
115
- }
116
- if (
117
- supportPerformanceTimingEvent('navigation') &&
118
- performance.getEntriesByType('navigation').length > 0
119
- ) {
120
- var navigationEntry = performance.getEntriesByType('navigation')[0]
121
- timing = extend(navigationEntry.toJSON(), forcedAttributes)
122
- } else {
123
- var relativePerformanceTiming = computeRelativePerformanceTiming()
124
- timing = extend(
125
- relativePerformanceTiming,
126
- {
127
- decodedBodySize: 0,
128
- duration: relativePerformanceTiming.responseEnd,
129
- name: window.location.href,
130
- startTime: 0
131
- },
132
- forcedAttributes
133
- )
99
+ return {
100
+ stop: function () {
101
+ each(cleanupTasks, function (task) {
102
+ return task()
103
+ })
134
104
  }
135
- callback(timing)
136
- })
137
- }
138
-
139
- function retrieveNavigationTiming(callback) {
140
- function sendFakeTiming() {
141
- callback(
142
- extend(computeRelativePerformanceTiming(), { entryType: 'navigation' })
143
- )
144
105
  }
145
-
146
- runOnReadyState('complete', function () {
147
- // Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
148
- setTimeout(sendFakeTiming)
149
- })
150
106
  }
151
107
 
152
108
  /**
@@ -176,7 +132,7 @@ function retrieveFirstInputTiming(callback) {
176
132
  // when the system received the event (e.g. evt.timeStamp) and when it could run the callback
177
133
  // (e.g. performance.now()).
178
134
  var timing = {
179
- entryType: 'first-input',
135
+ entryType: RumPerformanceEntryType.FIRST_INPUT,
180
136
  processingStart: relativeNow(),
181
137
  processingEnd: relativeNow(),
182
138
  startTime: evt.timeStamp,
@@ -193,7 +149,6 @@ function retrieveFirstInputTiming(callback) {
193
149
  { passive: true, capture: true }
194
150
  )
195
151
  var removeEventListeners = listeners.stop
196
-
197
152
  /**
198
153
  * Pointer events are a special case, because they can trigger main or compositor thread behavior.
199
154
  * We differenciate these cases based on whether or not we see a pointercancel event, which are
@@ -228,58 +183,20 @@ function retrieveFirstInputTiming(callback) {
228
183
  }
229
184
  }
230
185
  }
231
- }
232
-
233
- function computeRelativePerformanceTiming() {
234
- var result = {}
235
- var timing = performance.timing
236
- for (var key in timing) {
237
- if (isNumber(timing[key])) {
238
- result[key] = timing[key] === 0 ? 0 : getRelativeTime(timing[key])
239
- }
186
+ return {
187
+ stop: removeEventListeners
240
188
  }
241
- return result
242
189
  }
243
190
 
244
- function handleRumPerformanceEntries(lifeCycle, configuration, entries) {
245
- var rumPerformanceEntries = filter(entries, function (entry) {
246
- return (
247
- entry.entryType === 'resource' ||
248
- entry.entryType === 'navigation' ||
249
- entry.entryType === 'paint' ||
250
- entry.entryType === 'longtask' ||
251
- entry.entryType === 'largest-contentful-paint' ||
252
- entry.entryType === 'first-input' ||
253
- entry.entryType === 'layout-shift' ||
254
- entry.entryType === 'event'
255
- )
191
+ function handleRumPerformanceEntries(lifeCycle, entries) {
192
+ var rumPerformanceEntries = entries.filter(function (entry) {
193
+ return objectHasValue(RumPerformanceEntryType, entry.entryType)
256
194
  })
257
195
 
258
- var rumAllowedPerformanceEntries = filter(
259
- rumPerformanceEntries,
260
- function (entry) {
261
- return (
262
- !isIncompleteNavigation(entry) &&
263
- !isForbiddenResource(configuration, entry)
264
- )
265
- }
266
- )
267
-
268
- if (rumAllowedPerformanceEntries.length) {
196
+ if (rumPerformanceEntries.length) {
269
197
  lifeCycle.notify(
270
198
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
271
- rumAllowedPerformanceEntries
199
+ rumPerformanceEntries
272
200
  )
273
201
  }
274
202
  }
275
-
276
- function isIncompleteNavigation(entry) {
277
- return entry.entryType === 'navigation' && entry.loadEventEnd <= 0
278
- }
279
-
280
- function isForbiddenResource(configuration, entry) {
281
- return (
282
- entry.entryType === 'resource' &&
283
- !isAllowedRequestUrl(configuration, entry.name)
284
- )
285
- }
@@ -0,0 +1,148 @@
1
+ import {
2
+ addEventListener,
3
+ Observable,
4
+ setTimeout,
5
+ clearTimeout,
6
+ monitor,
7
+ includes
8
+ } from '@cloudcare/browser-core'
9
+ import {
10
+ isAllowedRequestUrl,
11
+ hasValidResourceEntryDuration
12
+ } from './rumEventsCollection/resource/resourceUtils'
13
+
14
+ // We want to use a real enum (i.e. not a const enum) here, to be able to check whether an arbitrary
15
+ // string is an expected performance entry
16
+ // eslint-disable-next-line no-restricted-syntax
17
+ export var RumPerformanceEntryType = {
18
+ EVENT: 'event',
19
+ FIRST_INPUT: 'first-input',
20
+ LARGEST_CONTENTFUL_PAINT: 'largest-contentful-paint',
21
+ LAYOUT_SHIFT: 'layout-shift',
22
+ LONG_TASK: 'longtask',
23
+ LONG_ANIMATION_FRAME: 'long-animation-frame',
24
+ NAVIGATION: 'navigation',
25
+ PAINT: 'paint',
26
+ RESOURCE: 'resource'
27
+ }
28
+
29
+ export function createPerformanceObservable(configuration, options) {
30
+ return new Observable(function (observable) {
31
+ if (!window.PerformanceObserver) {
32
+ return
33
+ }
34
+
35
+ var handlePerformanceEntries = function (entries) {
36
+ var rumPerformanceEntries = filterRumPerformanceEntries(
37
+ configuration,
38
+ entries
39
+ )
40
+ if (rumPerformanceEntries.length > 0) {
41
+ observable.notify(rumPerformanceEntries)
42
+ }
43
+ }
44
+
45
+ var timeoutId
46
+ var isObserverInitializing = true
47
+ const observer = new PerformanceObserver(
48
+ monitor(function (entries) {
49
+ // In Safari the performance observer callback is synchronous.
50
+ // Because the buffered performance entry list can be quite large we delay the computation to prevent the SDK from blocking the main thread on init
51
+ if (isObserverInitializing) {
52
+ timeoutId = setTimeout(function () {
53
+ handlePerformanceEntries(entries.getEntries())
54
+ })
55
+ } else {
56
+ handlePerformanceEntries(entries.getEntries())
57
+ }
58
+ })
59
+ )
60
+ try {
61
+ observer.observe(options)
62
+ } catch {
63
+ // Some old browser versions (<= chrome 74 ) don't support the PerformanceObserver type and buffered options
64
+ // In these cases, fallback to getEntriesByType and PerformanceObserver with entryTypes
65
+ // TODO: remove this fallback in the next major version
66
+ var fallbackSupportedEntryTypes = [
67
+ RumPerformanceEntryType.RESOURCE,
68
+ RumPerformanceEntryType.NAVIGATION,
69
+ RumPerformanceEntryType.LONG_TASK,
70
+ RumPerformanceEntryType.PAINT
71
+ ]
72
+ if (includes(fallbackSupportedEntryTypes, options.type)) {
73
+ if (options.buffered) {
74
+ timeoutId = setTimeout(function () {
75
+ handlePerformanceEntries(performance.getEntriesByType(options.type))
76
+ })
77
+ }
78
+ try {
79
+ observer.observe({ entryTypes: [options.type] })
80
+ } catch {
81
+ // Old versions of Safari are throwing "entryTypes contained only unsupported types"
82
+ // errors when observing only unsupported entry types.
83
+ //
84
+ // We could use `supportPerformanceTimingEvent` to make sure we don't invoke
85
+ // `observer.observe` with an unsupported entry type, but Safari 11 and 12 don't support
86
+ // `Performance.supportedEntryTypes`, so doing so would lose support for these versions
87
+ // even if they do support the entry type.
88
+ return
89
+ }
90
+ }
91
+ }
92
+ isObserverInitializing = false
93
+
94
+ manageResourceTimingBufferFull(configuration)
95
+
96
+ return function () {
97
+ observer.disconnect()
98
+ clearTimeout(timeoutId)
99
+ }
100
+ })
101
+ }
102
+
103
+ var resourceTimingBufferFullListener
104
+ function manageResourceTimingBufferFull(configuration) {
105
+ if (
106
+ !resourceTimingBufferFullListener &&
107
+ supportPerformanceObject() &&
108
+ 'addEventListener' in performance
109
+ ) {
110
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
111
+ resourceTimingBufferFullListener = addEventListener(
112
+ performance,
113
+ 'resourcetimingbufferfull',
114
+ function () {
115
+ performance.clearResourceTimings()
116
+ }
117
+ )
118
+ }
119
+ return function () {
120
+ resourceTimingBufferFullListener && resourceTimingBufferFullListener.stop()
121
+ }
122
+ }
123
+
124
+ function supportPerformanceObject() {
125
+ return window.performance !== undefined && 'getEntries' in performance
126
+ }
127
+
128
+ export function supportPerformanceTimingEvent(entryType) {
129
+ return (
130
+ window.PerformanceObserver &&
131
+ PerformanceObserver.supportedEntryTypes !== undefined &&
132
+ PerformanceObserver.supportedEntryTypes.includes(entryType)
133
+ )
134
+ }
135
+
136
+ function filterRumPerformanceEntries(configuration, entries) {
137
+ return entries.filter(function (entry) {
138
+ return !isForbiddenResource(configuration, entry)
139
+ })
140
+ }
141
+
142
+ function isForbiddenResource(configuration, entry) {
143
+ return (
144
+ entry.entryType === RumPerformanceEntryType.RESOURCE &&
145
+ (!isAllowedRequestUrl(configuration, entry.name) ||
146
+ !hasValidResourceEntryDuration(entry))
147
+ )
148
+ }
@@ -0,0 +1,16 @@
1
+ import { getRelativeTime, isNumber } from '@cloudcare/browser-core'
2
+
3
+ export function computeRelativePerformanceTiming() {
4
+ var result = {}
5
+ var timing = performance.timing
6
+
7
+ for (var key in timing) {
8
+ if (isNumber(timing[key])) {
9
+ var numberKey = key
10
+ var timingElement = timing[numberKey]
11
+ result[numberKey] =
12
+ timingElement === 0 ? 0 : getRelativeTime(timingElement)
13
+ }
14
+ }
15
+ return result
16
+ }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  instrumentSetter,
3
- instrumentMethodAndCallOriginal,
3
+ instrumentMethod,
4
4
  assign,
5
5
  throttle,
6
6
  DOM_EVENT,
@@ -425,19 +425,22 @@ export function initStyleSheetObserver(cb) {
425
425
  }
426
426
 
427
427
  var instrumentationStoppers = [
428
- instrumentMethodAndCallOriginal(CSSStyleSheet.prototype, 'insertRule', {
429
- before: function (rule, index) {
430
- checkStyleSheetAndCallback(this, function (id) {
431
- return cb({ id: id, adds: [{ rule: rule, index: index }] })
432
- })
433
- }
428
+ instrumentMethod(CSSStyleSheet.prototype, 'insertRule', function (params) {
429
+ var styleSheet = params.target
430
+ var parameters = params.parameters
431
+ var rule = parameters[0]
432
+ var index = parameters[1]
433
+ checkStyleSheetAndCallback(styleSheet, function (id) {
434
+ return cb({ id: id, adds: [{ rule: rule, index: index }] })
435
+ })
434
436
  }),
435
- instrumentMethodAndCallOriginal(CSSStyleSheet.prototype, 'deleteRule', {
436
- before: function (index) {
437
- checkStyleSheetAndCallback(this, function (id) {
438
- return cb({ id: id, removes: [{ index: index }] })
439
- })
440
- }
437
+ instrumentMethod(CSSStyleSheet.prototype, 'deleteRule', function (params) {
438
+ var styleSheet = params.target
439
+ var parameters = params.parameters
440
+ var index = parameters[0]
441
+ checkStyleSheetAndCallback(styleSheet, function (id) {
442
+ return cb({ id: id, removes: [{ index: index }] })
443
+ })
441
444
  })
442
445
  ]
443
446
 
@@ -450,29 +453,30 @@ export function initStyleSheetObserver(cb) {
450
453
 
451
454
  function instrumentGroupingCSSRuleClass(cls) {
452
455
  instrumentationStoppers.push(
453
- instrumentMethodAndCallOriginal(cls.prototype, 'insertRule', {
454
- before: function (rule, index) {
455
- var _this = this
456
- checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
457
- var path = getPathToNestedCSSRule(_this)
458
- if (path) {
459
- path.push(index || 0)
460
- cb({ id: id, adds: [{ rule: rule, index: path }] })
461
- }
462
- })
463
- }
456
+ instrumentMethod(cls.prototype, 'insertRule', function (params) {
457
+ var styleSheet = params.target
458
+ var parameters = params.parameters
459
+ var rule = parameters[0]
460
+ var index = parameters[1]
461
+ checkStyleSheetAndCallback(styleSheet.parentStyleSheet, function (id) {
462
+ var path = getPathToNestedCSSRule(styleSheet)
463
+ if (path) {
464
+ path.push(index || 0)
465
+ cb({ id: id, adds: [{ rule: rule, index: path }] })
466
+ }
467
+ })
464
468
  }),
465
- instrumentMethodAndCallOriginal(cls.prototype, 'deleteRule', {
466
- before: function (index) {
467
- var _this = this
468
- checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
469
- var path = getPathToNestedCSSRule(_this)
470
- if (path) {
471
- path.push(index)
472
- cb({ id: id, removes: [{ index: path }] })
473
- }
474
- })
475
- }
469
+ instrumentMethod(cls.prototype, 'deleteRule', function (params) {
470
+ var styleSheet = params.target
471
+ var parameters = params.parameters
472
+ var index = parameters[0]
473
+ checkStyleSheetAndCallback(styleSheet.parentStyleSheet, function (id) {
474
+ var path = getPathToNestedCSSRule(styleSheet)
475
+ if (path) {
476
+ path.push(index)
477
+ cb({ id: id, removes: [{ index: path }] })
478
+ }
479
+ })
476
480
  })
477
481
  )
478
482
  }
@@ -53,7 +53,9 @@ export function trackXhr(lifeCycle, configuration, tracer) {
53
53
  traceSampled: context.traceSampled,
54
54
  type: RequestType.XHR,
55
55
  url: context.url,
56
- xhr: context.xhr
56
+ xhr: context.xhr,
57
+ isAborted: context.isAborted,
58
+ handlingStack: context.handlingStack
57
59
  })
58
60
  break
59
61
  }
@@ -100,7 +102,9 @@ export function trackFetch(lifeCycle, configuration, tracer) {
100
102
  url: context.url,
101
103
  response: context.response,
102
104
  init: context.init,
103
- input: context.input
105
+ input: context.input,
106
+ isAborted: context.isAborted,
107
+ handlingStack: context.handlingStack
104
108
  })
105
109
  })
106
110
  break
@@ -4,7 +4,7 @@ import {
4
4
  assign,
5
5
  getRelativeTime,
6
6
  ONE_MINUTE,
7
- ContextHistory,
7
+ createValueHistory,
8
8
  UUID,
9
9
  clocksNow,
10
10
  ONE_SECOND,
@@ -38,7 +38,9 @@ export function trackClickActions(
38
38
  domMutationObservable,
39
39
  configuration
40
40
  ) {
41
- var history = new ContextHistory(ACTION_CONTEXT_TIME_OUT_DELAY)
41
+ var history = new createValueHistory({
42
+ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY
43
+ })
42
44
  var stopObservable = new Observable()
43
45
  var currentClickChain
44
46