# Web Vitals — card for AI agents

Measure Core Web Vitals and other key performance metrics in JavaScript.

Category: Logging, monitoring and analytics · npm package `web-vitals` · latest version 6.2.3 (checked 2026-11-01)
Install: `npm install web-vitals`
License: Apache-2.0 (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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.

## Docs written for agents
- [llms.txt (index of the docs)](https://developer.chrome.com/docs/crux/llms.txt)

## What it is
- web-vitals is a JavaScript library from the GoogleChrome GitHub organization, published on npm as `web-vitals` under Apache-2.0. The repository was created on 2020-03-23. The README calls it a "tiny (~3K, brotli'd), modular library" for measuring Web Vitals on real users. It covers the three Core Web Vitals (CLS, INP, LCP) and two other metrics, FCP and TTFB.
- Each metric is one function, such as `onLCP`, `onINP` or `onCLS`. You pass it a callback, and the callback runs when the value is ready to report. You can install it from npm or load it from a CDN. It comes in two builds: a "standard" build and an "attribution" build that adds diagnostic data to each metric.
- It is for sites that want their own real-user monitoring. The web.dev Web Vitals page says Chrome User Experience Report data "does not provide the detailed, per-pageview telemetry" needed to diagnose regressions. It names this library as the easiest way to measure the Core Web Vitals in JavaScript.

## Caveats
- Some values arrive late: 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.
- Some callbacks never fire: 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.
- Call each function once per page: Each `on*` call creates a `PerformanceObserver` and listeners that stay for the life of the page. The README warns that repeated calls can increase memory overhead.
- JavaScript numbers may not equal CrUX: The web.dev page notes that values measured in JavaScript with public APIs may differ from what CrUX reports.
- Soft-navigation support is Chromium-only: The `reportSoftNavs` option is loaded from a separate `web-vitals@soft-navs` build in the README's examples. It changes how the first page load is measured. Browsers without soft-navigation support ignore the flag.

## Numbers (AgentGid data)
- Gid Score: 76.3 (#172 of all tools, 4 of 121 in its category)
- Used in 47 public projects set up for AI coding agents (0.8%)
- Downloads last week: 92,054,080 (as of 2026-11-24), +67.2% over 4 weeks
- GitHub stars: 8,700 (as of 2026-11-24)
- Last push: 2026-11-12

## Often used with
Testing Library 85.1%, React 89.4%, Vite 66.0%, Playwright (JavaScript) 59.6%, jsdom 48.9%, date-fns 42.6%

## Checked alternatives (same job)
- Vercel Speed Insights: https://agentgid.com/tools/vercel-speed-insights/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/web-vitals/
- Homepage: https://github.com/GoogleChrome/web-vitals#readme
- Repository: https://github.com/GoogleChrome/web-vitals
- Source: https://github.com/GoogleChrome/web-vitals#readme
- Source: https://github.com/GoogleChrome/web-vitals
- Source: https://www.npmjs.com/package/web-vitals
- Source: https://web.dev/vitals

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
