File tree 1 file changed +7
-2
lines changed
packages/tracing/src/browser 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';
10
10
import { getFID } from './web-vitals/getFID' ;
11
11
import { getLCP } from './web-vitals/getLCP' ;
12
12
import { getTTFB } from './web-vitals/getTTFB' ;
13
+ import { getFirstHidden } from './web-vitals/lib/getFirstHidden' ;
13
14
14
15
const global = getGlobalObject < Window > ( ) ;
15
16
@@ -85,13 +86,17 @@ export class MetricsInstrumentation {
85
86
86
87
// capture web vitals
87
88
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 ) {
89
94
logger . log ( '[Measurements] Adding FP' ) ;
90
95
this . _measurements [ 'fp' ] = { value : entry . startTime } ;
91
96
this . _measurements [ 'mark.fp' ] = { value : startTimestamp } ;
92
97
}
93
98
94
- if ( entry . name === 'first-contentful-paint' ) {
99
+ if ( entry . name === 'first-contentful-paint' && shouldRecord ) {
95
100
logger . log ( '[Measurements] Adding FCP' ) ;
96
101
this . _measurements [ 'fcp' ] = { value : entry . startTime } ;
97
102
this . _measurements [ 'mark.fcp' ] = { value : startTimestamp } ;
You can’t perform that action at this time.
0 commit comments