@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
@@ -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
 
@@ -3,19 +3,17 @@ import {
3
3
  relativeToClocks,
4
4
  RumEventType,
5
5
  LifeCycleEventType,
6
- UUID
6
+ UUID,
7
+ RumLongTaskEntryType
7
8
  } from '@cloudcare/browser-core'
8
- export function startLongTaskCollection(lifeCycle, sessionManager) {
9
+ import { RumPerformanceEntryType } from '../../performanceObservable'
10
+ export function startLongTaskCollection(lifeCycle) {
9
11
  lifeCycle.subscribe(
10
12
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
11
13
  function (entries) {
12
14
  for (var i = 0; i < entries.length; i++) {
13
15
  var entry = entries[i]
14
- if (entry.entryType !== 'longtask') {
15
- return
16
- }
17
- var session = sessionManager.findTrackedSession(entry.startTime)
18
- if (!session) {
16
+ if (entry.entryType !== RumPerformanceEntryType.LONG_TASK) {
19
17
  break
20
18
  }
21
19
 
@@ -24,6 +22,7 @@ export function startLongTaskCollection(lifeCycle, sessionManager) {
24
22
  date: startClocks.timeStamp,
25
23
  long_task: {
26
24
  id: UUID(),
25
+ entryType: RumLongTaskEntryType.LONG_TASK,
27
26
  duration: toServerDuration(entry.duration)
28
27
  },
29
28
  type: RumEventType.LONG_TASK
@@ -31,7 +30,7 @@ export function startLongTaskCollection(lifeCycle, sessionManager) {
31
30
  lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
32
31
  rawRumEvent: rawRumEvent,
33
32
  startTime: startClocks.relative,
34
- domainContext: { performanceEntry: entry.toJSON() }
33
+ domainContext: { performanceEntry: entry }
35
34
  })
36
35
  }
37
36
  }
@@ -1,5 +1,8 @@
1
- import { isValidEntry } from './resourceUtils'
2
- import { map, filter, addDuration, WeakSet } from '@cloudcare/browser-core'
1
+ import {
2
+ hasValidResourceEntryDuration,
3
+ hasValidResourceEntryTimings
4
+ } from './resourceUtils'
5
+ import { filter, addDuration, WeakSet } from '@cloudcare/browser-core'
3
6
 
4
7
  var alreadyMatchedEntries = new WeakSet()
5
8
  /**
@@ -15,7 +18,7 @@ var alreadyMatchedEntries = new WeakSet()
15
18
  * - if two following timings match (OPTIONS request), return the timing for the actual request
16
19
  * - otherwise we can't decide, return undefined
17
20
  */
18
- export function matchRequestTiming(request) {
21
+ export function matchRequestResourceEntry(request) {
19
22
  if (!performance || !('getEntriesByName' in performance)) {
20
23
  return
21
24
  }
@@ -29,7 +32,10 @@ export function matchRequestTiming(request) {
29
32
  })
30
33
 
31
34
  candidates = filter(candidates, function (entry) {
32
- return isValidEntry(entry)
35
+ return (
36
+ hasValidResourceEntryDuration(entry) &&
37
+ hasValidResourceEntryTimings(entry)
38
+ )
33
39
  })
34
40
  candidates = filter(candidates, function (entry) {
35
41
  return isBetween(
@@ -10,93 +10,85 @@ import {
10
10
  ResourceType,
11
11
  RumEventType,
12
12
  LifeCycleEventType,
13
- toServerDuration,
14
- some,
15
- isNullUndefinedDefaultValue
13
+ toServerDuration
16
14
  } from '@cloudcare/browser-core'
17
- import { matchRequestTiming } from './matchRequestTiming'
15
+ import { matchRequestResourceEntry } from './matchRequestResourceEntry'
18
16
  import {
19
17
  computePerformanceResourceDetails,
20
- computePerformanceResourceDuration,
21
- computeResourceKind,
22
- computeSize,
23
- isRequestKind,
24
- is304,
25
- isCacheHit,
18
+ computeResourceEntryDuration,
19
+ computeResourceEntryType,
20
+ computeResourceEntrySize,
21
+ isResourceEntryRequestType,
26
22
  isResourceUrlLimit,
27
23
  isLongDataUrl,
28
24
  sanitizeDataUrl
29
25
  } from './resourceUtils'
30
- import { PageState } from '../../contexts/pageStateHistory.js'
26
+ import { PageState } from '../../contexts/pageStateHistory'
27
+ import {
28
+ createPerformanceObservable,
29
+ RumPerformanceEntryType
30
+ } from '../../performanceObservable'
31
+ import { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming'
31
32
  export function startResourceCollection(
32
33
  lifeCycle,
33
34
  configuration,
34
- sessionManager,
35
- pageStateHistory
35
+ pageStateHistory,
36
+ retrieveInitialDocumentResourceTimingImpl
36
37
  ) {
38
+ if (typeof retrieveInitialDocumentResourceTimingImpl === 'undefined') {
39
+ retrieveInitialDocumentResourceTimingImpl =
40
+ retrieveInitialDocumentResourceTiming
41
+ }
37
42
  lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
38
- var rawEvent = processRequest(
39
- request,
40
- configuration,
41
- sessionManager,
42
- pageStateHistory
43
- )
43
+ var rawEvent = processRequest(request, pageStateHistory)
44
44
  if (rawEvent) {
45
45
  lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
46
46
  }
47
47
  })
48
-
49
- lifeCycle.subscribe(
50
- LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
51
- function (entries) {
52
- for (var i = 0; i < entries.length; i++) {
53
- var entry = entries[i]
54
- if (
55
- entry.entryType === 'resource' &&
56
- !isRequestKind(entry) &&
57
- !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)
58
- ) {
59
- var rawEvent = processResourceEntry(
60
- entry,
61
- configuration,
62
- sessionManager,
63
- pageStateHistory
64
- )
65
- if (rawEvent) {
66
- lifeCycle.notify(
67
- LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
68
- rawEvent
69
- )
70
- }
48
+ var performanceResourceSubscription = createPerformanceObservable(
49
+ configuration,
50
+ {
51
+ type: RumPerformanceEntryType.RESOURCE,
52
+ buffered: true
53
+ }
54
+ ).subscribe(function (entries) {
55
+ for (var entry of entries) {
56
+ if (
57
+ !isResourceEntryRequestType(entry) &&
58
+ !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)
59
+ ) {
60
+ var rawEvent = processResourceEntry(entry, configuration)
61
+ if (rawEvent) {
62
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
71
63
  }
72
64
  }
73
65
  }
74
- )
66
+ })
67
+
68
+ retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {
69
+ var rawEvent = processResourceEntry(timing, configuration)
70
+ if (rawEvent) {
71
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
72
+ }
73
+ })
74
+ return {
75
+ stop: function () {
76
+ performanceResourceSubscription.unsubscribe()
77
+ }
78
+ }
75
79
  }
76
80
 
77
- function processRequest(
78
- request,
79
- configuration,
80
- sessionManager,
81
- pageStateHistory
82
- ) {
83
- var matchingTiming = matchRequestTiming(request)
81
+ function processRequest(request, pageStateHistory) {
82
+ var matchingTiming = matchRequestResourceEntry(request)
84
83
  var startClocks = matchingTiming
85
84
  ? relativeToClocks(matchingTiming.startTime)
86
85
  : request.startClocks
87
- var shouldIndex = shouldIndexResource(
88
- configuration,
89
- sessionManager,
90
- startClocks
91
- )
92
86
  var tracingInfo = computeRequestTracingInfo(request)
93
- if (!shouldIndex && !tracingInfo) {
94
- return
95
- }
87
+
96
88
  var type =
97
89
  request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
98
90
  var correspondingTimingOverrides = matchingTiming
99
- ? computePerformanceEntryMetrics(matchingTiming)
91
+ ? computeResourceEntryMetrics(matchingTiming)
100
92
  : undefined
101
93
 
102
94
  var duration = computeRequestDuration(
@@ -104,14 +96,7 @@ function processRequest(
104
96
  startClocks,
105
97
  request.duration
106
98
  )
107
- // var pageStateInfo = computePageStateInfo(
108
- // pageStateHistory,
109
- // startClocks,
110
- // isNullUndefinedDefaultValue(
111
- // matchingTiming && matchingTiming.duration,
112
- // request.duration
113
- // )
114
- // )
99
+
115
100
  var urlObj = urlParse(request.url).getParse()
116
101
  var resourceEvent = extend2Lev(
117
102
  {
@@ -145,44 +130,19 @@ function processRequest(
145
130
  response: request.response,
146
131
  requestInput: request.input,
147
132
  requestInit: request.init,
148
- error: request.error
133
+ error: request.error,
134
+ isAborted: request.isAborted,
135
+ handlingStack: request.handlingStack
149
136
  }
150
137
  }
151
138
  }
152
139
 
153
- function processResourceEntry(
154
- entry,
155
- configuration,
156
- sessionManager,
157
- pageStateHistory
158
- ) {
140
+ function processResourceEntry(entry, configuration) {
159
141
  var startClocks = relativeToClocks(entry.startTime)
160
- var shouldIndex = shouldIndexResource(
161
- configuration,
162
- sessionManager,
163
- startClocks
164
- )
165
- var tracingInfo = computeEntryTracingInfo(entry)
166
- if (!shouldIndex && !tracingInfo) {
167
- return
168
- }
169
- var type = computeResourceKind(entry)
170
- var entryMetrics = computePerformanceEntryMetrics(entry)
142
+ var tracingInfo = computeResourceEntryTracingInfo(entry)
143
+ var type = computeResourceEntryType(entry)
144
+ var entryMetrics = computeResourceEntryMetrics(entry)
171
145
  var urlObj = urlParse(entry.name).getParse()
172
- var statusCode = ''
173
- if (entry.responseStatus !== 0) {
174
- statusCode = entry.responseStatus
175
- } else if (is304(entry)) {
176
- statusCode = 304
177
- } else if (isCacheHit(entry)) {
178
- statusCode = 200
179
- }
180
- // var pageStateInfo = computePageStateInfo(
181
- // pageStateHistory,
182
- // startClocks,
183
- // entry.duration
184
- // )
185
-
186
146
  var resourceEvent = extend2Lev(
187
147
  {
188
148
  date: startClocks.timeStamp,
@@ -195,8 +155,8 @@ function processResourceEntry(
195
155
  urlPathGroup: replaceNumberCharByPath(urlObj.Path),
196
156
  urlQuery: getQueryParamsFromUrl(entry.name),
197
157
  method: 'GET',
198
- status: statusCode,
199
- statusGroup: getStatusGroup(statusCode)
158
+ status: discardZeroStatus(entry.responseStatus),
159
+ statusGroup: getStatusGroup(entry.responseStatus)
200
160
  },
201
161
  type: RumEventType.RESOURCE
202
162
  },
@@ -211,19 +171,16 @@ function processResourceEntry(
211
171
  }
212
172
  }
213
173
  }
214
- function shouldIndexResource(configuration, sessionManager, resourceStart) {
215
- return sessionManager.findTrackedSession(resourceStart.relative)
216
- }
217
174
 
218
- function computePerformanceEntryMetrics(timing) {
175
+ function computeResourceEntryMetrics(entry) {
219
176
  return {
220
177
  resource: extend2Lev(
221
178
  {},
222
179
  {
223
- duration: computePerformanceResourceDuration(timing)
180
+ duration: computeResourceEntryDuration(entry)
224
181
  },
225
- computeSize(timing),
226
- computePerformanceResourceDetails(timing)
182
+ computeResourceEntrySize(entry),
183
+ computePerformanceResourceDetails(entry)
227
184
  )
228
185
  }
229
186
  }
@@ -241,14 +198,7 @@ function computeRequestTracingInfo(request) {
241
198
  resource: { id: UUID() }
242
199
  }
243
200
  }
244
- // function computePageStateInfo(pageStateHistory, startClocks, duration) {
245
- // return {
246
- // _gc: {
247
- // page_states: pageStateHistory.findAll(startClocks.relative, duration),
248
- // page_was_discarded: String(document.wasDiscarded)
249
- // }
250
- // }
251
- // }
201
+
252
202
  function computeRequestDuration(pageStateHistory, startClocks, duration) {
253
203
  return !pageStateHistory.wasInPageStateDuringPeriod(
254
204
  PageState.FROZEN,
@@ -258,6 +208,13 @@ function computeRequestDuration(pageStateHistory, startClocks, duration) {
258
208
  ? toServerDuration(duration)
259
209
  : undefined
260
210
  }
261
- function computeEntryTracingInfo(entry) {
211
+ function computeResourceEntryTracingInfo(entry) {
262
212
  return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined
263
213
  }
214
+ /**
215
+ * The status is 0 for cross-origin resources without CORS headers, so the status is meaningless, and we shouldn't report it
216
+ * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
217
+ */
218
+ function discardZeroStatus(statusCode) {
219
+ return statusCode === 0 ? undefined : statusCode
220
+ }
@@ -75,8 +75,8 @@ var RESOURCE_TYPES = [
75
75
  ]
76
76
  ]
77
77
 
78
- export function computeResourceKind(timing) {
79
- var url = timing.name
78
+ export function computeResourceEntryType(entry) {
79
+ var url = entry.name
80
80
  if (!isValidUrl(url)) {
81
81
  return ResourceType.OTHER
82
82
  }
@@ -85,7 +85,8 @@ export function computeResourceKind(timing) {
85
85
  each(RESOURCE_TYPES, function (res) {
86
86
  var _type = res[0],
87
87
  isType = res[1]
88
- if (isType(timing.initiatorType, path)) {
88
+
89
+ if (isType(entry.initiatorType, path)) {
89
90
  type = _type
90
91
  return false
91
92
  }
@@ -102,10 +103,9 @@ function areInOrder() {
102
103
  return true
103
104
  }
104
105
 
105
- export function isRequestKind(timing) {
106
+ export function isResourceEntryRequestType(entry) {
106
107
  return (
107
- timing.initiatorType === 'xmlhttprequest' ||
108
- timing.initiatorType === 'fetch'
108
+ entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch'
109
109
  )
110
110
  }
111
111
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/
@@ -123,7 +123,7 @@ export function getStrSize(candidate) {
123
123
  export function isResourceUrlLimit(name, limitSize) {
124
124
  return getStrSize(name) > limitSize
125
125
  }
126
- export function computePerformanceResourceDuration(entry) {
126
+ export function computeResourceEntryDuration(entry) {
127
127
  // Safari duration is always 0 on timings blocked by cross origin policies.
128
128
  if (entry.duration === 0 && entry.startTime < entry.responseEnd) {
129
129
  return msToNs(entry.responseEnd - entry.startTime)
@@ -221,7 +221,7 @@ export function isCacheHit(entry) {
221
221
 
222
222
  // · loadEventEnd:返回当前网页load事件的回调函数运行结束时的Unix毫秒时间戳。如果该事件还没有发生,返回0
223
223
  export function computePerformanceResourceDetails(entry) {
224
- if (!isValidEntry(entry)) {
224
+ if (!hasValidResourceEntryTimings(entry)) {
225
225
  return undefined
226
226
  }
227
227
 
@@ -281,8 +281,10 @@ export function computePerformanceResourceDetails(entry) {
281
281
  }
282
282
  return details
283
283
  }
284
-
285
- export function isValidEntry(entry) {
284
+ export function hasValidResourceEntryDuration(entry) {
285
+ return entry.duration >= 0
286
+ }
287
+ export function hasValidResourceEntryTimings(entry) {
286
288
  // Ensure timings are in the right order. On top of filtering out potential invalid
287
289
  // RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be
288
290
  // collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing
@@ -364,7 +366,7 @@ function formatTiming(origin, start, end) {
364
366
  }
365
367
  }
366
368
 
367
- export function computeSize(entry) {
369
+ export function computeResourceEntrySize(entry) {
368
370
  // Make sure a request actually occurred
369
371
  if (entry.startTime < entry.responseStart) {
370
372
  return {
@@ -0,0 +1,45 @@
1
+ import { runOnReadyState, assign } from '@cloudcare/browser-core'
2
+ import {
3
+ RumPerformanceEntryType,
4
+ supportPerformanceTimingEvent
5
+ } from '../../performanceObservable'
6
+ import { FAKE_INITIAL_DOCUMENT } from './resourceUtils'
7
+ import { computeRelativePerformanceTiming } from '../../performanceUtils'
8
+ export function retrieveInitialDocumentResourceTiming(configuration, callback) {
9
+ runOnReadyState('interactive', function () {
10
+ var timing
11
+ var forcedAttributes = {
12
+ entryType: RumPerformanceEntryType.RESOURCE,
13
+ initiatorType: FAKE_INITIAL_DOCUMENT,
14
+ toJSON: function () {
15
+ return assign({}, timing, { toJSON: undefined })
16
+ }
17
+ }
18
+ if (
19
+ supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION) &&
20
+ performance.getEntriesByType(RumPerformanceEntryType.NAVIGATION).length >
21
+ 0
22
+ ) {
23
+ var navigationEntry = performance.getEntriesByType(
24
+ RumPerformanceEntryType.NAVIGATION
25
+ )[0]
26
+ timing = assign(navigationEntry.toJSON(), forcedAttributes)
27
+ } else {
28
+ var relativePerformanceTiming = computeRelativePerformanceTiming()
29
+ timing = assign(
30
+ relativePerformanceTiming,
31
+ {
32
+ decodedBodySize: 0,
33
+ encodedBodySize: 0,
34
+ transferSize: 0,
35
+ renderBlockingStatus: 'non-blocking',
36
+ duration: relativePerformanceTiming.responseEnd,
37
+ name: window.location.href,
38
+ startTime: 0
39
+ },
40
+ forcedAttributes
41
+ )
42
+ }
43
+ callback(timing)
44
+ })
45
+ }
@@ -35,8 +35,9 @@ export function trackCommonViewMetrics(
35
35
  var stopScrollMetricsTracking = _trackScrollMetrics.stop
36
36
  var stopCLSTracking
37
37
  var _trackCumulativeLayoutShift = trackCumulativeLayoutShift(
38
- lifeCycle,
39
38
  configuration,
39
+ lifeCycle,
40
+ viewStart.relative,
40
41
  function (cumulativeLayoutShift) {
41
42
  commonViewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
42
43
  scheduleViewUpdate()