-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(metrics): support FCP for all frames with devtools throttling (#…
- Loading branch information
Showing
15 changed files
with
362 additions
and
25 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
lighthouse-cli/test/fixtures/perf/frame-metrics-inner.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<div id="space"></div> | ||
<h1>THIS IS THE INNER FRAME LCP AND FCP</h1> | ||
<script> | ||
const space = document.getElementById('space'); | ||
setTimeout(() => { | ||
space.style.height = 200; | ||
}, 200); | ||
setTimeout(() => { | ||
space.style.height = 400; | ||
}, 400); | ||
setTimeout(() => { | ||
space.style.height = 600; | ||
}, 600); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<iframe id="frame" src="frame-metrics-inner.html" width="100%" height="700"></iframe> | ||
<div id="space"></div> | ||
<div> | ||
<span id="content"></span> | ||
</div> | ||
<script> | ||
const space = document.getElementById('space'); | ||
const content = document.getElementById('content'); | ||
|
||
const keepAliveInterval = setInterval(() => { | ||
const start = new Date(); | ||
let now = start; | ||
while (now - start < 51) { | ||
now = new Date(); | ||
} | ||
}, 1000); | ||
setTimeout(() => clearInterval(keepAliveInterval), 8000); | ||
|
||
// The innerHTML will be the LCP and FCP of the main frame. | ||
// It is painted after the inner frame FCP, and it is smaller than the inner frame LCP. | ||
// The metrics for all frames will therefore be different than the metrics for the main frame. | ||
setTimeout(() => { | ||
content.innerHTML = 'This is the main frame LCP and FCP.'; | ||
|
||
// Add a small layout shift in the main frame. | ||
// More layout shifts occur in the inner frame. | ||
// CLS for all frames will therefore, be different than CLS for main frame. | ||
setTimeout(() => { | ||
space.style.height = '100'; | ||
}, 50); | ||
}, 5000); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lighthouse-core/computed/metrics/first-contentful-paint-all-frames.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const makeComputedArtifact = require('../computed-artifact.js'); | ||
const ComputedMetric = require('./metric.js'); | ||
|
||
class FirstContentfulPaintAllFrames extends ComputedMetric { | ||
/** | ||
* @return {Promise<LH.Artifacts.LanternMetric>} | ||
*/ | ||
static computeSimulatedMetric() { | ||
// TODO: Add support for all frames in lantern. | ||
throw new Error('FCP All Frames not implemented in lantern'); | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @return {Promise<LH.Artifacts.Metric>} | ||
*/ | ||
static async computeObservedMetric(data) { | ||
const {traceOfTab} = data; | ||
|
||
return { | ||
timing: traceOfTab.timings.firstContentfulPaintAllFrames, | ||
timestamp: traceOfTab.timestamps.firstContentfulPaintAllFrames, | ||
}; | ||
} | ||
} | ||
|
||
module.exports = makeComputedArtifact(FirstContentfulPaintAllFrames); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.