|
1 | 1 | /**
|
2 | 2 | * @typedef {import("web-vitals").LCPMetric} LCPMetric
|
3 | 3 | * @typedef {import("./types.ts").ElementData} ElementData
|
| 4 | + * @typedef {import("./types.ts").OnTTFBFunction} OnTTFBFunction |
| 5 | + * @typedef {import("./types.ts").OnFCPFunction} OnFCPFunction |
| 6 | + * @typedef {import("./types.ts").OnLCPFunction} OnLCPFunction |
| 7 | + * @typedef {import("./types.ts").OnINPFunction} OnINPFunction |
| 8 | + * @typedef {import("./types.ts").OnCLSFunction} OnCLSFunction |
4 | 9 | * @typedef {import("./types.ts").URLMetric} URLMetric
|
5 | 10 | * @typedef {import("./types.ts").URLMetricGroupStatus} URLMetricGroupStatus
|
6 | 11 | * @typedef {import("./types.ts").Extension} Extension
|
@@ -335,6 +340,14 @@ export default async function detect( {
|
335 | 340 | { once: true }
|
336 | 341 | );
|
337 | 342 |
|
| 343 | + const { |
| 344 | + /** @type OnTTFBFunction */ onTTFB, |
| 345 | + /** @type OnFCPFunction */ onFCP, |
| 346 | + /** @type OnLCPFunction */ onLCP, |
| 347 | + /** @type OnINPFunction */ onINP, |
| 348 | + /** @type OnCLSFunction */ onCLS, |
| 349 | + } = await import( webVitalsLibrarySrc ); |
| 350 | + |
338 | 351 | // TODO: Does this make sense here?
|
339 | 352 | // Prevent detection when page is not scrolled to the initial viewport.
|
340 | 353 | if ( doc.documentElement.scrollTop > 0 ) {
|
@@ -368,7 +381,11 @@ export default async function detect( {
|
368 | 381 | if ( extension.initialize instanceof Function ) {
|
369 | 382 | const initializePromise = extension.initialize( {
|
370 | 383 | isDebug,
|
371 |
| - webVitalsLibrarySrc, |
| 384 | + onTTFB, |
| 385 | + onFCP, |
| 386 | + onLCP, |
| 387 | + onINP, |
| 388 | + onCLS, |
372 | 389 | } );
|
373 | 390 | if ( initializePromise instanceof Promise ) {
|
374 | 391 | extensionInitializePromises.push( initializePromise );
|
@@ -454,8 +471,6 @@ export default async function detect( {
|
454 | 471 | } );
|
455 | 472 | }
|
456 | 473 |
|
457 |
| - const { onLCP } = await import( webVitalsLibrarySrc ); |
458 |
| - |
459 | 474 | /** @type {LCPMetric[]} */
|
460 | 475 | const lcpMetricCandidates = [];
|
461 | 476 |
|
|
0 commit comments