Skip to content

Commit 35b9ae1

Browse files
authored
Merge pull request #1927 from WordPress/update/short-circuit-when-page-hidden
Short-circuit detection when page is opened in background tab since web-vitals.js will not report LCP
2 parents 61fa5d2 + e39b86a commit 35b9ae1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

plugins/optimization-detective/detect.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ export default async function detect( {
401401
return;
402402
}
403403

404+
if ( document.visibilityState === 'hidden' && ! document.prerendering ) {
405+
log( 'Page opened in background tab so URL Metric is not collected.' );
406+
return;
407+
}
408+
404409
// Abort if the current viewport is not among those which need URL Metrics.
405410
const urlMetricGroupStatus = getGroupForViewportWidth(
406411
win.innerWidth,

0 commit comments

Comments
 (0)