Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance benchmark-web-vitals command with additional metrics #41

Draft
wants to merge 3 commits into
base: add/benchmark-web-vitals
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ benchmark-server-timing -f path/to/urls.txt -n 5

### `benchmark-web-vitals`

Loads the provided URLs in a headless browser several times to measure median Web Vitals metrics for each URL. Currently the results cover load time metrics FCP, LCP, and TTFB. Including additional metrics is explored in a [follow up pull request](https://github.com/GoogleChromeLabs/wpp-research/pull/41).
Loads the provided URLs in a headless browser several times to measure median Web Vitals metrics for each URL. Currently the results cover metrics CLS, FCP, FID, INP, LCP, and TTFB.

#### Arguments

Expand Down
25 changes: 18 additions & 7 deletions cli/commands/benchmark-web-vitals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,31 @@ export async function handler( opt ) {
}

async function benchmarkURL( browser, params ) {
/*
* For now this only includes load time metrics.
* In the future, additional Web Vitals like CLS, FID, and INP should be
* added, however they are slightly more complex to retrieve through an
* automated headless browser test.
* See https://github.com/GoogleChromeLabs/wpp-research/pull/41.
*/
const metricsDefinition = {
CLS: {
listen: 'onCLS',
global: 'webVitalsCLS',
get: () => window.webVitalsCLS,
results: [],
},
FCP: {
listen: 'onFCP',
global: 'webVitalsFCP',
get: () => window.webVitalsFCP,
results: [],
},
FID: {
listen: 'onFID',
global: 'webVitalsFID',
get: () => window.webVitalsFID,
results: [],
},
INP: {
listen: 'onINP',
global: 'webVitalsINP',
get: () => window.webVitalsINP,
results: [],
},
LCP: {
listen: 'onLCP',
global: 'webVitalsLCP',
Expand Down