Skip to content

Commit 65170e5

Browse files
committed
WIP: puppeteer upgraded, working locally onSuccess
1 parent e067064 commit 65170e5

File tree

6 files changed

+374
-55
lines changed

6 files changed

+374
-55
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"express": "^4.17.1",
3131
"html-minifier": "^4.0.0",
3232
"lighthouse": "^9.6.3",
33-
"puppeteer": "^18.0.0"
33+
"puppeteer": "^24.8.2"
3434
},
3535
"engines": {
3636
"node": ">=18.14.0"

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, getBrowserPath } from '../../run-lighthouse.js';
4+
import { runLighthouse } 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-
const browserPath = await getBrowserPath();
19+
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(browserPath, fullPath, settings);
25+
const results = await runLighthouse("PLACEHOLDER", fullPath, settings);
2626
resolve({ error: false, results });
2727
} catch (error) {
2828
resolve({ error });

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { formatResults } from '../../format.js';
2-
import { runLighthouse, getBrowserPath } from '../../run-lighthouse.js';
2+
import { runLighthouse } from '../../run-lighthouse.js';
33

44
const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => {
55
try {
6-
const browserPath = await getBrowserPath();
7-
86
const getResults = async () => {
97
const fullPath = path ? `${url}/${path}` : url;
10-
const results = await runLighthouse(browserPath, fullPath, settings);
8+
const results = await runLighthouse(fullPath, settings);
119

1210
try {
1311
return { results };
@@ -19,6 +17,7 @@ const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => {
1917
const { error, results } = await getResults();
2018

2119
if (error) {
20+
console.log("error line 22 run audit with url", error)
2221
return { error };
2322
} else {
2423
const { summary, shortSummary, details, report, errors, runtimeError } =
@@ -37,6 +36,7 @@ const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => {
3736
};
3837
}
3938
} catch (error) {
39+
console.log("error line 41 run audit with url", error)
4040
return { error };
4141
}
4242
};

src/lib/run-event/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const runEvent = async ({
1717
} = {}) => {
1818
const isOnSuccess = event === 'onSuccess';
1919

20-
const deployUrl = process.env.DEPLOY_URL;
20+
const deployUrl = 'https://68244ec43a5a6b46e855abe0--testing-secret-scanning-ui.netlify.app/';
2121

2222
// If we don't have the deploy URL to test against, we can't run Lighthouse onSuccess.
2323
// If running locally, ensure you have a DEPLOY_URL set in your .env file
@@ -67,6 +67,7 @@ const runEvent = async ({
6767
});
6868

6969
console.log(startMessage);
70+
console.log('*** url', url);
7071

7172
const runner = isOnSuccess ? runAuditWithUrl : runAuditWithServer;
7273
const { errors, summary, shortSummary, details, report, runtimeError } =

src/run-lighthouse.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
import puppeteer from 'puppeteer';
1+
import puppeteer from 'puppeteer';
22
import lighthouse from 'lighthouse';
33
import log from 'lighthouse-logger';
4-
import chromeLauncher from 'chrome-launcher';
54

6-
export const getBrowserPath = async () => {
7-
const browserFetcher = puppeteer.createBrowserFetcher();
8-
const revisions = await browserFetcher.localRevisions();
9-
if (revisions.length <= 0) {
10-
throw new Error('Could not find local browser');
11-
}
12-
const info = await browserFetcher.revisionInfo(revisions[0]);
13-
return info.executablePath;
14-
};
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+
// };
1514

16-
export const runLighthouse = async (browserPath, url, settings) => {
15+
export const runLighthouse = async (url, settings) => {
1716
let chrome;
1817
try {
1918
const logLevel = 'error';
2019
log.setLevel(logLevel);
21-
chrome = await chromeLauncher.launch({
22-
chromePath: browserPath,
23-
chromeFlags: [
20+
chrome = await puppeteer.launch({
21+
args: [
2422
'--headless',
2523
'--no-sandbox',
2624
'--disable-gpu',
2725
'--disable-dev-shm-usage',
26+
'--remote-debugging-port=0'
2827
],
2928
logLevel,
3029
});
30+
31+
// Get the debugging port from the browser's websocket endpoint
32+
const browserWSEndpoint = chrome.wsEndpoint();
33+
const port = parseInt(browserWSEndpoint.split(':')[2].split('/')[0], 10);
34+
3135
const results = await lighthouse(
3236
url,
3337
{
34-
port: chrome.port,
38+
port,
3539
output: 'html',
3640
logLevel,
3741
},
@@ -40,7 +44,7 @@ export const runLighthouse = async (browserPath, url, settings) => {
4044
return results;
4145
} finally {
4246
if (chrome) {
43-
await chrome.kill();
47+
await chrome.close();
4448
}
4549
}
4650
};

0 commit comments

Comments
 (0)