Skip to content

Commit 20c9d01

Browse files
committed
updated to work with onPostBuild step also
1 parent 65170e5 commit 20c9d01

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/lib/run-audit-with-server/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'path';
22

33
import { formatResults } from '../../format.js';
4-
import { runLighthouse } from '../../run-lighthouse.js';
4+
import { runLighthouse, getBrowserPath } from '../../run-lighthouse.js';
55
import persistResults from '../persist-results/index.js';
66
import getServer from '../get-server/index.js';
77

@@ -16,13 +16,13 @@ const runAuditWithServer = async ({
1616
try {
1717
const { server } = getServer({ serveDir: serveDir, auditUrl: url });
1818

19-
19+
const browserPath = await getBrowserPath();
2020

2121
const { error, results } = await new Promise((resolve) => {
2222
const instance = server.listen(async () => {
2323
try {
2424
const fullPath = path ? `${server.url}/${path}` : server.url;
25-
const results = await runLighthouse("PLACEHOLDER", fullPath, settings);
25+
const results = await runLighthouse(browserPath, fullPath, settings);
2626
resolve({ error: false, results });
2727
} catch (error) {
2828
resolve({ error });

src/run-lighthouse.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import puppeteer from 'puppeteer';
22
import lighthouse from 'lighthouse';
33
import log from 'lighthouse-logger';
44

5-
// export const getBrowserPath = async () => {
6-
// const browserFetcher = new BrowserFetcher();
7-
// const revisions = await browserFetcher.localRevisions();
8-
// if (revisions.length <= 0) {
9-
// throw new Error('Could not find local browser');
10-
// }
11-
// const info = await browserFetcher.revisionInfo(revisions[0]);
12-
// return info.executablePath;
13-
// };
5+
export const getBrowserPath = async () => {
6+
// In newer Puppeteer versions, we can get the executable path directly
7+
return puppeteer.executablePath();
8+
};
149

15-
export const runLighthouse = async (url, settings) => {
10+
export const runLighthouse = async (browserPath, url, settings) => {
1611
let chrome;
1712
try {
1813
const logLevel = 'error';
1914
log.setLevel(logLevel);
2015
chrome = await puppeteer.launch({
16+
executablePath: browserPath,
2117
args: [
2218
'--headless',
2319
'--no-sandbox',

0 commit comments

Comments
 (0)