Skip to content

Commit

Permalink
Prevent FID entries being emitted as INP for non-supporting browsers (#…
Browse files Browse the repository at this point in the history
…368)

* Prevent FID entries being emitted as INP for non-supporting browsers

* Extra comment

* Update src/onINP.ts

Co-authored-by: Philip Walton <philipwalton@users.noreply.github.com>

---------

Co-authored-by: Philip Walton <philipwalton@users.noreply.github.com>
  • Loading branch information
tunetheweb and philipwalton committed Jul 12, 2023
1 parent 073033f commit 3806160
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -218,9 +217,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']);
Expand Down

0 comments on commit 3806160

Please sign in to comment.