Skip to content

Commit 87054dc

Browse files
fix: viewport option
1 parent bda352b commit 87054dc

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { createServer } from "node:http";
1010
import { chromium } from "playwright";
1111
import { playAudit } from "playwright-lighthouse";
1212
import { z } from "zod";
13+
import lighthouseMobileConfig from "lighthouse/core/config/lr-mobile-config";
14+
import lighthouseDesktopConfig from "lighthouse/core/config/lr-desktop-config";
1315

1416
const port = process.env.PORT || 3000;
1517
const signature = process.env.APPWRITE_BROWSER_SECRET;
@@ -72,8 +74,13 @@ router.get(
7274

7375
const lighthouseParams = z.object({
7476
url: z.string().url(),
77+
viewport: z.enum(["mobile", "desktop"]).default("mobile"),
7578
formats: z.array(z.enum(["html", "json"])).default(["json"]),
7679
});
80+
const configs = {
81+
mobile: lighthouseMobileConfig,
82+
desktop: lighthouseDesktopConfig,
83+
};
7784
router.get(
7885
"/lighthouse",
7986
defineEventHandler(async (event) => {
@@ -88,6 +95,7 @@ router.get(
8895
json: query.formats.includes("json"),
8996
},
9097
},
98+
config: configs[query.viewport],
9199
page: page,
92100
port: 9222,
93101
thresholds: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4",
1515
"dependencies": {
1616
"h3": "^1.13.0",
17+
"lighthouse": "^12.2.1",
1718
"playwright": "^1.48.1",
1819
"playwright-lighthouse": "^4.0.0",
1920
"zod": "^3.23.8"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)