1 | import type { CLSMetric, CLSMetricWithAttribution } from './cls.js';
|
2 | import type { FCPMetric, FCPMetricWithAttribution } from './fcp.js';
|
3 | import type { FIDMetric, FIDMetricWithAttribution } from './fid.js';
|
4 | import type { INPMetric, INPMetricWithAttribution } from './inp.js';
|
5 | import type { LCPMetric, LCPMetricWithAttribution } from './lcp.js';
|
6 | import type { TTFBMetric, TTFBMetricWithAttribution } from './ttfb.js';
|
7 | export interface Metric {
|
8 | /**
|
9 | * The name of the metric (in acronym form).
|
10 | */
|
11 | name: 'CLS' | 'FCP' | 'FID' | 'INP' | 'LCP' | 'TTFB';
|
12 | /**
|
13 | * The current value of the metric.
|
14 | */
|
15 | value: number;
|
16 | /**
|
17 | * The rating as to whether the metric value is within the "good",
|
18 | * "needs improvement", or "poor" thresholds of the metric.
|
19 | */
|
20 | rating: 'good' | 'needs-improvement' | 'poor';
|
21 | /**
|
22 | * The delta between the current value and the last-reported value.
|
23 | * On the first report, `delta` and `value` will always be the same.
|
24 | */
|
25 | delta: number;
|
26 | /**
|
27 | * A unique ID representing this particular metric instance. This ID can
|
28 | * be used by an analytics tool to dedupe multiple values sent for the same
|
29 | * metric instance, or to group multiple deltas together and calculate a
|
30 | * total. It can also be used to differentiate multiple different metric
|
31 | * instances sent from the same page, which can happen if the page is
|
32 | * restored from the back/forward cache (in that case new metrics object
|
33 | * get created).
|
34 | */
|
35 | id: string;
|
36 | /**
|
37 | * Any performance entries relevant to the metric value calculation.
|
38 | * The array may also be empty if the metric value was not based on any
|
39 | * entries (e.g. a CLS value of 0 given no layout shifts).
|
40 | */
|
41 | entries: PerformanceEntry[];
|
42 | /**
|
43 | * The type of navigation.
|
44 | *
|
45 | * This will be the value returned by the Navigation Timing API (or
|
46 | * `undefined` if the browser doesn't support that API), with the following
|
47 | * exceptions:
|
48 | * - 'back-forward-cache': for pages that are restored from the bfcache.
|
49 | * - 'back_forward' is renamed to 'back-forward' for consistency.
|
50 | * - 'prerender': for pages that were prerendered.
|
51 | * - 'restore': for pages that were discarded by the browser and then
|
52 | * restored by the user.
|
53 | */
|
54 | navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender' | 'restore';
|
55 | }
|
56 | /** The union of supported metric types. */
|
57 | export type MetricType = CLSMetric | FCPMetric | FIDMetric | INPMetric | LCPMetric | TTFBMetric;
|
58 | /** The union of supported metric attribution types. */
|
59 | export type MetricWithAttribution = CLSMetricWithAttribution | FCPMetricWithAttribution | FIDMetricWithAttribution | INPMetricWithAttribution | LCPMetricWithAttribution | TTFBMetricWithAttribution;
|
60 | /**
|
61 | * The thresholds of metric's "good", "needs improvement", and "poor" ratings.
|
62 | *
|
63 | * - Metric values up to and including [0] are rated "good"
|
64 | * - Metric values up to and including [1] are rated "needs improvement"
|
65 | * - Metric values above [1] are "poor"
|
66 | *
|
67 | * | Metric value | Rating |
|
68 | * | --------------- | ------------------- |
|
69 | * | ≦ [0] | "good" |
|
70 | * | > [0] and ≦ [1] | "needs improvement" |
|
71 | * | > [1] | "poor" |
|
72 | */
|
73 | export type MetricRatingThresholds = [number, number];
|
74 | /**
|
75 | * @deprecated Use metric-specific function types instead, such as:
|
76 | * `(metric: LCPMetric) => void`. If a single callback type is needed for
|
77 | * multiple metrics, use `(metric: MetricType) => void`.
|
78 | */
|
79 | export interface ReportCallback {
|
80 | (metric: MetricType): void;
|
81 | }
|
82 | export interface ReportOpts {
|
83 | reportAllChanges?: boolean;
|
84 | durationThreshold?: number;
|
85 | }
|
86 | /**
|
87 | * The loading state of the document. Note: this value is similar to
|
88 | * `document.readyState` but it subdivides the "interactive" state into the
|
89 | * time before and after the DOMContentLoaded event fires.
|
90 | *
|
91 | * State descriptions:
|
92 | * - `loading`: the initial document response has not yet been fully downloaded
|
93 | * and parsed. This is equivalent to the corresponding `readyState` value.
|
94 | * - `dom-interactive`: the document has been fully loaded and parsed, but
|
95 | * scripts may not have yet finished loading and executing.
|
96 | * - `dom-content-loaded`: the document is fully loaded and parsed, and all
|
97 | * scripts (except `async` scripts) have loaded and finished executing.
|
98 | * - `complete`: the document and all of its sub-resources have finished
|
99 | * loading. This is equivalent to the corresponding `readyState` value.
|
100 | */
|
101 | export type LoadState = 'loading' | 'dom-interactive' | 'dom-content-loaded' | 'complete';
|