Skip to content

Commit 66f3938

Browse files
authored
Move support check to beginning of onINP function (#490)
1 parent b32786b commit 66f3938

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/onINP.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ export const onINP = (
6464
onReport: (metric: INPMetric) => void,
6565
opts?: ReportOpts,
6666
) => {
67+
// Return if the browser doesn't support all APIs needed to measure INP.
68+
if (
69+
!(
70+
'PerformanceEventTiming' in self &&
71+
'interactionId' in PerformanceEventTiming.prototype
72+
)
73+
) {
74+
return;
75+
}
76+
6777
// Set defaults
6878
opts = opts || {};
6979

@@ -104,15 +114,9 @@ export const onINP = (
104114
);
105115

106116
if (po) {
107-
// If browser supports interactionId (and so supports INP), also
108-
// observe entries of type `first-input`. This is useful in cases
117+
// Also observe entries of type `first-input`. This is useful in cases
109118
// where the first interaction is less than the `durationThreshold`.
110-
if (
111-
'PerformanceEventTiming' in self &&
112-
'interactionId' in PerformanceEventTiming.prototype
113-
) {
114-
po.observe({type: 'first-input', buffered: true});
115-
}
119+
po.observe({type: 'first-input', buffered: true});
116120

117121
onHidden(() => {
118122
handleEntries(po.takeRecords() as INPMetric['entries']);

0 commit comments

Comments
 (0)