Web Vitals
Measure Core Web Vitals and other key performance metrics in JavaScript.
2. Maintained
github.com/GoogleChrome/web-vitals3. Used by agents' projects
Dependency in 47 public GitHub projects set up for AI coding agents that we scanned (0.8%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
developer.chrome.com/docs/crux/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Web Vitals does
web-vitals is Google Chrome's own field-measurement library: it reports CLS, INP and LCP from real users in a way the README says "accurately matches" how Chrome measures them and reports them to Google tools, and you can load it late without losing data.
Web Vitals popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Web Vitals is used
- Web Vitals is a dependency in 47 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (1.0% of the 4,867 JavaScript/TypeScript ones), #15 of 121 in logging, monitoring and analytics.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 311; those are left out of every share on this page.
- The most used alternative in our scan is Vercel Speed Insights (109 projects).
- Projects that use it most often also use Testing Library (85.1%), React (89.4%), Vite (66.0%).
By coding agent
Often used with
Web Vitals in practice
Strengths
The README says the library measures each metric the way Chrome does and the way it is reported to CrUX, PageSpeed Insights and Search Console's Speed Report.
The library uses the <code>buffered</code> flag on <code>PerformanceObserver</code>, so it still sees performance entries from before it loaded. The README recommends deferring it until other user-impacting code has loaded.
Change the import to <code>web-vitals/attribution</code> and each metric object gets an extra <code>attribution</code> property with diagnostic details. The README says this build is about 1.5K (brotli'd) larger and recommends it only if you use those features.
Each report carries an <code>id</code> and a <code>delta</code>. If your analytics provider cannot update a value it has already received, you send deltas and sum them by ID.
Watch out for
Some metrics wait until the user interacts, switches tabs, or the page starts to unload. CLS and INP are reported again when the page becomes hidden. All metrics are reported again after a back/forward cache restore.
INP is missing if the user never interacts with the page. CLS, FCP and LCP are missing if the page loaded in the background. Expect gaps in your data.
Each <code>on*</code> call creates a <code>PerformanceObserver</code> and listeners that stay for the life of the page. The README warns that repeated calls can increase memory overhead.
Report only the delta of each change
import {onCLS, onINP, onLCP} from 'web-vitals';
function logDelta({name, id, delta}) {
console.log(`${name} matching ID ${id} changed by ${delta}`);
}
onCLS(logDelta);
onINP(logDelta);
onLCP(logDelta);More about Web Vitals
Packages around it
- @testing-library: Component testing
- react-scripts: Create React App tooling
- react: UI library
- react-router-dom: Client-side routing
- @emotion: CSS-in-JS styling
- axios: HTTP client
More in Logging, monitoring and analytics
Alternatives
Web Vitals This page
Measure web performance metrics and get recommendations for improvement.
Get started
Install it.
npm install web-vitalsRules for your agent
## Web Vitals
- Install with `npm install web-vitals` and import from the package. The README calls npm the recommended way. If you must use a script tag, self-host the built files rather than relying on unpkg, jsDelivr or cdnjs.
- Defer loading the library until after other user-impacting code. The `buffered` flag means early entries are not lost.
- Call each of `onCLS()`, `onINP()`, `onLCP()` once per page load. Repeated calls add `PerformanceObserver` instances and listeners for the life of the page.
- Import from `web-vitals/attribution` only when the code actually reads the `attribution` property. It adds about 1.5K brotli'd.
- For analytics backends that cannot overwrite a sent value, send `delta` and group by `id`. A back/forward cache restore produces a new `id`.
- Do not enable `reportAllChanges` in production. The README says it is for debugging.
- Do not assume callbacks fire immediately, or at all. With `reportSoftNavs`, use the `navigationURL` property instead of the current URL.