Two tools
get_performance_metrics is instant. run_audit needs a
browser to itself. Choose by what the number is for.
| Situation | Tool |
|---|---|
| Is this slower than last time? | get_performance_metrics |
| Comparing several pages | get_performance_metrics |
| Inside a loop | get_performance_metrics |
| Why is it slow, specifically? | run_audit |
| An accessibility or SEO score | run_audit |
| A number going into a report | run_audit |
Quick timings
get_performance_metrics(session_id, lease, page_id)
This reads the page's own PerformanceObserver data: navigation
timings, first paint, FCP, LCP, transfer size and resource count. It needs no
queue or second browser. It tells you whether the page is slow and roughly
where. Use it by default for regression checks.
Full audits
run_audit(session_id, lease, url, categories: ["performance", "accessibility"])
-> {ticket, queue_position, available, note}
get_audit(session_id, lease, ticket)
run_audit runs real Lighthouse in a separate browser that vitro
starts for the audit and then discards. You get scores, Core Web Vitals, the
biggest opportunities and the failed audits. categories defaults
to all four: performance, accessibility,
best-practices and seo.
An audit loads the page several times under throttling and uses a lot of CPU
and memory, so audits share a small pool of browsers sized to the machine.
When the pool is busy, an audit waits in a queue. run_audit
returns a ticket at once with your queue position and never blocks. Do not
poll it in a tight loop. To learn that it finished, use one of these, best
first:
-
Send a
progressTokenwith the call. vitro pushesnotifications/progressas the queue moves, when the slot becomes yours, and with the result. Your client must keep the streamable-HTTP channel open for this. -
Watch your own timeline.
audit_startedandaudit_finishedappear in the session journal. -
Call
get_auditwith the ticket now and then.
If available is false, Lighthouse is not installed on
that machine. get_performance_metrics still works. Report that
Lighthouse is unavailable, and do not report the page as broken.
Getting numbers you can trust
-
Throttle on purpose.
set_network_conditionstakesdownload_kbps,upload_kbps,latency_msandoffline. Unthrottled local numbers make any page look fast. -
Set the viewport first with
emulateorresize. LCP depends on what is above the fold, so a metric without its viewport cannot be reproduced. -
Measure a settled page. Use
wait_foron the element you care about first, so you do not time a page mid-load. - A new session starts with an empty cache, which gives the first-visit number (usually the useful one). Do not compare it with a warm reload and call the difference a regression.
Report each number with its viewport, its throttling and whether the cache was cold.
What is missing on purpose
There is no start_trace. A Chrome trace is tens of megabytes and
needs a UI to read, so an agent cannot use it. run_audit gives
the same conclusions, already reduced to opportunities and failed audits.