@cloudcare/browser-rum 3.1.23 → 3.1.24
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.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +1 -1
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/domain/firstInputPolyfill.js +83 -0
- package/cjs/domain/firstInputPolyfill.js.map +1 -0
- package/cjs/domain/performanceCollection.js +4 -90
- package/cjs/domain/performanceCollection.js.map +1 -1
- package/cjs/domain/performanceObservable.js +11 -0
- package/cjs/domain/performanceObservable.js.map +1 -1
- package/cjs/domain/performanceUtils.js +30 -2
- package/cjs/domain/performanceUtils.js.map +1 -1
- package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +10 -2
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +4 -20
- package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +6 -3
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstInput.js +8 -3
- package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +4 -4
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +21 -6
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +6 -4
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js +19 -24
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +1 -1
- package/esm/boot/rum.js.map +1 -1
- package/esm/domain/firstInputPolyfill.js +77 -0
- package/esm/domain/firstInputPolyfill.js.map +1 -0
- package/esm/domain/performanceCollection.js +4 -90
- package/esm/domain/performanceCollection.js.map +1 -1
- package/esm/domain/performanceObservable.js +11 -1
- package/esm/domain/performanceObservable.js.map +1 -1
- package/esm/domain/performanceUtils.js +29 -2
- package/esm/domain/performanceUtils.js.map +1 -1
- package/esm/domain/replay/deflate/deflateWorker.js +1 -1
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +11 -3
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +6 -22
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +8 -5
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js +10 -5
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +4 -4
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +23 -8
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +7 -5
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +21 -26
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/rum.js +1 -1
- package/src/domain/firstInputPolyfill.js +92 -0
- package/src/domain/performanceCollection.js +5 -112
- package/src/domain/performanceObservable.js +17 -2
- package/src/domain/performanceUtils.js +37 -2
- package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +37 -26
- package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +6 -35
- package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -2
- package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +26 -19
- package/src/domain/rumEventsCollection/view/trackFirstInput.js +40 -42
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -4
- package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +43 -35
- package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +32 -32
- package/src/domain/rumEventsCollection/view/trackNavigationTimings.js +29 -31
- package/src/domain/rumEventsCollection/view/trackViews.js +1 -6
|
@@ -33,16 +33,8 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
33
33
|
var handlePerformanceEntryList = monitor(function (entries) {
|
|
34
34
|
handleRumPerformanceEntries(lifeCycle, entries.getEntries())
|
|
35
35
|
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
RumPerformanceEntryType.PAINT
|
|
39
|
-
]
|
|
40
|
-
var experimentalEntries = [
|
|
41
|
-
RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT,
|
|
42
|
-
RumPerformanceEntryType.FIRST_INPUT,
|
|
43
|
-
RumPerformanceEntryType.LAYOUT_SHIFT,
|
|
44
|
-
RumPerformanceEntryType.EVENT
|
|
45
|
-
]
|
|
36
|
+
|
|
37
|
+
var experimentalEntries = [RumPerformanceEntryType.LAYOUT_SHIFT]
|
|
46
38
|
try {
|
|
47
39
|
// Experimental entries are not retrieved by performance.getEntries()
|
|
48
40
|
// use a single PerformanceObserver with buffered flag by type
|
|
@@ -53,26 +45,16 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
53
45
|
)
|
|
54
46
|
observer.observe({
|
|
55
47
|
type: type,
|
|
56
|
-
buffered: true
|
|
57
|
-
// durationThreshold only impact PerformanceEventTiming entries used for INP computation which requires a threshold at 40 (default is 104ms)
|
|
58
|
-
// cf: https://github.com/GoogleChrome/web-vitals/blob/3806160ffbc93c3c4abf210a167b81228172b31c/src/onINP.ts#L209
|
|
59
|
-
durationThreshold: 40
|
|
48
|
+
buffered: true
|
|
60
49
|
})
|
|
61
50
|
cleanupTasks.push(function () {
|
|
62
51
|
observer.disconnect()
|
|
63
52
|
})
|
|
64
53
|
})
|
|
65
|
-
} catch (e) {
|
|
66
|
-
// Some old browser versions (ex: chrome 67) don't support the PerformanceObserver type and buffered options
|
|
67
|
-
// In these cases, fallback to PerformanceObserver with entryTypes
|
|
68
|
-
each(experimentalEntries, function (type) {
|
|
69
|
-
mainEntries.push(type)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
54
|
+
} catch (e) {}
|
|
72
55
|
var mainObserver = new PerformanceObserver(handlePerformanceEntryList)
|
|
73
|
-
// mainObserver.observe({ entryTypes: mainEntries })
|
|
74
56
|
try {
|
|
75
|
-
mainObserver.observe({ entryTypes:
|
|
57
|
+
mainObserver.observe({ entryTypes: experimentalEntries })
|
|
76
58
|
cleanupTasks.push(function () {
|
|
77
59
|
mainObserver.disconnect()
|
|
78
60
|
})
|
|
@@ -90,12 +72,6 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
90
72
|
}
|
|
91
73
|
}
|
|
92
74
|
|
|
93
|
-
if (!supportPerformanceTimingEvent(RumPerformanceEntryType.FIRST_INPUT)) {
|
|
94
|
-
var _retrieveFirstInputTiming = retrieveFirstInputTiming(function (timing) {
|
|
95
|
-
return handleRumPerformanceEntries(lifeCycle, [timing])
|
|
96
|
-
})
|
|
97
|
-
cleanupTasks.push(_retrieveFirstInputTiming.stop)
|
|
98
|
-
}
|
|
99
75
|
return {
|
|
100
76
|
stop: function () {
|
|
101
77
|
each(cleanupTasks, function (task) {
|
|
@@ -105,89 +81,6 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
105
81
|
}
|
|
106
82
|
}
|
|
107
83
|
|
|
108
|
-
/**
|
|
109
|
-
* first-input timing entry polyfill based on
|
|
110
|
-
* https://github.com/GoogleChrome/web-vitals/blob/master/src/lib/polyfills/firstInputPolyfill.ts
|
|
111
|
-
*/
|
|
112
|
-
function retrieveFirstInputTiming(callback) {
|
|
113
|
-
var startTimeStamp = dateNow()
|
|
114
|
-
var timingSent = false
|
|
115
|
-
|
|
116
|
-
var listeners = addEventListeners(
|
|
117
|
-
window,
|
|
118
|
-
[
|
|
119
|
-
DOM_EVENT.CLICK,
|
|
120
|
-
DOM_EVENT.MOUSE_DOWN,
|
|
121
|
-
DOM_EVENT.KEY_DOWN,
|
|
122
|
-
DOM_EVENT.TOUCH_START,
|
|
123
|
-
DOM_EVENT.POINTER_DOWN
|
|
124
|
-
],
|
|
125
|
-
function (evt) {
|
|
126
|
-
// Only count cancelable events, which should trigger behavior important to the user.
|
|
127
|
-
if (!evt.cancelable) {
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// This timing will be used to compute the "first Input delay", which is the delta between
|
|
132
|
-
// when the system received the event (e.g. evt.timeStamp) and when it could run the callback
|
|
133
|
-
// (e.g. performance.now()).
|
|
134
|
-
var timing = {
|
|
135
|
-
entryType: RumPerformanceEntryType.FIRST_INPUT,
|
|
136
|
-
processingStart: relativeNow(),
|
|
137
|
-
processingEnd: relativeNow(),
|
|
138
|
-
startTime: evt.timeStamp,
|
|
139
|
-
duration: 0,
|
|
140
|
-
name: ''
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (evt.type === DOM_EVENT.POINTER_DOWN) {
|
|
144
|
-
sendTimingIfPointerIsNotCancelled(timing)
|
|
145
|
-
} else {
|
|
146
|
-
sendTiming(timing)
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
{ passive: true, capture: true }
|
|
150
|
-
)
|
|
151
|
-
var removeEventListeners = listeners.stop
|
|
152
|
-
/**
|
|
153
|
-
* Pointer events are a special case, because they can trigger main or compositor thread behavior.
|
|
154
|
-
* We differenciate these cases based on whether or not we see a pointercancel event, which are
|
|
155
|
-
* fired when we scroll. If we're scrolling we don't need to report input delay since FID excludes
|
|
156
|
-
* scrolling and pinch/zooming.
|
|
157
|
-
*/
|
|
158
|
-
function sendTimingIfPointerIsNotCancelled(timing) {
|
|
159
|
-
addEventListeners(
|
|
160
|
-
window,
|
|
161
|
-
[DOM_EVENT.POINTER_UP, DOM_EVENT.POINTER_CANCEL],
|
|
162
|
-
function (event) {
|
|
163
|
-
if (event.type === DOM_EVENT.POINTER_UP) {
|
|
164
|
-
sendTiming(timing)
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
{ once: true }
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function sendTiming(timing) {
|
|
172
|
-
if (!timingSent) {
|
|
173
|
-
timingSent = true
|
|
174
|
-
removeEventListeners()
|
|
175
|
-
// In some cases the recorded delay is clearly wrong, e.g. it's negative or it's larger than
|
|
176
|
-
// the time between now and when the page was loaded.
|
|
177
|
-
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/4
|
|
178
|
-
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/6
|
|
179
|
-
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/7
|
|
180
|
-
var delay = timing.processingStart - timing.startTime
|
|
181
|
-
if (delay >= 0 && delay < dateNow() - startTimeStamp) {
|
|
182
|
-
callback(timing)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
stop: removeEventListeners
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
84
|
function handleRumPerformanceEntries(lifeCycle, entries) {
|
|
192
85
|
var rumPerformanceEntries = entries.filter(function (entry) {
|
|
193
86
|
return objectHasValue(RumPerformanceEntryType, entry.entryType)
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
isAllowedRequestUrl,
|
|
11
11
|
hasValidResourceEntryDuration
|
|
12
12
|
} from './rumEventsCollection/resource/resourceUtils'
|
|
13
|
-
|
|
13
|
+
import { retrieveFirstInputTiming } from './firstInputPolyfill'
|
|
14
14
|
// We want to use a real enum (i.e. not a const enum) here, to be able to check whether an arbitrary
|
|
15
15
|
// string is an expected performance entry
|
|
16
16
|
// eslint-disable-next-line no-restricted-syntax
|
|
@@ -93,9 +93,24 @@ export function createPerformanceObservable(configuration, options) {
|
|
|
93
93
|
isObserverInitializing = false
|
|
94
94
|
|
|
95
95
|
manageResourceTimingBufferFull(configuration)
|
|
96
|
-
|
|
96
|
+
var stopFirstInputTiming
|
|
97
|
+
if (
|
|
98
|
+
!supportPerformanceTimingEvent(RumPerformanceEntryType.FIRST_INPUT) &&
|
|
99
|
+
options.type === RumPerformanceEntryType.FIRST_INPUT
|
|
100
|
+
) {
|
|
101
|
+
var _retrieveFirstInputTiming = retrieveFirstInputTiming(
|
|
102
|
+
configuration,
|
|
103
|
+
function (timing) {
|
|
104
|
+
handlePerformanceEntries([timing])
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
stopFirstInputTiming = _retrieveFirstInputTiming.stop
|
|
108
|
+
}
|
|
97
109
|
return function () {
|
|
98
110
|
observer.disconnect()
|
|
111
|
+
if (stopFirstInputTiming) {
|
|
112
|
+
stopFirstInputTiming()
|
|
113
|
+
}
|
|
99
114
|
clearTimeout(timeoutId)
|
|
100
115
|
}
|
|
101
116
|
})
|
|
@@ -1,6 +1,41 @@
|
|
|
1
|
-
import { getRelativeTime, isNumber } from '@cloudcare/browser-core'
|
|
1
|
+
import { getRelativeTime, isNumber, assign } from '@cloudcare/browser-core'
|
|
2
|
+
import {
|
|
3
|
+
supportPerformanceTimingEvent,
|
|
4
|
+
RumPerformanceEntryType
|
|
5
|
+
} from './performanceObservable'
|
|
2
6
|
|
|
3
|
-
export function
|
|
7
|
+
export function getNavigationEntry() {
|
|
8
|
+
if (supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION)) {
|
|
9
|
+
var navigationEntry = performance.getEntriesByType(
|
|
10
|
+
RumPerformanceEntryType.NAVIGATION
|
|
11
|
+
)[0]
|
|
12
|
+
if (navigationEntry) {
|
|
13
|
+
return navigationEntry
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var timings = computeTimingsFromDeprecatedPerformanceTiming()
|
|
18
|
+
var entry = assign(
|
|
19
|
+
{
|
|
20
|
+
entryType: RumPerformanceEntryType.NAVIGATION,
|
|
21
|
+
initiatorType: 'navigation',
|
|
22
|
+
name: window.location.href,
|
|
23
|
+
startTime: 0,
|
|
24
|
+
duration: timings.responseEnd,
|
|
25
|
+
decodedBodySize: 0,
|
|
26
|
+
encodedBodySize: 0,
|
|
27
|
+
transferSize: 0,
|
|
28
|
+
renderBlockingStatus: 'non-blocking',
|
|
29
|
+
toJSON: function () {
|
|
30
|
+
return assign({}, entry, { toJSON: undefined })
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
timings
|
|
34
|
+
)
|
|
35
|
+
return entry
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function computeTimingsFromDeprecatedPerformanceTiming() {
|
|
4
39
|
var result = {}
|
|
5
40
|
var timing = performance.timing
|
|
6
41
|
|
|
@@ -6,33 +6,44 @@ import {
|
|
|
6
6
|
UUID,
|
|
7
7
|
RumLongTaskEntryType
|
|
8
8
|
} from '@cloudcare/browser-core'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
import {
|
|
10
|
+
RumPerformanceEntryType,
|
|
11
|
+
createPerformanceObservable
|
|
12
|
+
} from '../../performanceObservable'
|
|
13
|
+
export function startLongTaskCollection(lifeCycle, configuration) {
|
|
14
|
+
var performanceLongTaskSubscription = createPerformanceObservable(
|
|
15
|
+
configuration,
|
|
16
|
+
{
|
|
17
|
+
type: RumPerformanceEntryType.LONG_TASK,
|
|
18
|
+
buffered: true
|
|
19
|
+
}
|
|
20
|
+
).subscribe(function (entries) {
|
|
21
|
+
for (var i = 0; i < entries.length; i++) {
|
|
22
|
+
var entry = entries[i]
|
|
23
|
+
if (entry.entryType !== RumPerformanceEntryType.LONG_TASK) {
|
|
24
|
+
break
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
|
|
31
|
-
rawRumEvent: rawRumEvent,
|
|
32
|
-
startTime: startClocks.relative,
|
|
33
|
-
domainContext: { performanceEntry: entry }
|
|
34
|
-
})
|
|
27
|
+
var startClocks = relativeToClocks(entry.startTime)
|
|
28
|
+
var rawRumEvent = {
|
|
29
|
+
date: startClocks.timeStamp,
|
|
30
|
+
long_task: {
|
|
31
|
+
id: UUID(),
|
|
32
|
+
entryType: RumLongTaskEntryType.LONG_TASK,
|
|
33
|
+
duration: toServerDuration(entry.duration)
|
|
34
|
+
},
|
|
35
|
+
type: RumEventType.LONG_TASK
|
|
35
36
|
}
|
|
37
|
+
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
|
|
38
|
+
rawRumEvent: rawRumEvent,
|
|
39
|
+
startTime: startClocks.relative,
|
|
40
|
+
domainContext: { performanceEntry: entry }
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
return {
|
|
45
|
+
stop: function () {
|
|
46
|
+
performanceLongTaskSubscription.unsubscribe()
|
|
36
47
|
}
|
|
37
|
-
|
|
48
|
+
}
|
|
38
49
|
}
|
|
@@ -1,45 +1,16 @@
|
|
|
1
1
|
import { runOnReadyState, assign } from '@cloudcare/browser-core'
|
|
2
|
-
import {
|
|
3
|
-
RumPerformanceEntryType,
|
|
4
|
-
supportPerformanceTimingEvent
|
|
5
|
-
} from '../../performanceObservable'
|
|
2
|
+
import { RumPerformanceEntryType } from '../../performanceObservable'
|
|
6
3
|
import { FAKE_INITIAL_DOCUMENT } from './resourceUtils'
|
|
7
|
-
import {
|
|
4
|
+
import { getNavigationEntry } from '../../performanceUtils'
|
|
8
5
|
export function retrieveInitialDocumentResourceTiming(configuration, callback) {
|
|
9
6
|
runOnReadyState('interactive', function () {
|
|
10
|
-
var
|
|
11
|
-
var forcedAttributes = {
|
|
7
|
+
var entry = assign(getNavigationEntry().toJSON(), {
|
|
12
8
|
entryType: RumPerformanceEntryType.RESOURCE,
|
|
13
9
|
initiatorType: FAKE_INITIAL_DOCUMENT,
|
|
14
10
|
toJSON: function () {
|
|
15
|
-
return assign({},
|
|
11
|
+
return assign({}, entry, { toJSON: undefined })
|
|
16
12
|
}
|
|
17
|
-
}
|
|
18
|
-
|
|
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)
|
|
13
|
+
})
|
|
14
|
+
callback(entry)
|
|
44
15
|
})
|
|
45
16
|
}
|
|
@@ -47,8 +47,7 @@ export function trackCommonViewMetrics(
|
|
|
47
47
|
var _trackInteractionToNextPaint = trackInteractionToNextPaint(
|
|
48
48
|
configuration,
|
|
49
49
|
viewStart.relative,
|
|
50
|
-
loadingType
|
|
51
|
-
lifeCycle
|
|
50
|
+
loadingType
|
|
52
51
|
)
|
|
53
52
|
var stopINPTracking = _trackInteractionToNextPaint.stop
|
|
54
53
|
var getInteractionToNextPaint =
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import { find,
|
|
2
|
-
import {
|
|
1
|
+
import { find, ONE_MINUTE } from '@cloudcare/browser-core'
|
|
2
|
+
import {
|
|
3
|
+
RumPerformanceEntryType,
|
|
4
|
+
createPerformanceObservable
|
|
5
|
+
} from '../../performanceObservable'
|
|
3
6
|
export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE
|
|
4
|
-
export function trackFirstContentfulPaint(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
export function trackFirstContentfulPaint(
|
|
8
|
+
configuration,
|
|
9
|
+
firstHidden,
|
|
10
|
+
callback
|
|
11
|
+
) {
|
|
12
|
+
var performanceSubscription = createPerformanceObservable(configuration, {
|
|
13
|
+
type: RumPerformanceEntryType.PAINT,
|
|
14
|
+
buffered: true
|
|
15
|
+
}).subscribe(function (entries) {
|
|
16
|
+
var fcpEntry = find(entries, function (entry) {
|
|
17
|
+
return (
|
|
18
|
+
entry.entryType === RumPerformanceEntryType.PAINT &&
|
|
19
|
+
entry.name === 'first-contentful-paint' &&
|
|
20
|
+
entry.startTime < firstHidden.getTimeStamp() &&
|
|
21
|
+
entry.startTime < TIMING_MAXIMUM_DELAY
|
|
22
|
+
)
|
|
23
|
+
})
|
|
24
|
+
if (fcpEntry) {
|
|
25
|
+
callback(fcpEntry.startTime)
|
|
19
26
|
}
|
|
20
|
-
)
|
|
21
|
-
return { stop:
|
|
27
|
+
})
|
|
28
|
+
return { stop: performanceSubscription.unsubscribe }
|
|
22
29
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
elapsed,
|
|
3
|
-
find,
|
|
4
|
-
LifeCycleEventType,
|
|
5
|
-
isElementNode
|
|
6
|
-
} from '@cloudcare/browser-core'
|
|
1
|
+
import { elapsed, find, isElementNode } from '@cloudcare/browser-core'
|
|
7
2
|
import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
|
|
8
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
RumPerformanceEntryType,
|
|
5
|
+
createPerformanceObservable
|
|
6
|
+
} from '../../performanceObservable'
|
|
9
7
|
/**
|
|
10
8
|
* Track the first input occurring during the initial View to return:
|
|
11
9
|
* - First Input Delay
|
|
@@ -14,44 +12,44 @@ import { RumPerformanceEntryType } from '../../performanceObservable'
|
|
|
14
12
|
* Documentation: https://web.dev/fid/
|
|
15
13
|
* Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getFID.ts
|
|
16
14
|
*/
|
|
17
|
-
export function trackFirstInput(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
export function trackFirstInput(configuration, firstHidden, callback) {
|
|
16
|
+
const performanceFirstInputSubscription = createPerformanceObservable(
|
|
17
|
+
configuration,
|
|
18
|
+
{
|
|
19
|
+
type: RumPerformanceEntryType.FIRST_INPUT,
|
|
20
|
+
buffered: true
|
|
21
|
+
}
|
|
22
|
+
).subscribe(function (entries) {
|
|
23
|
+
var firstInputEntry = find(entries, function (entry) {
|
|
24
|
+
return (
|
|
25
|
+
entry.entryType === RumPerformanceEntryType.FIRST_INPUT &&
|
|
26
|
+
entry.startTime < firstHidden.getTimeStamp()
|
|
27
|
+
)
|
|
28
|
+
})
|
|
29
|
+
if (firstInputEntry) {
|
|
30
|
+
var firstInputDelay = elapsed(
|
|
31
|
+
firstInputEntry.startTime,
|
|
32
|
+
firstInputEntry.processingStart
|
|
33
|
+
)
|
|
34
|
+
var firstInputTargetSelector
|
|
35
|
+
if (firstInputEntry.target && isElementNode(firstInputEntry.target)) {
|
|
36
|
+
firstInputTargetSelector = getSelectorFromElement(
|
|
37
|
+
firstInputEntry.target,
|
|
38
|
+
configuration.actionNameAttribute
|
|
36
39
|
)
|
|
37
|
-
var firstInputTargetSelector
|
|
38
|
-
if (firstInputEntry.target && isElementNode(firstInputEntry.target)) {
|
|
39
|
-
firstInputTargetSelector = getSelectorFromElement(
|
|
40
|
-
firstInputEntry.target,
|
|
41
|
-
configuration.actionNameAttribute
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
callback({
|
|
45
|
-
// Ensure firstInputDelay to be positive, see
|
|
46
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=1185815
|
|
47
|
-
delay: firstInputDelay >= 0 ? firstInputDelay : 0,
|
|
48
|
-
time: firstInputEntry.startTime,
|
|
49
|
-
targetSelector: firstInputTargetSelector
|
|
50
|
-
})
|
|
51
40
|
}
|
|
41
|
+
callback({
|
|
42
|
+
// Ensure firstInputDelay to be positive, see
|
|
43
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1185815
|
|
44
|
+
delay: firstInputDelay >= 0 ? firstInputDelay : 0,
|
|
45
|
+
time: firstInputEntry.startTime,
|
|
46
|
+
targetSelector: firstInputTargetSelector
|
|
47
|
+
})
|
|
52
48
|
}
|
|
53
|
-
)
|
|
49
|
+
})
|
|
54
50
|
return {
|
|
55
|
-
stop:
|
|
51
|
+
stop: function () {
|
|
52
|
+
performanceFirstInputSubscription.unsubscribe()
|
|
53
|
+
}
|
|
56
54
|
}
|
|
57
55
|
}
|
|
@@ -7,7 +7,6 @@ import { trackFirstHidden } from './trackFirstHidden'
|
|
|
7
7
|
|
|
8
8
|
export var KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE
|
|
9
9
|
export function trackInitialViewMetrics(
|
|
10
|
-
lifeCycle,
|
|
11
10
|
configuration,
|
|
12
11
|
setLoadEvent,
|
|
13
12
|
scheduleViewUpdate
|
|
@@ -24,7 +23,7 @@ export function trackInitialViewMetrics(
|
|
|
24
23
|
var firstHidden = trackFirstHidden()
|
|
25
24
|
var stopNavigationTracking = _trackNavigationTimings.stop
|
|
26
25
|
var _trackFirstContentfulPaint = trackFirstContentfulPaint(
|
|
27
|
-
|
|
26
|
+
configuration,
|
|
28
27
|
firstHidden,
|
|
29
28
|
function (firstContentfulPaint) {
|
|
30
29
|
initialViewMetrics.firstContentfulPaint = firstContentfulPaint
|
|
@@ -33,7 +32,6 @@ export function trackInitialViewMetrics(
|
|
|
33
32
|
)
|
|
34
33
|
var stopFCPTracking = _trackFirstContentfulPaint.stop
|
|
35
34
|
var _trackLargestContentfulPaint = trackLargestContentfulPaint(
|
|
36
|
-
lifeCycle,
|
|
37
35
|
configuration,
|
|
38
36
|
firstHidden,
|
|
39
37
|
window,
|
|
@@ -44,7 +42,6 @@ export function trackInitialViewMetrics(
|
|
|
44
42
|
)
|
|
45
43
|
var stopLCPTracking = _trackLargestContentfulPaint.stop
|
|
46
44
|
var _trackFirstInput = trackFirstInput(
|
|
47
|
-
lifeCycle,
|
|
48
45
|
configuration,
|
|
49
46
|
firstHidden,
|
|
50
47
|
function (firstInput) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
noop,
|
|
3
|
-
LifeCycleEventType,
|
|
4
3
|
ViewLoadingType,
|
|
5
|
-
addTelemetryDebug,
|
|
6
4
|
ONE_MINUTE,
|
|
7
5
|
elapsed,
|
|
8
6
|
isElementNode
|
|
@@ -14,7 +12,8 @@ import {
|
|
|
14
12
|
} from './interactionCountPolyfill'
|
|
15
13
|
import {
|
|
16
14
|
RumPerformanceEntryType,
|
|
17
|
-
supportPerformanceTimingEvent
|
|
15
|
+
supportPerformanceTimingEvent,
|
|
16
|
+
createPerformanceObservable
|
|
18
17
|
} from '../../performanceObservable'
|
|
19
18
|
// Arbitrary value to prevent unnecessary memory usage on views with lots of interactions.
|
|
20
19
|
var MAX_INTERACTION_ENTRIES = 10
|
|
@@ -30,8 +29,7 @@ export var MAX_INP_VALUE = 1 * ONE_MINUTE
|
|
|
30
29
|
export function trackInteractionToNextPaint(
|
|
31
30
|
configuration,
|
|
32
31
|
viewStart,
|
|
33
|
-
viewLoadingType
|
|
34
|
-
lifeCycle
|
|
32
|
+
viewLoadingType
|
|
35
33
|
) {
|
|
36
34
|
if (!isInteractionToNextPaintSupported()) {
|
|
37
35
|
return {
|
|
@@ -53,40 +51,47 @@ export function trackInteractionToNextPaint(
|
|
|
53
51
|
var longestInteractions = trackLongestInteractions(getViewInteractionCount)
|
|
54
52
|
var interactionToNextPaint = -1
|
|
55
53
|
var interactionToNextPaintTargetSelector
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
function (entries) {
|
|
60
|
-
for (var entry of entries) {
|
|
61
|
-
if (
|
|
62
|
-
(entry.entryType === RumPerformanceEntryType.EVENT ||
|
|
63
|
-
entry.entryType === RumPerformanceEntryType.FIRST_INPUT) &&
|
|
64
|
-
entry.interactionId &&
|
|
65
|
-
entry.startTime >= viewStart &&
|
|
66
|
-
entry.startTime <= viewEnd
|
|
67
|
-
) {
|
|
68
|
-
longestInteractions.process(entry)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
var newInteraction = longestInteractions.estimateP98Interaction()
|
|
54
|
+
var interactionToNextPaintStartTime
|
|
55
|
+
function handleEntries(entries) {
|
|
56
|
+
for (var entry of entries) {
|
|
73
57
|
if (
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
entry.interactionId &&
|
|
59
|
+
entry.startTime >= viewStart &&
|
|
60
|
+
entry.startTime <= viewEnd
|
|
76
61
|
) {
|
|
77
|
-
|
|
62
|
+
longestInteractions.process(entry)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
var newInteraction = longestInteractions.estimateP98Interaction()
|
|
67
|
+
if (newInteraction && newInteraction.duration !== interactionToNextPaint) {
|
|
68
|
+
interactionToNextPaint = newInteraction.duration
|
|
69
|
+
interactionToNextPaintStartTime = elapsed(
|
|
70
|
+
viewStart,
|
|
71
|
+
newInteraction.startTime
|
|
72
|
+
)
|
|
73
|
+
if (newInteraction.target && isElementNode(newInteraction.target)) {
|
|
74
|
+
interactionToNextPaintTargetSelector = getSelectorFromElement(
|
|
75
|
+
newInteraction.target,
|
|
76
|
+
configuration.actionNameAttribute
|
|
77
|
+
)
|
|
78
|
+
} else {
|
|
79
|
+
interactionToNextPaintTargetSelector = undefined
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
|
-
|
|
82
|
+
}
|
|
83
|
+
var firstInputSubscription = createPerformanceObservable(configuration, {
|
|
84
|
+
type: RumPerformanceEntryType.FIRST_INPUT,
|
|
85
|
+
buffered: true
|
|
86
|
+
}).subscribe(handleEntries)
|
|
87
|
+
|
|
88
|
+
var eventSubscription = createPerformanceObservable(configuration, {
|
|
89
|
+
type: RumPerformanceEntryType.EVENT,
|
|
90
|
+
// durationThreshold only impact PerformanceEventTiming entries used for INP computation which requires a threshold at 40 (default is 104ms)
|
|
91
|
+
// cf: https://github.com/GoogleChrome/web-vitals/blob/3806160ffbc93c3c4abf210a167b81228172b31c/src/onINP.ts#L202-L210
|
|
92
|
+
durationThreshold: 40,
|
|
93
|
+
buffered: true
|
|
94
|
+
}).subscribe(handleEntries)
|
|
90
95
|
|
|
91
96
|
return {
|
|
92
97
|
getInteractionToNextPaint: function () {
|
|
@@ -107,7 +112,10 @@ export function trackInteractionToNextPaint(
|
|
|
107
112
|
viewEnd = viewEndTime
|
|
108
113
|
stopViewInteractionCount()
|
|
109
114
|
},
|
|
110
|
-
stop:
|
|
115
|
+
stop: function () {
|
|
116
|
+
eventSubscription.unsubscribe()
|
|
117
|
+
firstInputSubscription.unsubscribe()
|
|
118
|
+
}
|
|
111
119
|
}
|
|
112
120
|
}
|
|
113
121
|
|