Skip to content

Commit 5d272c0

Browse files
feat: add basic URL performance analyzer
1 parent 0aea4fa commit 5d272c0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

analyze.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import puppeteer from "puppeteer";
2+
import lighthouse from "lighthouse";
3+
import { URL } from "url";
4+
5+
async function runLighthouse(url) {
6+
const browser = await puppeteer.launch({
7+
headless: true,
8+
args: ["--remote-debugging-port=9222"],
9+
});
10+
11+
const result = await lighthouse(url, {
12+
port: 9222,
13+
output: "html",
14+
logLevel: "info",
15+
});
16+
17+
await browser.close();
18+
return result.lhr;
19+
}
20+
21+
const url = process.argv[2];
22+
if (!url) {
23+
console.error("❌ Please provide a URL");
24+
process.exit(1);
25+
}
26+
27+
const result = await runLighthouse(url);
28+
console.log(
29+
`✅ Performance score for ${url}: ${
30+
result.categories.performance.score * 100
31+
}`
32+
);

0 commit comments

Comments
 (0)