Skip to content

Commit 3628cea

Browse files
authoredMar 8, 2022
misc: support --chrome-flags in run devtools script (#13625)
1 parent 13eb37f commit 3628cea

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
 

‎.github/workflows/devtools.yml

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ jobs:
152152
- run: yarn --frozen-lockfile --network-timeout 1000000
153153
working-directory: ${{ github.workspace }}/lighthouse
154154

155+
# This is only done because the import of `parseChromeFlags` in pptr-run-devtool.js triggers imports that eventually
156+
# fail because of how report-assets.js reads generated files.
157+
- run: yarn build-report
158+
working-directory: ${{ github.workspace }}/lighthouse
159+
155160
- name: Define ToT chrome path
156161
run: echo "CHROME_PATH=/Users/runner/chrome-mac-tot/Chromium.app/Contents/MacOS/Chromium" >> $GITHUB_ENV
157162
- name: Install Chrome ToT

‎lighthouse-cli/test/smokehouse/lighthouse-runners/devtools.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ async function runLighthouse(url, configJson, testRunnerOptions = {}) {
7575
await buildDevtoolsPromise;
7676

7777
const outputDir = fs.mkdtempSync(os.tmpdir() + '/lh-smoke-cdt-runner-');
78+
const chromeFlags = [
79+
`--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`,
80+
];
7881
const args = [
7982
'run-devtools',
8083
url,
81-
`--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`,
84+
`--chrome-flags=${chromeFlags.join(' ')}`,
8285
'--output-dir', outputDir,
8386
];
8487
if (configJson) {

‎lighthouse-core/scripts/pptr-run-devtools.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
*
1313
* To use with locally built DevTools and Lighthouse, run (assuming devtools at ~/src/devtools/devtools-frontend):
1414
* yarn devtools
15-
* yarn run-devtools --custom-devtools-frontend=file://$HOME/src/devtools/devtools-frontend/out/Default/gen/front_end
15+
* yarn run-devtools --chrome-flags=--custom-devtools-frontend=file://$HOME/src/devtools/devtools-frontend/out/Default/gen/front_end
1616
*
1717
* Or with the DevTools in .tmp:
1818
* bash lighthouse-core/test/chromium-web-tests/setup.sh
19-
* yarn run-devtools --custom-devtools-frontend=file://$PWD/.tmp/chromium-web-tests/devtools/devtools-frontend/out/Default/gen/front_end
19+
* yarn run-devtools --chrome-flags=--custom-devtools-frontend=file://$PWD/.tmp/chromium-web-tests/devtools/devtools-frontend/out/Default/gen/front_end
2020
*
2121
* URL list file: yarn run-devtools < path/to/urls.txt
2222
* Single URL: yarn run-devtools "https://example.com"
@@ -30,6 +30,8 @@ import puppeteer from 'puppeteer';
3030
import yargs from 'yargs';
3131
import * as yargsHelpers from 'yargs/helpers';
3232

33+
import {parseChromeFlags} from '../../lighthouse-cli/run.js';
34+
3335
const y = yargs(yargsHelpers.hideBin(process.argv));
3436
const argv_ = y
3537
.usage('$0 [url]')
@@ -40,9 +42,9 @@ const argv_ = y
4042
default: 'latest-run/devtools-lhrs',
4143
alias: 'o',
4244
})
43-
.option('custom-devtools-frontend', {
45+
.option('chrome-flags', {
4446
type: 'string',
45-
alias: 'd',
47+
default: '',
4648
})
4749
.option('config', {
4850
type: 'string',
@@ -287,6 +289,7 @@ async function readUrlList() {
287289
}
288290

289291
async function run() {
292+
const chromeFlags = parseChromeFlags(argv['chromeFlags']);
290293
const outputDir = argv['output-dir'];
291294

292295
// Create output directory.
@@ -299,7 +302,9 @@ async function run() {
299302
fs.mkdirSync(outputDir);
300303
}
301304

302-
const customDevtools = argv['custom-devtools-frontend'];
305+
const customDevtools = chromeFlags
306+
.find(f => f.startsWith('--custom-devtools-frontend='))
307+
?.replace('--custom-devtools-frontend=', '');
303308
if (customDevtools) {
304309
console.log(`Using custom devtools frontend: ${customDevtools}`);
305310
console.log('Make sure it has been built recently!');
@@ -313,7 +318,7 @@ async function run() {
313318

314319
const browser = await puppeteer.launch({
315320
executablePath: process.env.CHROME_PATH,
316-
args: customDevtools ? [`--custom-devtools-frontend=${customDevtools}`] : [],
321+
args: chromeFlags,
317322
devtools: true,
318323
});
319324

0 commit comments

Comments
 (0)
Please sign in to comment.