diff --git a/scripts/pagespeed-sitemap.ts b/scripts/pagespeed-sitemap.ts index 902bcaa1..5c6b8e68 100644 --- a/scripts/pagespeed-sitemap.ts +++ b/scripts/pagespeed-sitemap.ts @@ -80,7 +80,23 @@ async function main() { Cookie: `klz_gatekeeper_session=${gatekeeperPassword}`, }); - const chromePath = process.env.CHROME_PATH || process.env.PUPPETEER_EXECUTABLE_PATH; + // Detect Chrome path from Puppeteer installation if not provided + let chromePath = process.env.CHROME_PATH || process.env.PUPPETEER_EXECUTABLE_PATH; + if (!chromePath) { + try { + const puppeteerInfo = execSync('npx puppeteer browsers latest chrome', { + encoding: 'utf8', + }); + const match = puppeteerInfo.match(/executablePath: (.*)/); + if (match && match[1]) { + chromePath = match[1].trim(); + console.log(`🔍 Detected Puppeteer Chrome at: ${chromePath}`); + } + } catch (e) { + console.warn('⚠️ Could not detect Puppeteer Chrome path automatically.'); + } + } + const chromePathArg = chromePath ? `--collect.chromePath="${chromePath}"` : ''; // Clean up old reports @@ -90,7 +106,7 @@ async function main() { // Using a more robust way to execute and capture output // We remove 'npx lhci upload' to keep everything local and avoid Google-hosted reports - const lhciCommand = `npx lhci collect ${urlArgs} ${chromePathArg} --config=config/lighthouserc.json --collect.settings.extraHeaders='${extraHeaders}' --collect.settings.chromeFlags="--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage" && npx lhci assert --config=config/lighthouserc.json`; + const lhciCommand = `CHROME_PATH="${chromePath}" npx lhci collect ${urlArgs} ${chromePathArg} --config=config/lighthouserc.json --collect.settings.extraHeaders='${extraHeaders}' --collect.settings.chromeFlags="--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage" && npx lhci assert --config=config/lighthouserc.json`; console.log(`💻 Executing LHCI...`); @@ -98,6 +114,7 @@ async function main() { execSync(lhciCommand, { encoding: 'utf8', stdio: 'inherit', + env: { ...process.env, CHROME_PATH: chromePath }, }); } catch (err: any) { console.warn('⚠️ LHCI assertion finished with warnings or errors.');