From d0de4ced0ef15b83548118ccf62d6a8ed3470875 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Wed, 12 Jul 2023 18:08:16 +0100 Subject: [PATCH 1/3] Prevent FID entries being emitted as INP for non-supporting browsers --- src/onINP.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/onINP.ts b/src/onINP.ts index 473af397..5f37ea4b 100644 --- a/src/onINP.ts +++ b/src/onINP.ts @@ -218,9 +218,12 @@ export const onINP = (onReport: INPReportCallback, opts?: ReportOpts) => { ); if (po) { - // Also observe entries of type `first-input`. This is useful in cases + // If browser supports interactionId (and so supports INP), also + // observe entries of type `first-input`. This is useful in cases // where the first interaction is less than the `durationThreshold`. - po.observe({type: 'first-input', buffered: true}); + if ('interactionId' in PerformanceEventTiming?.prototype) { + po.observe({type: 'first-input', buffered: true}); + } onHidden(() => { handleEntries(po.takeRecords() as INPMetric['entries']); From 47431ae04ad319e52d33fbe62613221f42078762 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Wed, 12 Jul 2023 18:13:37 +0100 Subject: [PATCH 2/3] Extra comment --- src/onINP.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/onINP.ts b/src/onINP.ts index 5f37ea4b..76875f03 100644 --- a/src/onINP.ts +++ b/src/onINP.ts @@ -170,9 +170,8 @@ export const onINP = (onReport: INPReportCallback, opts?: ReportOpts) => { // so to consider them in INP we have to first check that an existing // entry doesn't match the `duration` and `startTime`. // Note that this logic assumes that `event` entries are dispatched - // before `first-input` entries. This is true in Chrome but it is not - // true in Firefox; however, Firefox doesn't support interactionId, so - // it's not an issue at the moment. + // before `first-input` entries. This is true in Chrome (the only browser + // that currently supports INP). // TODO(philipwalton): remove once crbug.com/1325826 is fixed. if (entry.entryType === 'first-input') { const noMatchingEntry = !longestInteractionList.some( From a3f9e4d03f9c3be2badde8dbdac86deba21a377f Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Wed, 12 Jul 2023 18:29:29 +0100 Subject: [PATCH 3/3] Update src/onINP.ts Co-authored-by: Philip Walton --- src/onINP.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onINP.ts b/src/onINP.ts index 76875f03..11760a1b 100644 --- a/src/onINP.ts +++ b/src/onINP.ts @@ -220,7 +220,7 @@ export const onINP = (onReport: INPReportCallback, opts?: ReportOpts) => { // If browser supports interactionId (and so supports INP), also // observe entries of type `first-input`. This is useful in cases // where the first interaction is less than the `durationThreshold`. - if ('interactionId' in PerformanceEventTiming?.prototype) { + if ('interactionId' in PerformanceEventTiming.prototype) { po.observe({type: 'first-input', buffered: true}); }