@cloudcare/browser-rum 3.1.2 → 3.1.5

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 (139) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.js +23 -3
  4. package/cjs/boot/rum.js.map +1 -1
  5. package/cjs/boot/startRecording.js +1 -1
  6. package/cjs/boot/startRecording.js.map +1 -1
  7. package/cjs/domain/assembly.js +6 -5
  8. package/cjs/domain/assembly.js.map +1 -1
  9. package/cjs/domain/configuration.js +3 -7
  10. package/cjs/domain/configuration.js.map +1 -1
  11. package/cjs/domain/contexts/displayContext.js +12 -18
  12. package/cjs/domain/contexts/displayContext.js.map +1 -1
  13. package/cjs/domain/performanceCollection.js +16 -10
  14. package/cjs/domain/performanceCollection.js.map +1 -1
  15. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  16. package/cjs/domain/replay/record/privacy.js +0 -1
  17. package/cjs/domain/replay/record/privacy.js.map +1 -1
  18. package/cjs/domain/replay/record/serialize.js +12 -13
  19. package/cjs/domain/replay/record/serialize.js.map +1 -1
  20. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
  21. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  22. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js +2 -8
  23. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  24. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +53 -21
  25. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  26. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +11 -25
  27. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  28. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +45 -2
  29. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  30. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  31. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  32. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +22 -29
  33. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  34. package/cjs/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +12 -9
  35. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
  36. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +18 -27
  37. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  38. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +66 -11
  39. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  40. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +11 -6
  41. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  42. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  43. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  44. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -24
  45. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  46. package/cjs/domain/rumEventsCollection/view/trackViews.js +34 -12
  47. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  48. package/cjs/domain/rumEventsCollection/view/viewCollection.js +34 -33
  49. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  50. package/cjs/domain/trackEventCounts.js +4 -4
  51. package/cjs/domain/trackEventCounts.js.map +1 -1
  52. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  53. package/cjs/transport/startRumBatch.js +1 -1
  54. package/cjs/transport/startRumBatch.js.map +1 -1
  55. package/esm/boot/buildEnv.js +1 -1
  56. package/esm/boot/rum.js +23 -3
  57. package/esm/boot/rum.js.map +1 -1
  58. package/esm/boot/startRecording.js +1 -1
  59. package/esm/boot/startRecording.js.map +1 -1
  60. package/esm/domain/assembly.js +6 -5
  61. package/esm/domain/assembly.js.map +1 -1
  62. package/esm/domain/configuration.js +4 -8
  63. package/esm/domain/configuration.js.map +1 -1
  64. package/esm/domain/contexts/displayContext.js +11 -16
  65. package/esm/domain/contexts/displayContext.js.map +1 -1
  66. package/esm/domain/performanceCollection.js +17 -10
  67. package/esm/domain/performanceCollection.js.map +1 -1
  68. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  69. package/esm/domain/replay/record/privacy.js +0 -1
  70. package/esm/domain/replay/record/privacy.js.map +1 -1
  71. package/esm/domain/replay/record/serialize.js +13 -14
  72. package/esm/domain/replay/record/serialize.js.map +1 -1
  73. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +10 -33
  74. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  75. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js +3 -9
  76. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  77. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +54 -22
  78. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  79. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +13 -27
  80. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  81. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +47 -3
  82. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  83. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  84. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  85. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +22 -28
  86. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  87. package/esm/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +13 -9
  88. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -0
  89. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +19 -28
  90. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  91. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +65 -12
  92. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  93. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +12 -6
  94. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  95. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  96. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  97. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js +55 -25
  98. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  99. package/esm/domain/rumEventsCollection/view/trackViews.js +33 -12
  100. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  101. package/esm/domain/rumEventsCollection/view/viewCollection.js +35 -34
  102. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  103. package/esm/domain/trackEventCounts.js +4 -4
  104. package/esm/domain/trackEventCounts.js.map +1 -1
  105. package/esm/domain/waitPageActivityEnd.js.map +1 -1
  106. package/esm/transport/startRumBatch.js +1 -1
  107. package/esm/transport/startRumBatch.js.map +1 -1
  108. package/package.json +4 -4
  109. package/src/boot/rum.js +27 -3
  110. package/src/boot/startRecording.js +1 -0
  111. package/src/domain/assembly.js +6 -4
  112. package/src/domain/configuration.js +5 -9
  113. package/src/domain/contexts/displayContext.js +11 -20
  114. package/src/domain/performanceCollection.js +21 -10
  115. package/src/domain/replay/record/privacy.js +1 -5
  116. package/src/domain/replay/record/serialize.js +13 -16
  117. package/src/domain/rumEventsCollection/actions/trackClickActions.js +7 -35
  118. package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +4 -13
  119. package/src/domain/rumEventsCollection/resource/resourceCollection.js +115 -29
  120. package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +18 -35
  121. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +59 -3
  122. package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -4
  123. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +27 -32
  124. package/src/domain/rumEventsCollection/view/{trackFirstInputTimings.js → trackFirstInput.js} +25 -8
  125. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +24 -28
  126. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +79 -15
  127. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +21 -6
  128. package/src/domain/rumEventsCollection/view/trackLoadingTime.js +10 -2
  129. package/src/domain/rumEventsCollection/view/trackScrollMetrics.js +79 -35
  130. package/src/domain/rumEventsCollection/view/trackViews.js +39 -16
  131. package/src/domain/rumEventsCollection/view/viewCollection.js +90 -37
  132. package/src/domain/trackEventCounts.js +4 -4
  133. package/src/domain/waitPageActivityEnd.js +1 -0
  134. package/src/transport/startRumBatch.js +3 -1
  135. package/cjs/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
  136. package/esm/domain/rumEventsCollection/view/trackFirstInputTimings.js.map +0 -1
  137. package/src/.DS_Store +0 -0
  138. package/src/domain/.DS_Store +0 -0
  139. package/src/domain/rumEventsCollection/.DS_Store +0 -0
@@ -3,6 +3,7 @@ import {
3
3
  display,
4
4
  isPercentage,
5
5
  validateAndBuildConfiguration,
6
+ validatePostRequestRequireParamsConfiguration,
6
7
  isArray,
7
8
  TraceType,
8
9
  isNullUndefinedDefaultValue,
@@ -21,12 +22,9 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
21
22
  )
22
23
  return
23
24
  }
24
- if (!initConfiguration.datakitUrl && !initConfiguration.datakitOrigin) {
25
- display.error(
26
- 'datakitOrigin is not configured, no RUM data will be collected.'
27
- )
28
- return false
29
- }
25
+ var requireParamsValidate =
26
+ validatePostRequestRequireParamsConfiguration(initConfiguration)
27
+ if (!requireParamsValidate) return
30
28
  // TODO remove fallback in next major
31
29
  if (
32
30
  initConfiguration.sessionReplaySampleRate !== undefined &&
@@ -74,7 +72,6 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
74
72
  initConfiguration.trackUserInteractions,
75
73
  initConfiguration.trackInteractions
76
74
  )
77
- var trackFrustrations = !!initConfiguration.trackFrustrations
78
75
 
79
76
  return assign(
80
77
  {
@@ -90,8 +87,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
90
87
  initConfiguration.excludedActivityUrls,
91
88
  []
92
89
  ),
93
- trackUserInteractions: trackUserInteractions || trackFrustrations,
94
- trackFrustrations: trackFrustrations,
90
+ trackUserInteractions: trackUserInteractions,
95
91
  trackViewsManually: !!initConfiguration.trackViewsManually,
96
92
  traceType: isNullUndefinedDefaultValue(
97
93
  initConfiguration.traceType,
@@ -3,27 +3,18 @@ import {
3
3
  initViewportObservable
4
4
  } from '../initViewportObservable'
5
5
 
6
- var viewport
7
- var stopListeners
8
-
9
- export function getDisplayContext() {
10
- if (!viewport) {
11
- viewport = getViewportDimension()
12
- stopListeners = initViewportObservable().subscribe(function (
13
- viewportDimension
14
- ) {
15
- viewport = viewportDimension
16
- }).unsubscribe
17
- }
6
+ export function startDisplayContext() {
7
+ var viewport = getViewportDimension()
8
+ var unsubscribeViewport = initViewportObservable().subscribe(function (
9
+ viewportDimension
10
+ ) {
11
+ viewport = viewportDimension
12
+ }).unsubscribe
18
13
 
19
14
  return {
20
- viewport: viewport
21
- }
22
- }
23
-
24
- export function resetDisplayContext() {
25
- if (stopListeners) {
26
- stopListeners()
15
+ get: function () {
16
+ return { viewport: viewport }
17
+ },
18
+ stop: unsubscribeViewport
27
19
  }
28
- viewport = undefined
29
20
  }
@@ -13,7 +13,8 @@ import {
13
13
  runOnReadyState,
14
14
  setTimeout,
15
15
  addEventListener,
16
- monitor
16
+ monitor,
17
+ assign
17
18
  } from '@cloudcare/browser-core'
18
19
  import {
19
20
  FAKE_INITIAL_DOCUMENT,
@@ -55,7 +56,8 @@ export function startPerformanceCollection(lifeCycle, configuration) {
55
56
  var experimentalEntries = [
56
57
  'largest-contentful-paint',
57
58
  'first-input',
58
- 'layout-shift'
59
+ 'layout-shift',
60
+ 'event'
59
61
  ]
60
62
  try {
61
63
  // Experimental entries are not retrieved by performance.getEntries()
@@ -63,7 +65,13 @@ export function startPerformanceCollection(lifeCycle, configuration) {
63
65
  // to get values that could happen before SDK init
64
66
  each(experimentalEntries, function (type) {
65
67
  var observer = new PerformanceObserver(handlePerformanceEntryList)
66
- observer.observe({ type: type, buffered: true })
68
+ observer.observe({
69
+ type: type,
70
+ buffered: true,
71
+ // durationThreshold only impact PerformanceEventTiming entries used for INP computation which requires a threshold at 40 (default is 104ms)
72
+ // cf: https://github.com/GoogleChrome/web-vitals/blob/3806160ffbc93c3c4abf210a167b81228172b31c/src/onINP.ts#L209
73
+ durationThreshold: 40
74
+ })
67
75
  })
68
76
  } catch (e) {
69
77
  // Some old browser versions (ex: chrome 67) don't support the PerformanceObserver type and buffered options
@@ -100,7 +108,10 @@ export function retrieveInitialDocumentResourceTiming(callback) {
100
108
  var forcedAttributes = {
101
109
  entryType: 'resource',
102
110
  initiatorType: FAKE_INITIAL_DOCUMENT,
103
- traceId: ''
111
+ traceId: '',
112
+ toJSON: function () {
113
+ return assign({}, timing, { toJSON: undefined })
114
+ }
104
115
  }
105
116
  if (
106
117
  supportPerformanceTimingEvent('navigation') &&
@@ -167,7 +178,10 @@ function retrieveFirstInputTiming(callback) {
167
178
  var timing = {
168
179
  entryType: 'first-input',
169
180
  processingStart: relativeNow(),
170
- startTime: evt.timeStamp
181
+ processingEnd: relativeNow(),
182
+ startTime: evt.timeStamp,
183
+ duration: 0,
184
+ name: ''
171
185
  }
172
186
 
173
187
  if (evt.type === DOM_EVENT.POINTER_DOWN) {
@@ -236,7 +250,8 @@ function handleRumPerformanceEntries(lifeCycle, configuration, entries) {
236
250
  entry.entryType === 'longtask' ||
237
251
  entry.entryType === 'largest-contentful-paint' ||
238
252
  entry.entryType === 'first-input' ||
239
- entry.entryType === 'layout-shift'
253
+ entry.entryType === 'layout-shift' ||
254
+ entry.entryType === 'event'
240
255
  )
241
256
  })
242
257
 
@@ -268,7 +283,3 @@ function isForbiddenResource(configuration, entry) {
268
283
  !isAllowedRequestUrl(configuration, entry.name)
269
284
  )
270
285
  }
271
- export function supportPerformanceEntry() {
272
- // Safari 10 doesn't support PerformanceEntry
273
- return typeof PerformanceEntry === 'function'
274
- }
@@ -3,11 +3,7 @@ import {
3
3
  getParentNode,
4
4
  isTextNode
5
5
  } from '@cloudcare/browser-core'
6
- import {
7
- switchToAbsoluteUrl,
8
- getCssRulesString,
9
- getHref
10
- } from './serializationUtils'
6
+
11
7
  import {
12
8
  NodePrivacyLevel,
13
9
  PRIVACY_ATTR_NAME,
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  assign,
3
3
  startsWith,
4
- isNodeShadowHost,
5
- isNodeShadowRoot
4
+ isNodeShadowRoot,
5
+ forEachChildNodes,
6
+ hasChildNodes
6
7
  } from '@cloudcare/browser-core'
7
8
  import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelectorsFromElement'
8
9
  import {
@@ -109,18 +110,13 @@ function serializeDocumentTypeNode(documentType) {
109
110
  }
110
111
 
111
112
  function serializeDocumentFragmentNode(element, options) {
112
- var childNodes = []
113
- if (element.childNodes.length) {
114
- childNodes = serializeChildNodes(element, options)
115
- }
116
-
117
113
  var isShadowRoot = isNodeShadowRoot(element)
118
114
  if (isShadowRoot) {
119
115
  options.serializationContext.shadowRootsController.addShadowRoot(element)
120
116
  }
121
117
  return {
122
118
  type: NodeType.DocumentFragment,
123
- childNodes: childNodes,
119
+ childNodes: serializeChildNodes(element, options),
124
120
  isShadowRoot: isShadowRoot,
125
121
  adoptedStyleSheets: isShadowRoot
126
122
  ? serializeStyleSheets(element.adoptedStyleSheets)
@@ -185,7 +181,7 @@ export function serializeElementNode(element, options) {
185
181
  )
186
182
 
187
183
  var childNodes = []
188
- if (element.childNodes.length && tagName !== 'style') {
184
+ if (hasChildNodes(element) && tagName !== 'style') {
189
185
  // OBJECT POOLING OPTIMIZATION:
190
186
  // We should not create a new object systematically as it could impact performances. Try to reuse
191
187
  // the same object as much as possible, and clone it only if we need to.
@@ -204,12 +200,12 @@ export function serializeElementNode(element, options) {
204
200
  childNodes = serializeChildNodes(element, childNodesSerializationOptions)
205
201
  }
206
202
 
207
- if (isNodeShadowHost(element)) {
208
- var shadowRoot = serializeNodeWithId(element.shadowRoot, options)
209
- if (shadowRoot !== null) {
210
- childNodes.push(shadowRoot)
211
- }
212
- }
203
+ // if (isNodeShadowHost(element)) {
204
+ // var shadowRoot = serializeNodeWithId(element.shadowRoot, options)
205
+ // if (shadowRoot !== null) {
206
+ // childNodes.push(shadowRoot)
207
+ // }
208
+ // }
213
209
 
214
210
  return {
215
211
  type: NodeType.Element,
@@ -253,12 +249,13 @@ function serializeCDataNode() {
253
249
 
254
250
  export function serializeChildNodes(node, options) {
255
251
  var result = []
256
- node.childNodes.forEach(function (childNode) {
252
+ forEachChildNodes(node, function (childNode) {
257
253
  var serializedChildNode = serializeNodeWithId(childNode, options)
258
254
  if (serializedChildNode) {
259
255
  result.push(serializedChildNode)
260
256
  }
261
257
  })
258
+ // node.childNodes.forEach()
262
259
  return result
263
260
  }
264
261
 
@@ -52,7 +52,6 @@ export function trackClickActions(
52
52
  configuration,
53
53
  lifeCycle,
54
54
  domMutationObservable,
55
- history,
56
55
  pointerDownEvent
57
56
  )
58
57
  },
@@ -74,12 +73,14 @@ export function trackClickActions(
74
73
  var stopActionEventsListener = _listenActionEvents.stop
75
74
  var actionContexts = {
76
75
  findActionId: function (startTime) {
77
- return history.find(startTime)
76
+ const allIds = history.findAll(startTime)
77
+ if (allIds && allIds.length) {
78
+ return allIds[allIds.length - 1]
79
+ }
80
+ return undefined
78
81
  },
79
82
  findAllActionId: function (startTime) {
80
- return configuration.trackFrustrations
81
- ? history.findAll(startTime)
82
- : history.find(startTime)
83
+ return history.findAll(startTime)
83
84
  }
84
85
  }
85
86
 
@@ -110,24 +111,12 @@ function processPointerDown(
110
111
  configuration,
111
112
  lifeCycle,
112
113
  domMutationObservable,
113
- history,
114
114
  pointerDownEvent
115
115
  ) {
116
- if (!configuration.trackFrustrations && history.find()) {
117
- // TODO: remove this in a future major version. To keep retrocompatibility, ignore any new
118
- // action if another one is already occurring.
119
- return
120
- }
121
-
122
116
  var clickActionBase = computeClickActionBase(
123
117
  pointerDownEvent,
124
118
  configuration.actionNameAttribute
125
119
  )
126
- if (!configuration.trackFrustrations && !clickActionBase.name) {
127
- // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action
128
- // with a blank name
129
- return
130
- }
131
120
 
132
121
  var hadActivityOnPointerDown = false
133
122
 
@@ -138,8 +127,6 @@ function processPointerDown(
138
127
  function (pageActivityEndEvent) {
139
128
  hadActivityOnPointerDown = pageActivityEndEvent.hadActivity
140
129
  },
141
- // We don't care about the activity duration, we just want to know whether an activity did happen
142
- // within the "validation delay" or not. Limit the duration so the callback is called sooner.
143
130
  PAGE_ACTIVITY_VALIDATION_DELAY
144
131
  )
145
132
 
@@ -169,10 +156,7 @@ function startClickAction(
169
156
  clickActionBase,
170
157
  startEvent
171
158
  )
172
-
173
- if (configuration.trackFrustrations) {
174
- appendClickToClickChain(click)
175
- }
159
+ appendClickToClickChain(click)
176
160
  var _waitPageActivityEnd = waitPageActivityEnd(
177
161
  lifeCycle,
178
162
  domMutationObservable,
@@ -196,18 +180,6 @@ function startClickAction(
196
180
  } else {
197
181
  click.stop()
198
182
  }
199
-
200
- // Validate or discard the click only if we don't track frustrations. It'll be done when
201
- // the click chain is finalized.
202
- if (!configuration.trackFrustrations) {
203
- if (!pageActivityEndEvent.hadActivity) {
204
- // If we are not tracking frustrations, we should discard the click to keep backward
205
- // compatibility.
206
- click.discard()
207
- } else {
208
- click.validate()
209
- }
210
- }
211
183
  }
212
184
  },
213
185
  CLICK_ACTION_MAX_DURATION
@@ -1,5 +1,5 @@
1
1
  import { toValidEntry } from './resourceUtils'
2
- import { map, filter } from '@cloudcare/browser-core'
2
+ import { map, filter, addDuration } from '@cloudcare/browser-core'
3
3
 
4
4
  /**
5
5
  * Look for corresponding timing in resource timing buffer
@@ -26,7 +26,7 @@ export function matchRequestTiming(request) {
26
26
  var candidates = map(sameNameEntries, function (entry) {
27
27
  return entry.toJSON()
28
28
  })
29
-
29
+
30
30
  candidates = filter(candidates, toValidEntry)
31
31
  candidates = filter(candidates, function (entry) {
32
32
  return isBetween(
@@ -42,20 +42,11 @@ export function matchRequestTiming(request) {
42
42
  if (candidates.length === 1) {
43
43
  return candidates[0]
44
44
  }
45
-
46
- if (candidates.length === 2 && firstCanBeOptionRequest(candidates)) {
47
- return candidates[1]
48
- }
49
-
50
45
  return
51
46
  }
52
47
 
53
- function firstCanBeOptionRequest(correspondingEntries) {
54
- return endTime(correspondingEntries[0]) <= correspondingEntries[1].startTime
55
- }
56
-
57
48
  function endTime(timing) {
58
- return timing.startTime + timing.duration
49
+ return addDuration(timing.startTime, timing.duration)
59
50
  }
60
51
 
61
52
  function isBetween(timing, start, end) {
@@ -63,6 +54,6 @@ function isBetween(timing, start, end) {
63
54
  var errorMargin = 1
64
55
  return (
65
56
  timing.startTime >= start - errorMargin &&
66
- endTime(timing) <= end + errorMargin
57
+ endTime(timing) <= addDuration(end, errorMargin)
67
58
  )
68
59
  }
@@ -11,7 +11,10 @@ import {
11
11
  RequestType,
12
12
  ResourceType,
13
13
  RumEventType,
14
- LifeCycleEventType
14
+ LifeCycleEventType,
15
+ toServerDuration,
16
+ some,
17
+ isNullUndefinedDefaultValue
15
18
  } from '@cloudcare/browser-core'
16
19
  import { matchRequestTiming } from './matchRequestTiming'
17
20
  import {
@@ -24,13 +27,23 @@ import {
24
27
  isCacheHit,
25
28
  isResourceUrlLimit
26
29
  } from './resourceUtils'
27
- import { supportPerformanceEntry } from '../../performanceCollection'
28
- export function startResourceCollection(lifeCycle, configuration) {
30
+ import { PageState } from '../../contexts/pageStateHistory.js'
31
+ export function startResourceCollection(
32
+ lifeCycle,
33
+ configuration,
34
+ sessionManager,
35
+ pageStateHistory
36
+ ) {
29
37
  lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
30
- lifeCycle.notify(
31
- LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
32
- processRequest(request)
38
+ var rawEvent = processRequest(
39
+ request,
40
+ configuration,
41
+ sessionManager,
42
+ pageStateHistory
33
43
  )
44
+ if (rawEvent) {
45
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
46
+ }
34
47
  })
35
48
 
36
49
  lifeCycle.subscribe(
@@ -43,27 +56,62 @@ export function startResourceCollection(lifeCycle, configuration) {
43
56
  !isRequestKind(entry) &&
44
57
  !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)
45
58
  ) {
46
- lifeCycle.notify(
47
- LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
48
- processResourceEntry(entry)
59
+ var rawEvent = processResourceEntry(
60
+ entry,
61
+ configuration,
62
+ sessionManager,
63
+ pageStateHistory
49
64
  )
65
+ if (rawEvent) {
66
+ lifeCycle.notify(
67
+ LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
68
+ rawEvent
69
+ )
70
+ }
50
71
  }
51
72
  }
52
73
  }
53
74
  )
54
75
  }
55
76
 
56
- function processRequest(request) {
57
- var type =
58
- request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
77
+ function processRequest(
78
+ request,
79
+ configuration,
80
+ sessionManager,
81
+ pageStateHistory
82
+ ) {
59
83
  var matchingTiming = matchRequestTiming(request)
60
84
  var startClocks = matchingTiming
61
85
  ? relativeToClocks(matchingTiming.startTime)
62
86
  : request.startClocks
87
+ var shouldIndex = shouldIndexResource(
88
+ configuration,
89
+ sessionManager,
90
+ startClocks
91
+ )
92
+ var tracingInfo = computeRequestTracingInfo(request)
93
+ if (!shouldIndex && !tracingInfo) {
94
+ return
95
+ }
96
+ var type =
97
+ request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
63
98
  var correspondingTimingOverrides = matchingTiming
64
99
  ? computePerformanceEntryMetrics(matchingTiming)
65
100
  : undefined
66
- var tracingInfo = computeRequestTracingInfo(request)
101
+
102
+ var duration = computeRequestDuration(
103
+ pageStateHistory,
104
+ startClocks,
105
+ request.duration
106
+ )
107
+ var pageStateInfo = computePageStateInfo(
108
+ pageStateHistory,
109
+ startClocks,
110
+ isNullUndefinedDefaultValue(
111
+ matchingTiming && matchingTiming.duration,
112
+ request.duration
113
+ )
114
+ )
67
115
  var urlObj = urlParse(request.url).getParse()
68
116
  var resourceEvent = extend2Lev(
69
117
  {
@@ -71,7 +119,7 @@ function processRequest(request) {
71
119
  resource: {
72
120
  id: UUID,
73
121
  type: type,
74
- duration: msToNs(request.duration),
122
+ duration: duration,
75
123
  method: request.method,
76
124
  status: request.status,
77
125
  statusGroup: getStatusGroup(request.status),
@@ -84,14 +132,14 @@ function processRequest(request) {
84
132
  type: RumEventType.RESOURCE
85
133
  },
86
134
  tracingInfo,
87
- correspondingTimingOverrides
135
+ correspondingTimingOverrides,
136
+ pageStateInfo
88
137
  )
89
138
  return {
90
139
  startTime: startClocks.relative,
91
140
  rawRumEvent: resourceEvent,
92
141
  domainContext: {
93
- performanceEntry:
94
- matchingTiming && toPerformanceEntryRepresentation(matchingTiming),
142
+ performanceEntry: matchingTiming,
95
143
  xhr: request.xhr,
96
144
  response: request.response,
97
145
  requestInput: request.input,
@@ -101,10 +149,24 @@ function processRequest(request) {
101
149
  }
102
150
  }
103
151
 
104
- function processResourceEntry(entry) {
152
+ function processResourceEntry(
153
+ entry,
154
+ configuration,
155
+ sessionManager,
156
+ pageStateHistory
157
+ ) {
158
+ var startClocks = relativeToClocks(entry.startTime)
159
+ var shouldIndex = shouldIndexResource(
160
+ configuration,
161
+ sessionManager,
162
+ startClocks
163
+ )
164
+ var tracingInfo = computeEntryTracingInfo(entry)
165
+ if (!shouldIndex && !tracingInfo) {
166
+ return
167
+ }
105
168
  var type = computeResourceKind(entry)
106
169
  var entryMetrics = computePerformanceEntryMetrics(entry)
107
- var tracingInfo = computeEntryTracingInfo(entry)
108
170
  var urlObj = urlParse(entry.name).getParse()
109
171
  var statusCode = ''
110
172
  if (is304(entry)) {
@@ -112,7 +174,12 @@ function processResourceEntry(entry) {
112
174
  } else if (isCacheHit(entry)) {
113
175
  statusCode = 200
114
176
  }
115
- var startClocks = relativeToClocks(entry.startTime)
177
+ var pageStateInfo = computePageStateInfo(
178
+ pageStateHistory,
179
+ startClocks,
180
+ entry.duration
181
+ )
182
+
116
183
  var resourceEvent = extend2Lev(
117
184
  {
118
185
  date: startClocks.timeStamp,
@@ -131,16 +198,20 @@ function processResourceEntry(entry) {
131
198
  type: RumEventType.RESOURCE
132
199
  },
133
200
  tracingInfo,
134
- entryMetrics
201
+ entryMetrics,
202
+ pageStateInfo
135
203
  )
136
204
  return {
137
205
  startTime: startClocks.relative,
138
206
  rawRumEvent: resourceEvent,
139
207
  domainContext: {
140
- performanceEntry: toPerformanceEntryRepresentation(entry)
208
+ performanceEntry: entry
141
209
  }
142
210
  }
143
211
  }
212
+ function shouldIndexResource(configuration, sessionManager, resourceStart) {
213
+ return sessionManager.findTrackedSession(resourceStart.relative)
214
+ }
144
215
 
145
216
  function computePerformanceEntryMetrics(timing) {
146
217
  return {
@@ -154,12 +225,7 @@ function computePerformanceEntryMetrics(timing) {
154
225
  )
155
226
  }
156
227
  }
157
- function toPerformanceEntryRepresentation(entry) {
158
- if (supportPerformanceEntry() && entry instanceof PerformanceEntry) {
159
- entry.toJSON()
160
- }
161
- return entry
162
- }
228
+
163
229
  function computeRequestTracingInfo(request) {
164
230
  var hasBeenTraced = request.traceSampled && request.traceId && request.spanId
165
231
  if (!hasBeenTraced) {
@@ -173,7 +239,27 @@ function computeRequestTracingInfo(request) {
173
239
  resource: { id: UUID() }
174
240
  }
175
241
  }
176
-
242
+ function computePageStateInfo(pageStateHistory, startClocks, duration) {
243
+ return {
244
+ _gc: {
245
+ page_states: pageStateHistory.findAll(startClocks.relative, duration),
246
+ page_was_discarded: String(document.wasDiscarded)
247
+ }
248
+ }
249
+ }
250
+ function computeRequestDuration(pageStateHistory, startClocks, duration) {
251
+ const requestCrosseds = pageStateHistory.findAll(
252
+ startClocks.relative,
253
+ duration
254
+ )
255
+ var requestCrossedFrozenState
256
+ if (requestCrosseds) {
257
+ requestCrossedFrozenState = some(requestCrosseds, function (pageState) {
258
+ return pageState.state === PageState.FROZEN
259
+ })
260
+ }
261
+ return !requestCrossedFrozenState ? toServerDuration(duration) : undefined
262
+ }
177
263
  function computeEntryTracingInfo(entry) {
178
264
  return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined
179
265
  }