Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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