Skip to content

Commit 049ce65

Browse files
committed
try installing chrome
1 parent a7cbc2c commit 049ce65

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/run-lighthouse.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import lighthouse from 'lighthouse';
22
import chromeLauncher from 'chrome-launcher';
33
import log from 'lighthouse-logger';
44
import puppeteer from 'puppeteer';
5+
import { install } from '@puppeteer/browsers';
56

67
export const runLighthouse = async (url, settings) => {
78
let chrome;
@@ -22,19 +23,25 @@ export const runLighthouse = async (url, settings) => {
2223
handleSIGINT: true,
2324
};
2425

25-
// Get browser executable from puppeteer
26-
const browser = await puppeteer.launch({
27-
headless: 'new',
28-
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']
29-
});
30-
26+
// Install Chrome if needed and get its path
3127
try {
28+
console.log('Installing Chrome via puppeteer...');
29+
await install({
30+
browser: 'chrome',
31+
buildId: 'stable'
32+
});
33+
34+
const browser = await puppeteer.launch({
35+
headless: 'new',
36+
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']
37+
});
38+
3239
const browserPath = browser.executablePath();
3340
console.log(`Using Chrome from puppeteer: ${browserPath}`);
3441
launchOptions.chromePath = browserPath;
3542
await browser.close();
3643
} catch (error) {
37-
await browser.close();
44+
console.log('Error installing/launching Chrome:', error.message);
3845
// Fallback to environment variable if puppeteer's Chrome is not available
3946
if (process.env.CHROME_PATH) {
4047
console.log(`Using Chrome from environment: ${process.env.CHROME_PATH}`);

0 commit comments

Comments
 (0)