Skip to content

Commit

Permalink
Add workaround for Safari FCP bug
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed May 4, 2021
1 parent 78b2bf4 commit 4dfde19
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/getFCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ export const getFCP = (onReport: ReportHandler, reportAllChanges?: boolean) => {
}
};

const po = observe('paint', entryHandler);
if (po) {
// TODO(philipwalton): remove the use of `fcpEntry` once this bug is fixed.
// https://bugs.webkit.org/show_bug.cgi?id=225305
const fcpEntry = performance.getEntriesByName('first-contentful-paint')[0];
const po = fcpEntry ? null : observe('paint', entryHandler);

if (fcpEntry || po) {
report = bindReporter(onReport, metric, reportAllChanges);

if (fcpEntry) {
entryHandler(fcpEntry);
}

onBFCacheRestore((event) => {
metric = initMetric('FCP');
report = bindReporter(onReport, metric, reportAllChanges);
Expand Down

0 comments on commit 4dfde19

Please sign in to comment.