-
Notifications
You must be signed in to change notification settings - Fork 3
/
webvitals-crux.js
35 lines (30 loc) · 1.03 KB
/
webvitals-crux.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import WebPageTest from "webpagetest";
const wptServer = "https://www.webpagetest.org";
const wpt = new WebPageTest(wptServer, "YOUR_API_KEY");
let testURL = "https://www.webpagetest.org/"; //Your URL here
let options = {
firstViewOnly: true,
location: "Dulles:Chrome",
pollResults: 5,
timeout: 240,
};
wpt.runTest(testURL, options, (err, result) => {
if (result) {
console.log("<-------------Core Web Vitals------------->");
console.log({
CumulativeLayoutShift:
result.data.average.firstView["chromeUserTiming.CumulativeLayoutShift"],
LargestContentfulPaint:
result.data.average.firstView["chromeUserTiming.LargestContentfulPaint"],
TotalBlockingTime: result.data.average.firstView["TotalBlockingTime"],
});
if (result.data.median.firstView.CrUX !== undefined) {
console.log("<----------------Crux Data---------------->");
console.log(result.data.median.firstView.CrUX);
} else {
console.log("No CrUX Data Found");
}
} else {
console.log(err);
}
});