Skip to content

Commit 9d53449

Browse files
committed
use onHidden in getINP
1 parent e69e112 commit 9d53449

File tree

1 file changed

+5
-1
lines changed
  • packages/browser-utils/src/metrics/web-vitals

1 file changed

+5
-1
lines changed

packages/browser-utils/src/metrics/web-vitals/getINP.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { initMetric } from './lib/initMetric';
2020
import { initUnique } from './lib/initUnique';
2121
import { InteractionManager } from './lib/InteractionManager';
2222
import { observe } from './lib/observe';
23+
import { onHidden } from './lib/onHidden';
2324
import { initInteractionCountPolyfill } from './lib/polyfills/interactionCountPolyfill';
2425
import { whenActivated } from './lib/whenActivated';
2526
import { whenIdleOrHidden } from './lib/whenIdleOrHidden';
@@ -116,7 +117,10 @@ export const onINP = (onReport: (metric: INPMetric) => void, opts: INPReportOpts
116117
// where the first interaction is less than the `durationThreshold`.
117118
po.observe({ type: 'first-input', buffered: true });
118119

119-
WINDOW.document?.addEventListener('visibilitychange', () => {
120+
// sentry: we use onHidden instead of directly listening to visibilitychange
121+
// because some browsers we still support (Safari <14.4) don't fully support
122+
// `visibilitychange` or have known bugs w.r.t the `visibilitychange` event.
123+
onHidden(() => {
120124
if (WINDOW.document?.visibilityState === 'hidden') {
121125
handleEntries(po.takeRecords() as INPMetric['entries']);
122126
report(true);

0 commit comments

Comments
 (0)