Skip to content

Commit e39b86a

Browse files
committed
Short-circuit detection when page is opened in background tab
1 parent 47eef00 commit e39b86a

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
@@ -422,6 +422,11 @@ export default async function detect( {
422422
return;
423423
}
424424

425+
if ( document.visibilityState === 'hidden' && ! document.prerendering ) {
426+
log( 'Page opened in background tab so URL Metric is not collected.' );
427+
return;
428+
}
429+
425430
// Abort if the current viewport is not among those which need URL Metrics.
426431
const urlMetricGroupStatus = getGroupForViewportWidth(
427432
win.innerWidth,

0 commit comments

Comments
 (0)