Skip to content

Commit 868de7b

Browse files
committed
wholly puppeteer
1 parent 15ce11d commit 868de7b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/run-lighthouse.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
import lighthouse from 'lighthouse';
2-
import chromeLauncher from 'chrome-launcher';
2+
import puppeteer from 'puppeteer';
33
import log from 'lighthouse-logger';
44

55
export const runLighthouse = async (url, settings) => {
6-
let chrome;
6+
let browser;
77
try {
88
const logLevel = settings?.logLevel || 'error';
99
log.setLevel(logLevel);
1010

11-
// Launch Chrome using chrome-launcher
12-
chrome = await chromeLauncher.launch({
13-
chromeFlags: [
14-
'--headless=new',
11+
// Launch Chrome using Puppeteer with CI-friendly flags
12+
browser = await puppeteer.launch({
13+
headless: 'new',
14+
args: [
1515
'--no-sandbox',
1616
'--disable-gpu',
1717
'--disable-dev-shm-usage',
1818
'--disable-software-rasterizer',
1919
'--disable-setuid-sandbox',
2020
'--no-zygote',
21+
'--disable-web-security',
22+
'--allow-running-insecure-content',
23+
'--disable-features=IsolateOrigins,site-per-process',
2124
],
22-
logLevel,
23-
handleSIGINT: true,
25+
ignoreDefaultArgs: ['--enable-automation'],
2426
});
2527

28+
// Get the browser's websocket endpoint and extract the port
29+
const browserWSEndpoint = browser.wsEndpoint();
30+
const port = parseInt(browserWSEndpoint.split(':')[2].split('/')[0], 10);
31+
2632
const results = await lighthouse(
2733
url,
2834
{
29-
port: chrome.port,
35+
port,
3036
output: 'html',
3137
logLevel,
3238
onlyCategories: settings?.onlyCategories,
@@ -37,8 +43,8 @@ export const runLighthouse = async (url, settings) => {
3743
);
3844
return results;
3945
} finally {
40-
if (chrome) {
41-
await chrome.kill();
46+
if (browser) {
47+
await browser.close();
4248
}
4349
}
4450
};

0 commit comments

Comments
 (0)