Fix: correct Playwright Docker tag, sequential Lighthouse audits, devtools throttling
- Pin playwright npm to 1.59.1 to match Docker image tag - Update base image to mcr.microsoft.com/playwright:v1.59.1-jammy - Run Lighthouse desktop and mobile sequentially (parallel caused port conflict) - Switch to devtools throttling (simulate caused LanternError on localhost) - Skip browser download during npm ci (image has browsers pre-installed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
FROM mcr.microsoft.com/playwright/node:20-noble
|
FROM mcr.microsoft.com/playwright:v1.59.1-jammy
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies first (layer cache)
|
# Install dependencies first (layer cache)
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --omit=dev
|
RUN PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci --omit=dev
|
||||||
|
|
||||||
# Copy source
|
# Copy source
|
||||||
COPY src/ ./src/
|
COPY src/ ./src/
|
||||||
|
|||||||
2231
package-lock.json
generated
Normal file
2231
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chrome-launcher": "^1.1.2",
|
"chrome-launcher": "^1.1.2",
|
||||||
"lighthouse": "^12.2.1",
|
"lighthouse": "^12.2.1",
|
||||||
"playwright": "^1.44.0"
|
"playwright": "1.59.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20"
|
"node": ">=20"
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ async function main() {
|
|||||||
|
|
||||||
// Stage 2 & 3: Lighthouse desktop + mobile
|
// Stage 2 & 3: Lighthouse desktop + mobile
|
||||||
console.log('Running Lighthouse desktop audit...');
|
console.log('Running Lighthouse desktop audit...');
|
||||||
console.log('Running Lighthouse mobile audit...');
|
|
||||||
const lighthouseResults = await runLighthouse(url, rawDir);
|
const lighthouseResults = await runLighthouse(url, rawDir);
|
||||||
|
|
||||||
// Stage 4: Report assembly
|
// Stage 4: Report assembly
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ async function runPreset(url, preset, rawDir) {
|
|||||||
const chromePath = chromium.executablePath();
|
const chromePath = chromium.executablePath();
|
||||||
const chrome = await launch({
|
const chrome = await launch({
|
||||||
chromePath,
|
chromePath,
|
||||||
chromeFlags: ['--headless=new', '--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
chromeFlags: ['--headless', '--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -82,7 +82,7 @@ async function runPreset(url, preset, rawDir) {
|
|||||||
deviceScaleFactor: isDesktop ? 1 : 2,
|
deviceScaleFactor: isDesktop ? 1 : 2,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
throttlingMethod: 'simulate',
|
throttlingMethod: 'devtools',
|
||||||
onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
|
onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -116,10 +116,9 @@ async function runPreset(url, preset, rawDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runLighthouse(url, rawDir) {
|
export async function runLighthouse(url, rawDir) {
|
||||||
const [desktop, mobile] = await Promise.all([
|
const desktop = await runPreset(url, 'desktop', rawDir);
|
||||||
runPreset(url, 'desktop', rawDir),
|
console.log('Running Lighthouse mobile audit...');
|
||||||
runPreset(url, 'mobile', rawDir),
|
const mobile = await runPreset(url, 'mobile', rawDir);
|
||||||
]);
|
|
||||||
return [desktop, mobile];
|
return [desktop, mobile];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user