Skip to content

Commit 86ca835

Browse files
authored
fix(web-vitals): Only report FCP or FP if the page wasn't hidden prior to their instrumentation (#2979)
1 parent 182bb8b commit 86ca835

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/tracing/src/browser/metrics.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getCLS } from './web-vitals/getCLS';
1010
import { getFID } from './web-vitals/getFID';
1111
import { getLCP } from './web-vitals/getLCP';
1212
import { getTTFB } from './web-vitals/getTTFB';
13+
import { getFirstHidden } from './web-vitals/lib/getFirstHidden';
1314

1415
const 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 };

0 commit comments

Comments
 (0)