Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: support --chrome-flags in run devtools script #13625

Merged
merged 7 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/devtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ jobs:
- run: yarn --frozen-lockfile --network-timeout 1000000
working-directory: ${{ github.workspace }}/lighthouse

# This is only done because the import of `parseChromeFlags` in pptr-run-devtool.js triggers imports that eventually
# fail because of how report-assets.js reads generated files.
- run: yarn build-report
working-directory: ${{ github.workspace }}/lighthouse

- name: Define ToT chrome path
run: echo "CHROME_PATH=/Users/runner/chrome-mac-tot/Chromium.app/Contents/MacOS/Chromium" >> $GITHUB_ENV
- name: Install Chrome ToT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ async function runLighthouse(url, configJson, testRunnerOptions = {}) {
await buildDevtoolsPromise;

const outputDir = fs.mkdtempSync(os.tmpdir() + '/lh-smoke-cdt-runner-');
const chromeFlags = [
`--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`,
];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be wanting to add to this in the future.

const args = [
'run-devtools',
url,
`--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`,
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
`--chrome-flags=${chromeFlags.join(' ')}`,
'--output-dir', outputDir,
];
if (configJson) {
Expand Down
17 changes: 11 additions & 6 deletions lighthouse-core/scripts/pptr-run-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*
* To use with locally built DevTools and Lighthouse, run (assuming devtools at ~/src/devtools/devtools-frontend):
* yarn devtools
* yarn run-devtools --custom-devtools-frontend=file://$HOME/src/devtools/devtools-frontend/out/Default/gen/front_end
* yarn run-devtools --chrome-flags=--custom-devtools-frontend=file://$HOME/src/devtools/devtools-frontend/out/Default/gen/front_end
*
* Or with the DevTools in .tmp:
* bash lighthouse-core/test/chromium-web-tests/setup.sh
* yarn run-devtools --custom-devtools-frontend=file://$PWD/.tmp/chromium-web-tests/devtools/devtools-frontend/out/Default/gen/front_end
* yarn run-devtools --chrome-flags=--custom-devtools-frontend=file://$PWD/.tmp/chromium-web-tests/devtools/devtools-frontend/out/Default/gen/front_end
*
* URL list file: yarn run-devtools < path/to/urls.txt
* Single URL: yarn run-devtools "https://example.com"
Expand All @@ -30,6 +30,8 @@ import puppeteer from 'puppeteer';
import yargs from 'yargs';
import * as yargsHelpers from 'yargs/helpers';

import {parseChromeFlags} from '../../lighthouse-cli/run.js';

const y = yargs(yargsHelpers.hideBin(process.argv));
const argv_ = y
.usage('$0 [url]')
Expand All @@ -40,9 +42,9 @@ const argv_ = y
default: 'latest-run/devtools-lhrs',
alias: 'o',
})
.option('custom-devtools-frontend', {
.option('chrome-flags', {
type: 'string',
alias: 'd',
default: '',
})
.option('config', {
type: 'string',
Expand Down Expand Up @@ -287,6 +289,7 @@ async function readUrlList() {
}

async function run() {
const chromeFlags = parseChromeFlags(argv['chromeFlags']);
const outputDir = argv['output-dir'];

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

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

const browser = await puppeteer.launch({
executablePath: process.env.CHROME_PATH,
args: customDevtools ? [`--custom-devtools-frontend=${customDevtools}`] : [],
args: chromeFlags,
devtools: true,
});

Expand Down