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

Update benchmark-web-vitals to allow connection to existing browser instance (e.g. on mobile device) #58

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 13 additions & 1 deletion cli/commands/benchmark-web-vitals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,20 @@ export const options = [
description:
'Whether to show more granular percentiles instead of only the median',
},
{
argname: '-c, --connect <browserWSEndpoint>',
description: 'Connect to an existing browser instance',
},
];

async function getBrowser( opt ) {
return opt.connect
? puppeteer.connect( {
browserWSEndpoint: opt.connect,
} )
: puppeteer.launch();
}

export async function handler( opt ) {
if ( ! isValidTableFormat( opt.output ) ) {
log(
Expand All @@ -78,7 +90,7 @@ export async function handler( opt ) {
const { number: amount } = opt;
const results = [];

const browser = await puppeteer.launch();
const browser = await getBrowser( opt );

for await ( const url of getURLs( opt ) ) {
const { completeRequests, metrics } = await benchmarkURL( browser, {
Expand Down
3 changes: 2 additions & 1 deletion cli/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const catchException = ( handler ) => {
try {
await handler( ...args );
} catch ( error ) {
log( formats.error( error ) );
log( formats.error( `Error: ${ error.message }` ) );
console.error( error ); // eslint-disable-line no-console
process.exitCode = 1;
}
};
Expand Down
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"csv-stringify": "^6.2.0",
"lodash-es": "4.17.21",
"node-fetch": "^3.3.0",
"prettier": "npm:[email protected]",
"puppeteer": "^19",
"table": "^6.8.0"
},
Expand Down