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

Move the support check to the top of the onINP() function #490

Merged
merged 1 commit into from
Jun 6, 2024
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
20 changes: 12 additions & 8 deletions src/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export const onINP = (
onReport: (metric: INPMetric) => void,
opts?: ReportOpts,
) => {
// Return if the browser doesn't support all APIs needed to measure INP.
if (
!(
'PerformanceEventTiming' in self &&
'interactionId' in PerformanceEventTiming.prototype
)
) {
return;
}

// Set defaults
opts = opts || {};

Expand Down Expand Up @@ -104,15 +114,9 @@ export const onINP = (
);

if (po) {
// If browser supports interactionId (and so supports INP), also
// observe entries of type `first-input`. This is useful in cases
// Also observe entries of type `first-input`. This is useful in cases
// where the first interaction is less than the `durationThreshold`.
if (
'PerformanceEventTiming' in self &&
'interactionId' in PerformanceEventTiming.prototype
) {
po.observe({type: 'first-input', buffered: true});
}
po.observe({type: 'first-input', buffered: true});

onHidden(() => {
handleEntries(po.takeRecords() as INPMetric['entries']);
Expand Down
Loading