diff --git a/plugins/optimization-detective/detect.js b/plugins/optimization-detective/detect.js index cd42fd583a..d137edf379 100644 --- a/plugins/optimization-detective/detect.js +++ b/plugins/optimization-detective/detect.js @@ -422,6 +422,11 @@ export default async function detect( { return; } + if ( document.visibilityState === 'hidden' && ! document.prerendering ) { + log( 'Page opened in background tab so URL Metric is not collected.' ); + return; + } + // Abort if the current viewport is not among those which need URL Metrics. const urlMetricGroupStatus = getGroupForViewportWidth( win.innerWidth,