File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
packages/tracing/src/browser Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { getCLS } from './web-vitals/getCLS';
1010import { getFID } from './web-vitals/getFID' ;
1111import { getLCP } from './web-vitals/getLCP' ;
1212import { getTTFB } from './web-vitals/getTTFB' ;
13+ import { getFirstHidden } from './web-vitals/lib/getFirstHidden' ;
1314
1415const global = getGlobalObject < Window > ( ) ;
1516
@@ -85,13 +86,17 @@ export class MetricsInstrumentation {
8586
8687 // capture web vitals
8788
88- if ( entry . name === 'first-paint' ) {
89+ const firstHidden = getFirstHidden ( ) ;
90+ // Only report if the page wasn't hidden prior to the web vital.
91+ const shouldRecord = entry . startTime < firstHidden . timeStamp ;
92+
93+ if ( entry . name === 'first-paint' && shouldRecord ) {
8994 logger . log ( '[Measurements] Adding FP' ) ;
9095 this . _measurements [ 'fp' ] = { value : entry . startTime } ;
9196 this . _measurements [ 'mark.fp' ] = { value : startTimestamp } ;
9297 }
9398
94- if ( entry . name === 'first-contentful-paint' ) {
99+ if ( entry . name === 'first-contentful-paint' && shouldRecord ) {
95100 logger . log ( '[Measurements] Adding FCP' ) ;
96101 this . _measurements [ 'fcp' ] = { value : entry . startTime } ;
97102 this . _measurements [ 'mark.fcp' ] = { value : startTimestamp } ;
You can’t perform that action at this time.
0 commit comments