Skip to content

Commit a7cbc2c

Browse files
committed
is chrome available now?
1 parent b6f6fe0 commit a7cbc2c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/run-lighthouse.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import lighthouse from 'lighthouse';
22
import chromeLauncher from 'chrome-launcher';
33
import log from 'lighthouse-logger';
4+
import puppeteer from 'puppeteer';
45

56
export const runLighthouse = async (url, settings) => {
67
let chrome;
@@ -21,13 +22,26 @@ export const runLighthouse = async (url, settings) => {
2122
handleSIGINT: true,
2223
};
2324

24-
// Let chrome-launcher find Chrome in the environment
25-
if (process.env.CHROME_PATH) {
26-
console.log(`Using Chrome from environment: ${process.env.CHROME_PATH}`);
27-
launchOptions.chromePath = process.env.CHROME_PATH;
28-
} else {
29-
// Let chrome-launcher find Chrome automatically
30-
console.log('Letting chrome-launcher find Chrome...');
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+
31+
try {
32+
const browserPath = browser.executablePath();
33+
console.log(`Using Chrome from puppeteer: ${browserPath}`);
34+
launchOptions.chromePath = browserPath;
35+
await browser.close();
36+
} catch (error) {
37+
await browser.close();
38+
// Fallback to environment variable if puppeteer's Chrome is not available
39+
if (process.env.CHROME_PATH) {
40+
console.log(`Using Chrome from environment: ${process.env.CHROME_PATH}`);
41+
launchOptions.chromePath = process.env.CHROME_PATH;
42+
} else {
43+
console.log('Letting chrome-launcher find Chrome...');
44+
}
3145
}
3246

3347
chrome = await chromeLauncher.launch(launchOptions);

0 commit comments

Comments
 (0)