@adobe/helix-rum-enhancer 2.31.0-beta.4 → 2.31.0-beta.6

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.
@@ -9,403 +9,398 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- (function () {
13
- 'use strict';
12
+ (function (e) {
14
13
 
15
- (function (e) {
16
-
17
- var n,
18
- t,
19
- r,
20
- i,
21
- o,
22
- a = -1,
23
- c = function (e) {
24
- addEventListener("pageshow", function (n) {
25
- n.persisted && (a = n.timeStamp, e(n));
26
- }, true);
27
- },
28
- u = function () {
29
- var e = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
30
- if (e && e.responseStart > 0 && e.responseStart < performance.now()) return e;
31
- },
32
- s = function () {
33
- var e = u();
34
- return e && e.activationStart || 0;
35
- },
36
- f = function (e, n) {
37
- var t = u(),
38
- r = "navigate";
39
- a >= 0 ? r = "back-forward-cache" : t && (document.prerendering || s() > 0 ? r = "prerender" : document.wasDiscarded ? r = "restore" : t.type && (r = t.type.replace(/_/g, "-")));
40
- return {
41
- name: e,
42
- value: undefined === n ? -1 : n,
43
- rating: "good",
44
- delta: 0,
45
- entries: [],
46
- id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12),
47
- navigationType: r
48
- };
49
- },
50
- d = function (e, n, t) {
51
- try {
52
- if (PerformanceObserver.supportedEntryTypes.includes(e)) {
53
- var r = new PerformanceObserver(function (e) {
54
- Promise.resolve().then(function () {
55
- n(e.getEntries());
56
- });
14
+ var n,
15
+ t,
16
+ r,
17
+ i,
18
+ o,
19
+ a = -1,
20
+ c = function (e) {
21
+ addEventListener("pageshow", function (n) {
22
+ n.persisted && (a = n.timeStamp, e(n));
23
+ }, true);
24
+ },
25
+ u = function () {
26
+ var e = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
27
+ if (e && e.responseStart > 0 && e.responseStart < performance.now()) return e;
28
+ },
29
+ s = function () {
30
+ var e = u();
31
+ return e && e.activationStart || 0;
32
+ },
33
+ f = function (e, n) {
34
+ var t = u(),
35
+ r = "navigate";
36
+ a >= 0 ? r = "back-forward-cache" : t && (document.prerendering || s() > 0 ? r = "prerender" : document.wasDiscarded ? r = "restore" : t.type && (r = t.type.replace(/_/g, "-")));
37
+ return {
38
+ name: e,
39
+ value: undefined === n ? -1 : n,
40
+ rating: "good",
41
+ delta: 0,
42
+ entries: [],
43
+ id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12),
44
+ navigationType: r
45
+ };
46
+ },
47
+ d = function (e, n, t) {
48
+ try {
49
+ if (PerformanceObserver.supportedEntryTypes.includes(e)) {
50
+ var r = new PerformanceObserver(function (e) {
51
+ Promise.resolve().then(function () {
52
+ n(e.getEntries());
57
53
  });
58
- return r.observe(Object.assign({
59
- type: e,
60
- buffered: !0
61
- }, t || {})), r;
62
- }
63
- } catch (e) {}
64
- },
65
- l = function (e, n, t, r) {
66
- var i, o;
67
- return function (a) {
68
- n.value >= 0 && (a || r) && ((o = n.value - (i || 0)) || undefined === i) && (i = n.value, n.delta = o, n.rating = function (e, n) {
69
- return e > n[1] ? "poor" : e > n[0] ? "needs-improvement" : "good";
70
- }(n.value, t), e(n));
71
- };
72
- },
73
- p = function (e) {
74
- requestAnimationFrame(function () {
75
- return requestAnimationFrame(function () {
76
- return e();
77
54
  });
78
- });
79
- },
80
- v = function (e) {
81
- document.addEventListener("visibilitychange", function () {
82
- "hidden" === document.visibilityState && e();
83
- });
84
- },
85
- m = function (e) {
86
- var n = false;
87
- return function () {
88
- n || (e(), n = true);
89
- };
90
- },
91
- h = -1,
92
- g = function () {
93
- return "hidden" !== document.visibilityState || document.prerendering ? 1 / 0 : 0;
94
- },
95
- T = function (e) {
96
- "hidden" === document.visibilityState && h > -1 && (h = "visibilitychange" === e.type ? e.timeStamp : 0, E());
97
- },
98
- y = function () {
99
- addEventListener("visibilitychange", T, true), addEventListener("prerenderingchange", T, true);
100
- },
101
- E = function () {
102
- removeEventListener("visibilitychange", T, true), removeEventListener("prerenderingchange", T, true);
103
- },
104
- C = function () {
105
- return h < 0 && (h = g(), y(), c(function () {
106
- setTimeout(function () {
107
- h = g(), y();
108
- }, 0);
109
- })), {
110
- get firstHiddenTime() {
111
- return h;
112
- }
113
- };
114
- },
115
- L = function (e) {
116
- document.prerendering ? addEventListener("prerenderingchange", function () {
117
- return e();
118
- }, true) : e();
119
- },
120
- S = [1800, 3e3],
121
- b = function (e, n) {
122
- n = n || {}, L(function () {
123
- var t,
124
- r = C(),
125
- i = f("FCP"),
126
- o = d("paint", function (e) {
127
- e.forEach(function (e) {
128
- "first-contentful-paint" === e.name && (o.disconnect(), e.startTime < r.firstHiddenTime && (i.value = Math.max(e.startTime - s(), 0), i.entries.push(e), t(!0)));
129
- });
130
- });
131
- o && (t = l(e, i, S, n.reportAllChanges), c(function (r) {
132
- i = f("FCP"), t = l(e, i, S, n.reportAllChanges), p(function () {
133
- i.value = performance.now() - r.timeStamp, t(true);
134
- });
135
- }));
136
- });
137
- },
138
- w = [.1, .25],
139
- I = 0,
140
- P = 1 / 0,
141
- A = 0,
142
- F = function (e) {
143
- e.forEach(function (e) {
144
- e.interactionId && (P = Math.min(P, e.interactionId), A = Math.max(A, e.interactionId), I = A ? (A - P) / 7 + 1 : 0);
145
- });
146
- },
147
- M = function () {
148
- return n ? I : performance.interactionCount || 0;
149
- },
150
- k = function () {
151
- "interactionCount" in performance || n || (n = d("event", F, {
152
- type: "event",
153
- buffered: true,
154
- durationThreshold: 0
155
- }));
156
- },
157
- D = [],
158
- B = new Map(),
159
- R = 0,
160
- x = function () {
161
- var e = Math.min(D.length - 1, Math.floor((M() - R) / 50));
162
- return D[e];
163
- },
164
- H = [],
165
- N = function (e) {
166
- if (H.forEach(function (n) {
167
- return n(e);
168
- }), e.interactionId || "first-input" === e.entryType) {
169
- var n = D[D.length - 1],
170
- t = B.get(e.interactionId);
171
- if (t || D.length < 10 || e.duration > n.latency) {
172
- if (t) e.duration > t.latency ? (t.entries = [e], t.latency = e.duration) : e.duration === t.latency && e.startTime === t.entries[0].startTime && t.entries.push(e);else {
173
- var r = {
174
- id: e.interactionId,
175
- latency: e.duration,
176
- entries: [e]
177
- };
178
- B.set(r.id, r), D.push(r);
179
- }
180
- D.sort(function (e, n) {
181
- return n.latency - e.latency;
182
- }), D.length > 10 && D.splice(10).forEach(function (e) {
183
- return B.delete(e.id);
184
- });
185
- }
55
+ return r.observe(Object.assign({
56
+ type: e,
57
+ buffered: !0
58
+ }, t || {})), r;
186
59
  }
187
- },
188
- q = function (e) {
189
- var n = self.requestIdleCallback || self.setTimeout,
190
- t = -1;
191
- return e = m(e), "hidden" === document.visibilityState ? e() : (t = n(e), v(e)), t;
192
- },
193
- O = [200, 500],
194
- j = [2500, 4e3],
195
- V = {},
196
- _ = [800, 1800],
197
- z = function e(n) {
198
- document.prerendering ? L(function () {
199
- return e(n);
200
- }) : "complete" !== document.readyState ? addEventListener("load", function () {
201
- return e(n);
202
- }, true) : setTimeout(n, 0);
203
- },
204
- G = {
205
- passive: true,
206
- capture: true
207
- },
208
- J = new Date(),
209
- K = function (e, n) {
210
- t || (t = n, r = e, i = new Date(), W(removeEventListener), Q());
211
- },
212
- Q = function () {
213
- if (r >= 0 && r < i - J) {
214
- var e = {
215
- entryType: "first-input",
216
- name: t.type,
217
- target: t.target,
218
- cancelable: t.cancelable,
219
- startTime: t.timeStamp,
220
- processingStart: t.timeStamp + r
221
- };
222
- o.forEach(function (n) {
223
- n(e);
224
- }), o = [];
225
- }
226
- },
227
- U = function (e) {
228
- if (e.cancelable) {
229
- var n = (e.timeStamp > 1e12 ? new Date() : performance.now()) - e.timeStamp;
230
- "pointerdown" == e.type ? function (e, n) {
231
- var t = function () {
232
- K(e, n), i();
233
- },
234
- r = function () {
235
- i();
236
- },
237
- i = function () {
238
- removeEventListener("pointerup", t, G), removeEventListener("pointercancel", r, G);
239
- };
240
- addEventListener("pointerup", t, G), addEventListener("pointercancel", r, G);
241
- }(n, e) : K(n, e);
242
- }
243
- },
244
- W = function (e) {
245
- ["mousedown", "keydown", "touchstart", "pointerdown"].forEach(function (n) {
246
- return e(n, U, G);
60
+ } catch (e) {}
61
+ },
62
+ l = function (e, n, t, r) {
63
+ var i, o;
64
+ return function (a) {
65
+ n.value >= 0 && (a || r) && ((o = n.value - (i || 0)) || undefined === i) && (i = n.value, n.delta = o, n.rating = function (e, n) {
66
+ return e > n[1] ? "poor" : e > n[0] ? "needs-improvement" : "good";
67
+ }(n.value, t), e(n));
68
+ };
69
+ },
70
+ p = function (e) {
71
+ requestAnimationFrame(function () {
72
+ return requestAnimationFrame(function () {
73
+ return e();
247
74
  });
248
- },
249
- X = [100, 300];
250
- return e.CLSThresholds = w, e.FCPThresholds = S, e.FIDThresholds = X, e.INPThresholds = O, e.LCPThresholds = j, e.TTFBThresholds = _, e.onCLS = function (e, n) {
251
- n = n || {}, b(m(function () {
252
- var t,
253
- r = f("CLS", 0),
254
- i = 0,
255
- o = [],
256
- a = function (e) {
257
- e.forEach(function (e) {
258
- if (!e.hadRecentInput) {
259
- var n = o[0],
260
- t = o[o.length - 1];
261
- i && e.startTime - t.startTime < 1e3 && e.startTime - n.startTime < 5e3 ? (i += e.value, o.push(e)) : (i = e.value, o = [e]);
262
- }
263
- }), i > r.value && (r.value = i, r.entries = o, t());
264
- },
265
- u = d("layout-shift", a);
266
- u && (t = l(e, r, w, n.reportAllChanges), v(function () {
267
- a(u.takeRecords()), t(true);
268
- }), c(function () {
269
- i = 0, r = f("CLS", 0), t = l(e, r, w, n.reportAllChanges), p(function () {
270
- return t();
271
- });
272
- }), setTimeout(t, 0));
273
- }));
274
- }, e.onFCP = b, e.onFID = function (e, n) {
275
- n = n || {}, L(function () {
276
- var i,
277
- a = C(),
278
- u = f("FID"),
279
- s = function (e) {
280
- e.startTime < a.firstHiddenTime && (u.value = e.processingStart - e.startTime, u.entries.push(e), i(true));
281
- },
282
- p = function (e) {
283
- e.forEach(s);
284
- },
285
- h = d("first-input", p);
286
- i = l(e, u, X, n.reportAllChanges), h && (v(m(function () {
287
- p(h.takeRecords()), h.disconnect();
288
- })), c(function () {
289
- var a;
290
- u = f("FID"), i = l(e, u, X, n.reportAllChanges), o = [], r = -1, t = null, W(addEventListener), a = s, o.push(a), Q();
291
- }));
292
75
  });
293
- }, e.onINP = function (e, n) {
294
- "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (n = n || {}, L(function () {
295
- var t;
296
- k();
297
- var r,
298
- i = f("INP"),
299
- o = function (e) {
300
- q(function () {
301
- e.forEach(N);
302
- var n = x();
303
- n && n.latency !== i.value && (i.value = n.latency, i.entries = n.entries, r());
304
- });
305
- },
306
- a = d("event", o, {
307
- durationThreshold: null !== (t = n.durationThreshold) && undefined !== t ? t : 40
308
- });
309
- r = l(e, i, O, n.reportAllChanges), a && (a.observe({
310
- type: "first-input",
311
- buffered: true
312
- }), v(function () {
313
- o(a.takeRecords()), r(true);
314
- }), c(function () {
315
- R = M(), D.length = 0, B.clear(), i = f("INP"), r = l(e, i, O, n.reportAllChanges);
316
- }));
317
- }));
318
- }, e.onLCP = function (e, n) {
76
+ },
77
+ v = function (e) {
78
+ document.addEventListener("visibilitychange", function () {
79
+ "hidden" === document.visibilityState && e();
80
+ });
81
+ },
82
+ m = function (e) {
83
+ var n = false;
84
+ return function () {
85
+ n || (e(), n = true);
86
+ };
87
+ },
88
+ h = -1,
89
+ g = function () {
90
+ return "hidden" !== document.visibilityState || document.prerendering ? 1 / 0 : 0;
91
+ },
92
+ T = function (e) {
93
+ "hidden" === document.visibilityState && h > -1 && (h = "visibilitychange" === e.type ? e.timeStamp : 0, E());
94
+ },
95
+ y = function () {
96
+ addEventListener("visibilitychange", T, true), addEventListener("prerenderingchange", T, true);
97
+ },
98
+ E = function () {
99
+ removeEventListener("visibilitychange", T, true), removeEventListener("prerenderingchange", T, true);
100
+ },
101
+ C = function () {
102
+ return h < 0 && (h = g(), y(), c(function () {
103
+ setTimeout(function () {
104
+ h = g(), y();
105
+ }, 0);
106
+ })), {
107
+ get firstHiddenTime() {
108
+ return h;
109
+ }
110
+ };
111
+ },
112
+ L = function (e) {
113
+ document.prerendering ? addEventListener("prerenderingchange", function () {
114
+ return e();
115
+ }, true) : e();
116
+ },
117
+ S = [1800, 3e3],
118
+ b = function (e, n) {
319
119
  n = n || {}, L(function () {
320
120
  var t,
321
121
  r = C(),
322
- i = f("LCP"),
323
- o = function (e) {
324
- n.reportAllChanges || (e = e.slice(-1)), e.forEach(function (e) {
325
- e.startTime < r.firstHiddenTime && (i.value = Math.max(e.startTime - s(), 0), i.entries = [e], t());
122
+ i = f("FCP"),
123
+ o = d("paint", function (e) {
124
+ e.forEach(function (e) {
125
+ "first-contentful-paint" === e.name && (o.disconnect(), e.startTime < r.firstHiddenTime && (i.value = Math.max(e.startTime - s(), 0), i.entries.push(e), t(!0)));
326
126
  });
327
- },
328
- a = d("largest-contentful-paint", o);
329
- if (a) {
330
- t = l(e, i, j, n.reportAllChanges);
331
- var u = m(function () {
332
- V[i.id] || (o(a.takeRecords()), a.disconnect(), V[i.id] = true, t(true));
333
127
  });
334
- ["keydown", "click"].forEach(function (e) {
335
- addEventListener(e, function () {
336
- return q(u);
337
- }, {
338
- once: true,
339
- capture: true
340
- });
341
- }), v(u), c(function (r) {
342
- i = f("LCP"), t = l(e, i, j, n.reportAllChanges), p(function () {
343
- i.value = performance.now() - r.timeStamp, V[i.id] = true, t(true);
344
- });
128
+ o && (t = l(e, i, S, n.reportAllChanges), c(function (r) {
129
+ i = f("FCP"), t = l(e, i, S, n.reportAllChanges), p(function () {
130
+ i.value = performance.now() - r.timeStamp, t(true);
345
131
  });
346
- }
347
- });
348
- }, e.onTTFB = function (e, n) {
349
- n = n || {};
350
- var t = f("TTFB"),
351
- r = l(e, t, _, n.reportAllChanges);
352
- z(function () {
353
- var i = u();
354
- i && (t.value = Math.max(i.responseStart - s(), 0), t.entries = [i], r(true), c(function () {
355
- t = f("TTFB", 0), (r = l(e, t, _, n.reportAllChanges))(true);
356
132
  }));
357
133
  });
358
- }, e;
359
- })({});
360
-
361
- function addCWVTracking({
362
- sampleRUM,
363
- sourceSelector,
364
- targetSelector,
365
- fflags
366
- }) {
367
- setTimeout(() => {
368
- try {
369
- const cwvScript = new URL('.rum/web-vitals/dist/web-vitals.iife.js', sampleRUM.baseURL).href;
370
- if (document.querySelector(`script[src="${cwvScript}"]`)) {
371
- return;
134
+ },
135
+ w = [.1, .25],
136
+ I = 0,
137
+ P = 1 / 0,
138
+ A = 0,
139
+ F = function (e) {
140
+ e.forEach(function (e) {
141
+ e.interactionId && (P = Math.min(P, e.interactionId), A = Math.max(A, e.interactionId), I = A ? (A - P) / 7 + 1 : 0);
142
+ });
143
+ },
144
+ M = function () {
145
+ return n ? I : performance.interactionCount || 0;
146
+ },
147
+ k = function () {
148
+ "interactionCount" in performance || n || (n = d("event", F, {
149
+ type: "event",
150
+ buffered: true,
151
+ durationThreshold: 0
152
+ }));
153
+ },
154
+ D = [],
155
+ B = new Map(),
156
+ R = 0,
157
+ x = function () {
158
+ var e = Math.min(D.length - 1, Math.floor((M() - R) / 50));
159
+ return D[e];
160
+ },
161
+ H = [],
162
+ N = function (e) {
163
+ if (H.forEach(function (n) {
164
+ return n(e);
165
+ }), e.interactionId || "first-input" === e.entryType) {
166
+ var n = D[D.length - 1],
167
+ t = B.get(e.interactionId);
168
+ if (t || D.length < 10 || e.duration > n.latency) {
169
+ if (t) e.duration > t.latency ? (t.entries = [e], t.latency = e.duration) : e.duration === t.latency && e.startTime === t.entries[0].startTime && t.entries.push(e);else {
170
+ var r = {
171
+ id: e.interactionId,
172
+ latency: e.duration,
173
+ entries: [e]
174
+ };
175
+ B.set(r.id, r), D.push(r);
176
+ }
177
+ D.sort(function (e, n) {
178
+ return n.latency - e.latency;
179
+ }), D.length > 10 && D.splice(10).forEach(function (e) {
180
+ return B.delete(e.id);
181
+ });
372
182
  }
373
- const script = document.createElement('script');
374
- script.src = cwvScript;
375
- script.onload = () => {
376
- const storeCWV = measurement => {
377
- const data = {
378
- cwv: {}
183
+ }
184
+ },
185
+ q = function (e) {
186
+ var n = self.requestIdleCallback || self.setTimeout,
187
+ t = -1;
188
+ return e = m(e), "hidden" === document.visibilityState ? e() : (t = n(e), v(e)), t;
189
+ },
190
+ O = [200, 500],
191
+ j = [2500, 4e3],
192
+ V = {},
193
+ _ = [800, 1800],
194
+ z = function e(n) {
195
+ document.prerendering ? L(function () {
196
+ return e(n);
197
+ }) : "complete" !== document.readyState ? addEventListener("load", function () {
198
+ return e(n);
199
+ }, true) : setTimeout(n, 0);
200
+ },
201
+ G = {
202
+ passive: true,
203
+ capture: true
204
+ },
205
+ J = new Date(),
206
+ K = function (e, n) {
207
+ t || (t = n, r = e, i = new Date(), W(removeEventListener), Q());
208
+ },
209
+ Q = function () {
210
+ if (r >= 0 && r < i - J) {
211
+ var e = {
212
+ entryType: "first-input",
213
+ name: t.type,
214
+ target: t.target,
215
+ cancelable: t.cancelable,
216
+ startTime: t.timeStamp,
217
+ processingStart: t.timeStamp + r
218
+ };
219
+ o.forEach(function (n) {
220
+ n(e);
221
+ }), o = [];
222
+ }
223
+ },
224
+ U = function (e) {
225
+ if (e.cancelable) {
226
+ var n = (e.timeStamp > 1e12 ? new Date() : performance.now()) - e.timeStamp;
227
+ "pointerdown" == e.type ? function (e, n) {
228
+ var t = function () {
229
+ K(e, n), i();
230
+ },
231
+ r = function () {
232
+ i();
233
+ },
234
+ i = function () {
235
+ removeEventListener("pointerup", t, G), removeEventListener("pointercancel", r, G);
379
236
  };
380
- data.cwv[measurement.name] = measurement.value;
381
- if (measurement.name === 'LCP' && measurement.entries.length > 0) {
382
- const {
383
- element
384
- } = measurement.entries.pop();
385
- data.target = targetSelector(element);
386
- data.source = sourceSelector(element) || element && element.outerHTML.slice(0, 30);
387
- }
388
- sampleRUM('cwv', data);
389
- };
390
- const isEager = metric => ['CLS', 'LCP'].includes(metric);
391
- ['INP', 'TTFB', 'CLS', 'LCP'].forEach(metric => {
392
- const metricFn = window.webVitals[`on${metric}`];
393
- if (typeof metricFn === 'function') {
394
- let opts = {};
395
- fflags.enabled('eagercwv', () => {
396
- opts = {
397
- reportAllChanges: isEager(metric)
398
- };
399
- });
400
- metricFn(storeCWV, opts);
237
+ addEventListener("pointerup", t, G), addEventListener("pointercancel", r, G);
238
+ }(n, e) : K(n, e);
239
+ }
240
+ },
241
+ W = function (e) {
242
+ ["mousedown", "keydown", "touchstart", "pointerdown"].forEach(function (n) {
243
+ return e(n, U, G);
244
+ });
245
+ },
246
+ X = [100, 300];
247
+ return e.CLSThresholds = w, e.FCPThresholds = S, e.FIDThresholds = X, e.INPThresholds = O, e.LCPThresholds = j, e.TTFBThresholds = _, e.onCLS = function (e, n) {
248
+ n = n || {}, b(m(function () {
249
+ var t,
250
+ r = f("CLS", 0),
251
+ i = 0,
252
+ o = [],
253
+ a = function (e) {
254
+ e.forEach(function (e) {
255
+ if (!e.hadRecentInput) {
256
+ var n = o[0],
257
+ t = o[o.length - 1];
258
+ i && e.startTime - t.startTime < 1e3 && e.startTime - n.startTime < 5e3 ? (i += e.value, o.push(e)) : (i = e.value, o = [e]);
401
259
  }
260
+ }), i > r.value && (r.value = i, r.entries = o, t());
261
+ },
262
+ u = d("layout-shift", a);
263
+ u && (t = l(e, r, w, n.reportAllChanges), v(function () {
264
+ a(u.takeRecords()), t(true);
265
+ }), c(function () {
266
+ i = 0, r = f("CLS", 0), t = l(e, r, w, n.reportAllChanges), p(function () {
267
+ return t();
268
+ });
269
+ }), setTimeout(t, 0));
270
+ }));
271
+ }, e.onFCP = b, e.onFID = function (e, n) {
272
+ n = n || {}, L(function () {
273
+ var i,
274
+ a = C(),
275
+ u = f("FID"),
276
+ s = function (e) {
277
+ e.startTime < a.firstHiddenTime && (u.value = e.processingStart - e.startTime, u.entries.push(e), i(true));
278
+ },
279
+ p = function (e) {
280
+ e.forEach(s);
281
+ },
282
+ h = d("first-input", p);
283
+ i = l(e, u, X, n.reportAllChanges), h && (v(m(function () {
284
+ p(h.takeRecords()), h.disconnect();
285
+ })), c(function () {
286
+ var a;
287
+ u = f("FID"), i = l(e, u, X, n.reportAllChanges), o = [], r = -1, t = null, W(addEventListener), a = s, o.push(a), Q();
288
+ }));
289
+ });
290
+ }, e.onINP = function (e, n) {
291
+ "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (n = n || {}, L(function () {
292
+ var t;
293
+ k();
294
+ var r,
295
+ i = f("INP"),
296
+ o = function (e) {
297
+ q(function () {
298
+ e.forEach(N);
299
+ var n = x();
300
+ n && n.latency !== i.value && (i.value = n.latency, i.entries = n.entries, r());
402
301
  });
403
- };
404
- document.head.appendChild(script);
405
- } catch (error) {}
406
- }, 2000);
407
- }
302
+ },
303
+ a = d("event", o, {
304
+ durationThreshold: null !== (t = n.durationThreshold) && undefined !== t ? t : 40
305
+ });
306
+ r = l(e, i, O, n.reportAllChanges), a && (a.observe({
307
+ type: "first-input",
308
+ buffered: true
309
+ }), v(function () {
310
+ o(a.takeRecords()), r(true);
311
+ }), c(function () {
312
+ R = M(), D.length = 0, B.clear(), i = f("INP"), r = l(e, i, O, n.reportAllChanges);
313
+ }));
314
+ }));
315
+ }, e.onLCP = function (e, n) {
316
+ n = n || {}, L(function () {
317
+ var t,
318
+ r = C(),
319
+ i = f("LCP"),
320
+ o = function (e) {
321
+ n.reportAllChanges || (e = e.slice(-1)), e.forEach(function (e) {
322
+ e.startTime < r.firstHiddenTime && (i.value = Math.max(e.startTime - s(), 0), i.entries = [e], t());
323
+ });
324
+ },
325
+ a = d("largest-contentful-paint", o);
326
+ if (a) {
327
+ t = l(e, i, j, n.reportAllChanges);
328
+ var u = m(function () {
329
+ V[i.id] || (o(a.takeRecords()), a.disconnect(), V[i.id] = true, t(true));
330
+ });
331
+ ["keydown", "click"].forEach(function (e) {
332
+ addEventListener(e, function () {
333
+ return q(u);
334
+ }, {
335
+ once: true,
336
+ capture: true
337
+ });
338
+ }), v(u), c(function (r) {
339
+ i = f("LCP"), t = l(e, i, j, n.reportAllChanges), p(function () {
340
+ i.value = performance.now() - r.timeStamp, V[i.id] = true, t(true);
341
+ });
342
+ });
343
+ }
344
+ });
345
+ }, e.onTTFB = function (e, n) {
346
+ n = n || {};
347
+ var t = f("TTFB"),
348
+ r = l(e, t, _, n.reportAllChanges);
349
+ z(function () {
350
+ var i = u();
351
+ i && (t.value = Math.max(i.responseStart - s(), 0), t.entries = [i], r(true), c(function () {
352
+ t = f("TTFB", 0), (r = l(e, t, _, n.reportAllChanges))(true);
353
+ }));
354
+ });
355
+ }, e;
356
+ })({});
408
357
 
409
- return addCWVTracking;
358
+ function addCWVTracking({
359
+ sampleRUM,
360
+ sourceSelector,
361
+ targetSelector,
362
+ fflags
363
+ }) {
364
+ setTimeout(() => {
365
+ try {
366
+ const cwvScript = new URL('.rum/web-vitals/dist/web-vitals.iife.js', sampleRUM.baseURL).href;
367
+ if (document.querySelector(`script[src="${cwvScript}"]`)) {
368
+ return;
369
+ }
370
+ const script = document.createElement('script');
371
+ script.src = cwvScript;
372
+ script.onload = () => {
373
+ const storeCWV = measurement => {
374
+ const data = {
375
+ cwv: {}
376
+ };
377
+ data.cwv[measurement.name] = measurement.value;
378
+ if (measurement.name === 'LCP' && measurement.entries.length > 0) {
379
+ const {
380
+ element
381
+ } = measurement.entries.pop();
382
+ data.target = targetSelector(element);
383
+ data.source = sourceSelector(element) || element && element.outerHTML.slice(0, 30);
384
+ }
385
+ sampleRUM('cwv', data);
386
+ };
387
+ const isEager = metric => ['CLS', 'LCP'].includes(metric);
388
+ ['INP', 'TTFB', 'CLS', 'LCP'].forEach(metric => {
389
+ const metricFn = window.webVitals[`on${metric}`];
390
+ if (typeof metricFn === 'function') {
391
+ let opts = {};
392
+ fflags.enabled('eagercwv', () => {
393
+ opts = {
394
+ reportAllChanges: isEager(metric)
395
+ };
396
+ });
397
+ metricFn(storeCWV, opts);
398
+ }
399
+ });
400
+ };
401
+ document.head.appendChild(script);
402
+ } catch (error) {}
403
+ }, 2000);
404
+ }
410
405
 
411
- })();
406
+ export { addCWVTracking as default };