Skip to content

Commit 46d9ba7

Browse files
brendankennypaulirish
authored andcommitted
add flag to FMP to indicate if it fell back to FMP candidate (#2851)
1 parent a829811 commit 46d9ba7

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

lighthouse-core/audits/first-meaningful-paint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class FirstMeaningfulPaint extends Audit {
8282
fMP: traceOfTab.timings.firstMeaningfulPaint,
8383
onLoad: traceOfTab.timings.onLoad,
8484
endOfTrace: traceOfTab.timings.traceEnd,
85-
}
85+
},
86+
fmpFellBack: traceOfTab.fmpFellBack
8687
};
8788

8889
Object.keys(extendedInfo.timings).forEach(key => {

lighthouse-core/closure/typedefs/ComputedArtifacts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let TraceTimes;
3434
firstContentfulPaintEvt: TraceEvent,
3535
firstMeaningfulPaintEvt: TraceEvent,
3636
onLoadEvt: TraceEvent,
37+
fmpFellBack: boolean,
3738
}} */
3839
let TraceOfTabArtifact;
3940

lighthouse-core/gather/computed/trace-of-tab.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ class TraceOfTab extends ComputedArtifact {
6969
let firstMeaningfulPaint = frameEvents.find(
7070
e => e.name === 'firstMeaningfulPaint' && e.ts > navigationStart.ts
7171
);
72+
let fmpFellBack = false;
7273

7374
// If there was no firstMeaningfulPaint event found in the trace, the network idle detection
7475
// may have not been triggered before Lighthouse finished tracing.
7576
// In this case, we'll use the last firstMeaningfulPaintCandidate we can find.
7677
// However, if no candidates were found (a bogus trace, likely), we fail.
7778
if (!firstMeaningfulPaint) {
7879
const fmpCand = 'firstMeaningfulPaintCandidate';
80+
fmpFellBack = true;
7981
log.verbose('trace-of-tab', `No firstMeaningfulPaint found, falling back to last ${fmpCand}`);
8082
const lastCandidate = frameEvents.filter(e => e.name === fmpCand).pop();
8183
if (!lastCandidate) {
@@ -131,6 +133,7 @@ class TraceOfTab extends ComputedArtifact {
131133
firstContentfulPaintEvt: firstContentfulPaint,
132134
firstMeaningfulPaintEvt: firstMeaningfulPaint,
133135
onLoadEvt: onLoad,
136+
fmpFellBack,
134137
};
135138
}
136139
}

lighthouse-core/test/audits/first-meaningful-paint-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ describe('Performance: first-meaningful-paint audit', () => {
5959
it('scores the fMP correctly', () => {
6060
assert.equal(fmpResult.score, 99);
6161
});
62+
63+
it('did not fall back to an FMP candidate event', () => {
64+
assert.ok(!fmpResult.extendedInfo.value.fmpFellBack);
65+
});
6266
});
6367

6468
describe('finds correct FMP', () => {
@@ -68,6 +72,7 @@ describe('Performance: first-meaningful-paint audit', () => {
6872
assert.equal(result.rawValue, 529.9);
6973
assert.equal(result.extendedInfo.value.timestamps.navStart, 29343540951);
7074
assert.equal(result.extendedInfo.value.timings.fCP, 80.054);
75+
assert.ok(!result.extendedInfo.value.fmpFellBack);
7176
assert.ok(!result.debugString);
7277
});
7378
});
@@ -78,6 +83,7 @@ describe('Performance: first-meaningful-paint audit', () => {
7883
assert.equal(result.rawValue, 632.4);
7984
assert.equal(result.extendedInfo.value.timestamps.navStart, 8885424467);
8085
assert.equal(result.extendedInfo.value.timings.fCP, 632.419);
86+
assert.ok(!result.extendedInfo.value.fmpFellBack);
8187
assert.ok(!result.debugString);
8288
});
8389
});
@@ -88,6 +94,7 @@ describe('Performance: first-meaningful-paint audit', () => {
8894
assert.equal(result.rawValue, 878.4);
8995
assert.equal(result.extendedInfo.value.timestamps.navStart, 1805796384607);
9096
assert.equal(result.extendedInfo.value.timings.fCP, 879.046);
97+
assert.ok(!result.extendedInfo.value.fmpFellBack);
9198
assert.ok(!result.debugString);
9299
});
93100
});
@@ -97,6 +104,7 @@ describe('Performance: first-meaningful-paint audit', () => {
97104
assert.equal(result.displayValue, '4,460\xa0ms');
98105
assert.equal(result.rawValue, 4460.9);
99106
assert.equal(result.extendedInfo.value.timings.fCP, 1494.73);
107+
assert.ok(result.extendedInfo.value.fmpFellBack);
100108
assert.ok(!result.debugString);
101109
});
102110
});
@@ -111,6 +119,8 @@ describe('Performance: first-meaningful-paint audit', () => {
111119
assert.strictEqual(result.extendedInfo.value.timings.fMP, 482.318);
112120
assert.strictEqual(result.extendedInfo.value.timestamps.fCP, undefined);
113121
assert.strictEqual(result.extendedInfo.value.timestamps.fMP, 2149509604903);
122+
// NOTE: falls back to candidate FMP
123+
assert.ok(result.extendedInfo.value.fmpFellBack);
114124
});
115125
});
116126
});

lighthouse-core/test/gather/computed/trace-of-tab-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('Trace of Tab computed artifact:', () => {
5858
assert.equal(trace.navigationStartEvt.ts, 29343540951);
5959
assert.equal(trace.firstContentfulPaintEvt.ts, 29343621005);
6060
assert.equal(trace.firstMeaningfulPaintEvt.ts, 29344070867);
61+
assert.ok(!trace.fmpFellBack);
6162
});
6263

6364
it('if there was a tracingStartedInPage after the frame\'s navStart #2', () => {
@@ -66,6 +67,7 @@ describe('Trace of Tab computed artifact:', () => {
6667
assert.equal(trace.navigationStartEvt.ts, 8885424467);
6768
assert.equal(trace.firstContentfulPaintEvt.ts, 8886056886);
6869
assert.equal(trace.firstMeaningfulPaintEvt.ts, 8886056891);
70+
assert.ok(!trace.fmpFellBack);
6971
});
7072

7173
it('if it appears slightly before the fCP', () => {
@@ -74,6 +76,7 @@ describe('Trace of Tab computed artifact:', () => {
7476
assert.equal(trace.navigationStartEvt.ts, 1805796384607);
7577
assert.equal(trace.firstContentfulPaintEvt.ts, 1805797263653);
7678
assert.equal(trace.firstMeaningfulPaintEvt.ts, 1805797262960);
79+
assert.ok(!trace.fmpFellBack);
7780
});
7881

7982
it('from candidates if no defined FMP exists', () => {
@@ -82,6 +85,7 @@ describe('Trace of Tab computed artifact:', () => {
8285
assert.equal(trace.navigationStartEvt.ts, 2146735807738);
8386
assert.equal(trace.firstContentfulPaintEvt.ts, 2146737302468);
8487
assert.equal(trace.firstMeaningfulPaintEvt.ts, 2146740268666);
88+
assert.ok(trace.fmpFellBack);
8589
});
8690
});
8791

@@ -91,6 +95,7 @@ describe('Trace of Tab computed artifact:', () => {
9195
assert.equal(trace.navigationStartEvt.ts, 2149509122585, 'bad navStart');
9296
assert.equal(trace.firstContentfulPaintEvt, undefined, 'bad fcp');
9397
assert.equal(trace.firstMeaningfulPaintEvt.ts, 2149509604903, 'bad fmp');
98+
assert.ok(trace.fmpFellBack);
9499
});
95100

96101
it('handles traces missing a paints (captured in background tab)', () => {

0 commit comments

Comments
 (0)