Skip to content

Commit

Permalink
Merge pull request #145 from GoogleChrome/fcp-safari
Browse files Browse the repository at this point in the history
Add workaround for Safari FCP bug
  • Loading branch information
philipwalton authored May 4, 2021
2 parents 78b2bf4 + 4dfde19 commit 1a29dca
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 1a29dca

Please sign in to comment.