Skip to content

Commit f254253

Browse files
committed
cache the browser path to prevent dupes
1 parent 9fc3998 commit f254253

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/run-lighthouse.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ import lighthouse from 'lighthouse';
33
import log from 'lighthouse-logger';
44
import chromeLauncher from 'chrome-launcher';
55

6+
// Cache the browser path to avoid multiple launches
7+
let cachedBrowserPath;
8+
69
export const getBrowserPath = async () => {
10+
if (cachedBrowserPath) {
11+
return cachedBrowserPath;
12+
}
13+
714
const browser = await puppeteer.launch({
815
headless: 'new',
916
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
1017
});
11-
const path = browser.process().spawnfile;
18+
cachedBrowserPath = browser.process().spawnfile;
1219
await browser.close();
13-
return path;
20+
return cachedBrowserPath;
1421
};
1522

1623
export const runLighthouse = async (browserPath, url, settings) => {

0 commit comments

Comments
 (0)