sitespeed.io
Version:
sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
1,284 lines (1,245 loc) • 83.5 kB
JavaScript
import path from 'node:path';
import { platform } from 'node:os';
import { createRequire } from 'node:module';
import { readFileSync, statSync } from 'node:fs';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import merge from 'lodash.merge';
import set from 'lodash.set';
import get from 'lodash.get';
import { getURLs, getAliases } from './util.js';
import { toArray } from '../support/util.js';
import friendlynames from '../support/friendlynames.js';
import { config as browsertimeConfig } from '../plugins/browsertime/index.js';
import { config as metricsConfig } from '../plugins/metrics/index.js';
import { config as slackConfig } from '../plugins/slack/index.js';
import { config as htmlConfig } from '../plugins/html/index.js';
import { messageTypes as matrixMessageTypes } from '../plugins/matrix/index.js';
import { findUpSync } from '../support/fileUtil.js';
import { registerPluginOptions } from './pluginOptions.js';
const metricList = Object.keys(friendlynames);
const require = createRequire(import.meta.url);
const version = require('../../package.json').version;
const configFiles = ['.sitespeed.io.json'];
const addedPlugins = yargs(hideBin(process.argv))
.option('plugins.add', { type: 'array' })
.help(false)
.version(false)
.parse();
const globalPluginsToAdd = addedPlugins.plugins?.add || [];
function fixAndroidArgs(args) {
return args.map(arg => (arg === '--android' ? '--android.enabled' : arg));
}
if (process.argv.includes('--config')) {
const index = process.argv.indexOf('--config');
configFiles.unshift(process.argv[index + 1]);
}
const configPath = findUpSync(configFiles);
let config;
try {
config = configPath ? JSON.parse(readFileSync(configPath)) : undefined;
if (config && process.argv.includes('--ignoreExtends')) {
delete config.extends;
}
} catch (error) {
if (error instanceof SyntaxError) {
console.error(
'Error: Could not parse the config JSON file ' +
configPath +
'. Is the file really valid JSON?'
);
}
throw error;
}
function validateInput(argv) {
// Check NodeJS major version
const fullVersion = process.versions.node;
const minVersion = 20;
const majorVersion = fullVersion.split('.')[0];
if (majorVersion < minVersion) {
return (
'Error: You need to have at least NodeJS version ' +
minVersion +
' to run sitespeed.io. You are using version ' +
fullVersion
);
}
if (argv.headless && (argv.video || argv.visualMetrics)) {
return 'Error: You cannot combine headless with video/visualMetrics because they need a screen to work.';
}
if (Array.isArray(argv.browsertime.iterations)) {
return 'Error: Ooops you passed number of iterations twice, remove one of them and try again.';
}
if (Array.isArray(argv.browser)) {
return 'Error: You can only run with one browser at a time.';
}
if (argv.outputFolder && argv.copyLatestFilesToBase) {
return 'Error: Setting --outputfolder do not work together with --copyLatestFilesToBase';
}
if (argv.slug) {
const characters = /[^\w-]/g;
if (characters.test(argv.slug)) {
return 'The slug can only use characters A-Z a-z 0-9 and -_.';
}
if (argv.slug.length > 200) {
return 'The max length for the slug is 200 characters.';
}
}
if (argv.crawler && argv.crawler.depth && argv.multi) {
return 'Error: Crawl do not work running in multi mode.';
}
if (argv.crux && argv.crux.key && argv.multi) {
return 'Error: Getting CrUx data do not work running in multi mode.';
}
/*
if (argv.browsertime.cpu && argv.browsertime.enableProfileRun) {
return 'Error: Use either --cpu or --enableProfileRun. Profile run will run one extra iteration to collect cpu/trace data.';
}*/
if (
argv.urlAlias &&
argv._ &&
getURLs(argv._).length !== toArray(argv.urlAlias).length
) {
return 'Error: You have a miss match between number of alias and URLs.';
}
if (
argv.groupAlias &&
argv._ &&
getURLs(argv._).length !== toArray(argv.groupAlias).length
) {
return 'Error: You have a miss match between number of alias for groups and URLs.';
}
if (
argv.browsertime.connectivity &&
argv.browsertime.connectivity.engine === 'humble' &&
(!argv.browsertime.connectivity.humble ||
!argv.browsertime.connectivity.humble.url)
) {
return 'You need to specify the URL to Humble by using the --browsertime.connectivity.humble.url option.';
}
if (
argv.browsertime.safari &&
argv.browsertime.safari.useSimulator &&
argv.browsertime.docker
) {
return 'You cannot use Safari simulator in Docker. You need to run on directly on Mac OS.';
}
if (
argv.browsertime.safari &&
argv.browsertime.safari.useSimulator &&
!argv.browsertime.safari.deviceUDID
) {
return 'You need to specify the --safari.deviceUDID when you run the simulator. Run "xcrun simctl list devices" in your terminal to list all devices.';
}
if (argv.browsertime.debug && argv.browsertime.browser === 'safari') {
return 'Debug mode do not work in Safari. Please try with Firefox/Chrome or Edge';
}
if (argv.browsertime.debug && argv.android) {
return 'Debug mode do not work on Android. Please run debug mode on Desktop.';
}
if (argv.browsertime.debug && argv.docker) {
return 'There is no benefit running debug mode inside a Docker container.';
}
// If we ask the API for finished test, we don't need a URL
if (argv._.length === 0 && !argv.api.id) {
return 'You need to supply one/multiple URLs or scripts';
}
// validate URLs/files
const urlOrFiles = argv._;
for (let urlOrFile of urlOrFiles) {
if (!urlOrFile.startsWith('http')) {
// is existing file?
try {
statSync(urlOrFile);
} catch {
return (
'Error: ' +
urlOrFile +
' does not exist, is the path to the file correct?'
);
}
}
}
for (let metric of toArray(argv.html.pageSummaryMetrics)) {
const [m, k] = metric.split('.');
if (
!metricList.some(
tools => friendlynames[tools][m] && friendlynames[tools][m][k]
)
) {
return 'Error: Require summary page metrics to be from given array';
}
}
for (let metric of toArray(argv.html.summaryBoxes)) {
if (!htmlConfig.html.summaryBoxes.includes(metric)) {
return `Error: ${metric} is not part of summary box metric.`;
}
}
if (argv.html && argv.html.summaryBoxesThresholds) {
try {
const box = readFileSync(path.resolve(argv.html.summaryBoxesThresholds), {
encoding: 'utf8'
});
argv.html.summaryBoxesThresholds = JSON.parse(box);
} catch (error) {
return (
'Error: Could not read ' +
argv.html.summaryBoxesThresholds +
' ' +
error
);
}
}
return true;
}
export async function parseCommandLine() {
const fixedArgs = fixAndroidArgs(hideBin(process.argv));
const yargsInstance = yargs(fixedArgs);
yargsInstance
.parserConfiguration({
'camel-case-expansion': false,
'deep-merge-config': true
})
.env('SITESPEED_IO')
.usage('$0 [options] <url>/<file>')
.option('debugMessages', {
default: false,
describe:
'Debug mode logs all internal messages in the message queue to the log.',
type: 'boolean'
})
.option('verbose', {
alias: ['v'],
describe:
'Verbose mode prints progress messages to the console. Enter up to three times (-vvv)' +
' to increase the level of detail.',
type: 'count'
})
/*
Browsertime cli options
*/
.option('browsertime.browser', {
alias: ['b', 'browser'],
default: browsertimeConfig.browser,
describe:
'Choose which Browser to use when you test. Safari only works on Mac OS X and iOS 13 (or later).',
choices: ['chrome', 'firefox', 'safari', 'edge'],
group: 'Browser'
})
.option('browsertime.iterations', {
alias: 'n',
default: browsertimeConfig.iterations,
describe: 'How many times you want to test each page',
group: 'Browser'
})
.option('browsertime.xvfb', {
alias: 'xvfb',
type: 'boolean',
default: false,
describe: 'Start xvfb before the browser is started'
})
.option('browsertime.xvfbParams.display', {
alias: 'xvfbParams.display',
default: 99,
describe: 'The display used for xvfb'
})
.option('browsertime.spa', {
alias: 'spa',
describe:
'Convenient parameter to use if you test a SPA application: will automatically wait for X seconds after last network activity and use hash in file names. Read https://www.sitespeed.io/documentation/sitespeed.io/spa/',
type: 'boolean',
default: false,
group: 'Browser'
})
.option('browsertime.debug', {
alias: 'debug',
type: 'boolean',
default: false,
describe:
'Run Browsertime in debug mode. Use commands.breakpoint(name) to set breakpoints in your script. Debug mode works for Firefox/Chrome/Edge on desktop.',
group: 'Browser'
})
.option('browsertime.limitedRunData', {
type: 'boolean',
default: true,
describe: 'Send only limited metrics from one run to the datasource.',
group: 'Browser'
})
.option('browsertime.android.gnirehtet', {
alias: ['gnirehtet', 'browsertime.gnirehtet'],
type: 'boolean',
default: false,
describe:
'Start gnirehtet and reverse tethering the traffic from your Android phone.',
group: 'Android'
})
.option('browsertime.connectivity.profile', {
alias: 'c',
default: browsertimeConfig.connectivity.profile,
choices: [
'4g',
'3g',
'3gfast',
'3gslow',
'3gem',
'2g',
'cable',
'native',
'custom'
],
describe:
'The connectivity profile. To actually set the connectivity you can choose between Docker networks or Throttle, read https://www.sitespeed.io/documentation/sitespeed.io/connectivity/',
type: 'string',
group: 'Browser'
})
.option('browsertime.connectivity.alias', {
describe: 'Give your connectivity profile a custom name',
type: 'string',
group: 'Browser'
})
.option('browsertime.connectivity.down', {
default: browsertimeConfig.connectivity.downstreamKbps,
alias: ['downstreamKbps', 'browsertime.connectivity.downstreamKbps'],
describe: 'This option requires --connectivity be set to "custom".',
group: 'Browser'
})
.option('browsertime.connectivity.up', {
default: browsertimeConfig.connectivity.upstreamKbps,
alias: ['upstreamKbps', 'browsertime.connectivity.upstreamKbps'],
describe: 'This option requires --connectivity be set to "custom".',
group: 'Browser'
})
.option('browsertime.connectivity.rtt', {
default: browsertimeConfig.connectivity.latency,
alias: ['latency', 'browsertime.connectivity.latency'],
describe: 'This option requires --connectivity be set to "custom".',
group: 'Browser'
})
.option('browsertime.connectivity.engine', {
alias: 'connectivity.engine',
default: 'external',
choices: ['external', 'throttle', 'humble'],
describe:
'The engine for connectivity. Throttle works on Mac and tc based Linux. For mobile you can use Humble if you have a Humble setup. Use external if you set the connectivity outside of Browsertime. More documentation at https://www.sitespeed.io/documentation/sitespeed.io/connectivity/.',
type: 'string',
group: 'Browser'
})
.option('browsertime.connectivity.humble.url', {
alias: 'connectivity.humble.url',
type: 'string',
describe:
'The path to your Humble instance. For example http://raspberrypi:3000',
group: 'Browser'
})
.option('browsertime.timeouts.pageCompleteCheck', {
alias: 'maxLoadTime',
default: 120_000,
type: 'number',
describe:
'The max load time to wait for a page to finish loading (in milliseconds).',
group: 'Browser'
})
.option('browsertime.pageCompleteCheck', {
alias: 'pageCompleteCheck',
describe:
'Supply a JavaScript that decides when the browser is finished loading the page and can start to collect metrics. The JavaScript snippet is repeatedly queried to see if page has completed loading (indicated by the script returning true). Checkout https://www.sitespeed.io/documentation/sitespeed.io/browsers/#choose-when-to-end-your-test ',
group: 'Browser'
})
.option('browsertime.pageCompleteWaitTime', {
alias: 'pageCompleteWaitTime',
describe:
'How long time you want to wait for your pageCompleteCheck to finish, after it is signaled to closed. Extra parameter passed on to your pageCompleteCheck.',
default: 5000,
group: 'Browser'
})
.option('browsertime.pageCompleteCheckInactivity', {
alias: 'pageCompleteCheckInactivity',
describe:
'Alternative way to choose when to end your test. This will wait for 2 seconds of inactivity that happens after loadEventEnd.',
type: 'boolean',
default: false,
group: 'Browser'
})
.option('browsertime.pageCompleteCheckPollTimeout', {
alias: 'pageCompleteCheckPollTimeout',
type: 'number',
default: 1500,
describe:
'The time in ms to wait for running the page complete check the next time.',
group: 'Browser'
})
.option('browsertime.pageCompleteCheckStartWait', {
alias: 'pageCompleteCheckStartWait',
type: 'number',
default: 500,
describe:
'The time in ms to wait for running the page complete check for the first time. Use this when you have a pageLoadStrategy set to none',
group: 'Browser'
})
.option('browsertime.pageCompleteCheckNetworkIdle', {
alias: 'pageCompleteCheckNetworkIdle',
type: 'boolean',
default: false,
describe:
'Use the network log instead of running JavaScript to decide when to end the test. This will wait for 5 seconds of no network activity before it ends the test. This can be used with Chrome/Edge and Firefox.',
group: 'Browser'
})
.option('browsertime.pageLoadStrategy', {
alias: 'pageLoadStrategy',
type: 'string',
default: 'none',
choices: ['eager', 'none', 'normal'],
describe:
'Set the strategy to waiting for document readiness after a navigation event. After the strategy is ready, your pageCompleteCheck will start running. This only work for Firefox and Chrome and please check which value each browser implements.',
group: 'Browser'
})
.option('browsertime.script', {
describe:
'Add custom Javascript that collect metrics and run after the page has finished loading. Note that --script can be passed multiple times if you want to collect multiple metrics. The metrics will automatically be pushed to the summary/detailed summary and each individual page + sent to Graphite',
alias: ['script'],
group: 'Browser'
})
.option('browsertime.injectJs', {
describe:
'Inject JavaScript into the current page at document_start. More info: https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/contentScripts',
alias: ['injectJs'],
group: 'Browser'
})
.option('browsertime.selenium.url', {
describe:
'Configure the path to the Selenium server when fetching timings using browsers. If not configured the supplied NodeJS/Selenium version is used.',
group: 'Browser'
})
.option('browsertime.viewPort', {
alias: 'viewPort',
default: browsertimeConfig.viewPort,
describe: 'The browser view port size WidthxHeight like 400x300',
group: 'Browser'
})
.option('browsertime.userAgent', {
alias: 'userAgent',
describe:
'The full User Agent string, defaults to the User Agent used by the browsertime.browser option.',
group: 'Browser'
})
.option('browsertime.appendToUserAgent', {
alias: 'appendToUserAgent',
describe:
'Append a String to the user agent. Works in Chrome/Edge and Firefox.',
group: 'Browser'
})
.option('browsertime.preURL', {
alias: 'preURL',
describe:
'A URL that will be accessed first by the browser before the URL that you wanna analyse. Use it to fill the cache.',
group: 'Browser'
})
.option('browsertime.preScript', {
alias: 'preScript',
describe:
'Selenium script(s) to run before you test your URL. They will run outside of the analyse phase. Note that --preScript can be passed multiple times.',
group: 'Browser'
})
.option('browsertime.postScript', {
alias: 'postScript',
describe:
'Selenium script(s) to run after you test your URL. They will run outside of the analyse phase. Note that --postScript can be passed multiple times.',
group: 'Browser'
})
.option('browsertime.delay', {
alias: 'delay',
describe:
'Delay between runs, in milliseconds. Use it if your web server needs to rest between runs :)',
group: 'Browser'
})
.option('browsertime.visualMetrics', {
alias: ['visualMetrics', 'speedIndex'],
type: 'boolean',
describe:
'Calculate Visual Metrics like SpeedIndex, First Visual Change and Last Visual Change. Requires FFMpeg and Python dependencies',
group: 'Browser'
})
.option('browsertime.visualMetricsPerceptual', {
alias: ['visualMetricsPerceptual'],
type: 'boolean',
describe: 'Collect Perceptual Speed Index when you run --visualMetrics.',
group: 'Browser'
})
.option('browsertime.visualMetricsContentful', {
alias: ['visualMetricsContentful'],
type: 'boolean',
describe: 'Collect Contentful Speed Index when you run --visualMetrics.',
group: 'Browser'
})
.option('browsertime.visualElements', {
type: 'boolean',
alias: ['visualElements'],
describe:
'Collect Visual Metrics from elements. Works only with --visualMetrics turned on. By default you will get visual metrics from the largest image within the view port and the largest h1. You can also configure to pickup your own defined elements with --scriptInput.visualElements',
group: 'Browser'
})
.option('browsertime.scriptInput.visualElements', {
alias: ['scriptInput.visualElements'],
describe:
'Include specific elements in visual elements. Give the element a name and select it with document.body.querySelector. Use like this: --scriptInput.visualElements name:domSelector . If you want to measure multiple elements, use a configuration file with an array for the input. Visual Metrics will use these elements and calculate when they are visible and fully rendered.',
group: 'Browser'
})
.option('browsertime.scriptInput.longTask', {
alias: 'minLongTaskLength',
description:
'Set the minimum length of a task to be categorised as a CPU Long Task. It can never be smaller than 50. The value is in ms and you make Browsertime collect long tasks using --chrome.collectLongTasks or --cpu.',
type: 'number',
default: 50,
group: 'Browser'
})
.option('browsertime.video', {
alias: 'video',
type: 'boolean',
describe:
'Record a video and store the video. Set it to false to remove the video that is created by turning on visualMetrics. To remove fully turn off video recordings, make sure to set video and visualMetrics to false. Requires FFMpeg to be installed.',
group: 'Browser'
})
.option('browsertime.videoParams.framerate', {
alias: ['videoParams.framerate', 'fps'],
default: 30,
describe: 'Frames per second in the video',
group: 'Browser'
})
.option('browsertime.videoParams.crf', {
alias: 'videoParams.crf',
default: 23,
describe:
'Constant rate factor for the end result video, see https://trac.ffmpeg.org/wiki/Encode/H.264#crf',
group: 'Browser'
})
.option('browsertime.videoParams.addTimer', {
alias: 'videoParams.addTimer',
default: true,
type: 'boolean',
describe: 'Add timer and metrics to the video',
group: 'Browser'
})
.option('browsertime.videoParams.convert', {
alias: 'videoParams.convert',
type: 'boolean',
default: true,
describe:
'Convert the original video to a viewable format (for most video players). Turn that off to make a faster run.',
group: 'Browser'
})
.option('browsertime.videoParams.keepOriginalVideo', {
alias: 'videoParams.keepOriginalVideo',
type: 'boolean',
default: false,
describe:
'Keep the original video. Use it when you have a Visual Metrics bug and want to create an issue at GitHub. Supply the original video in the issue and we can reproduce your issue.',
group: 'video'
})
.option('browsertime.cpu', {
alias: 'cpu',
type: 'boolean',
describe:
'Easy way to enable both chrome.timeline and CPU long tasks for Chrome and geckoProfile for Firefox',
group: 'Browser'
})
.option('browsertime.enableProfileRun', {
alias: 'enableProfileRun',
type: 'boolean',
describe:
'Make one extra run that collects the profiling trace log (no other metrics is collected). For Chrome it will collect the timeline trace, for Firefox it will get the Geckoprofiler trace. This means you do not need to get the trace for all runs and can skip the overhead it produces. You should not run this together with --cpu since that will get a trace for every iteration.'
})
.option('browsertime.enableVideoRun', {
alias: 'enableVideoRun',
type: 'boolean',
describe:
'Make one extra run that collects video and visual metrics. This means you can do your runs with --visualMetrics true --video false --enableVideoRun true to collect visual metrics from all runs and save a video from the profile/video run. If you run it together with --enableProfileRun it will also collect profiling race.'
})
.option('browsertime.videoParams.filmstripFullSize', {
alias: 'videoParams.filmstripFullSize',
type: 'boolean',
default: false,
describe:
'Keep original sized screenshots in the filmstrip. Will make the run take longer time',
group: 'Filmstrip'
})
.option('browsertime.videoParams.filmstripQuality', {
alias: 'videoParams.filmstripQuality',
default: 75,
describe: 'The quality of the filmstrip screenshots. 0-100.',
group: 'Filmstrip'
})
.option('browsertime.videoParams.createFilmstrip', {
alias: 'videoParams.createFilmstrip',
type: 'boolean',
default: true,
describe: 'Create filmstrip screenshots.',
group: 'Filmstrip'
})
.option('browsertime.videoParams.thumbsize', {
alias: 'videoParams.thumbsize',
default: 400,
describe:
'The maximum size of the thumbnail in the filmstrip. Default is 400 pixels in either direction. If browsertime.videoParams.filmstripFullSize is used that setting overrides this.',
group: 'Filmstrip'
})
.option('filmstrip.showAll', {
type: 'boolean',
default: false,
describe:
'Show all screenshots in the filmstrip, independent if they have changed or not.',
group: 'Filmstrip'
})
.option('browsertime.userTimingAllowList', {
alias: 'userTimingAllowList',
describe:
'This option takes a regex that will whitelist which userTimings to capture in the results. All userTimings are captured by default.',
group: 'Browser'
})
.option('axe.enable', {
type: 'boolean',
describe:
'Run axe tests. Axe will run after all other metrics is collected and will add some extra time to each test.',
group: 'Browser'
})
.option('browsertime.cjs', {
alias: 'cjs',
describe:
'Load scripting files that ends with .js as common js. Default (false) loads files as esmodules.',
type: 'boolean',
default: false
})
.option('browsertime.tcpdump', {
alias: 'tcpdump',
type: 'boolean',
default: false,
describe:
'Collect a tcpdump for each tested URL. The user that runs sitespeed.io should have sudo rights for tcpdump to work.'
})
.option('browsertime.firefox.includeResponseBodies', {
alias: 'firefox.includeResponseBodies',
describe: 'Collect response bodies in the HAR',
default: 'none',
choices: ['none', 'all'],
group: 'Firefox'
})
.option('browsertime.firefox.nightly', {
alias: 'firefox.nightly',
describe:
'Use Firefox Nightly. Works on OS X. For Linux you need to set the binary path.',
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.beta', {
alias: 'firefox.beta',
describe:
'Use Firefox Beta. Works on OS X. For Linux you need to set the binary path.',
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.developer', {
alias: 'firefox.developer',
describe:
'Use Firefox Developer. Works on OS X. For Linux you need to set the binary path.',
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.binaryPath', {
alias: 'firefox.binaryPath',
describe:
'Path to custom Firefox binary (e.g. Firefox Nightly). ' +
'On OS X, the path should be to the binary inside the app bundle, ' +
'e.g. /Applications/Firefox.app/Contents/MacOS/firefox-bin',
group: 'Firefox'
})
.option('browsertime.firefox.preference', {
alias: 'firefox.preference',
describe:
'Extra command line arguments to pass Firefox preferences by the format key:value ' +
'To add multiple preferences, repeat --firefox.preference once per argument.',
group: 'Firefox'
})
.option('browsertime.firefox.acceptInsecureCerts', {
alias: 'firefox.acceptInsecureCerts',
describe: 'Accept insecure certs',
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.memoryReport', {
alias: 'firefox.memoryReport',
describe: 'Measure firefox resident memory after each iteration.',
default: false,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.memoryReportParams.minizeFirst', {
alias: 'firefox.memoryReportParams.minizeFirst',
describe:
'Force a collection before dumping and measuring the memory report.',
default: false,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.geckoProfiler', {
alias: 'firefox.geckoProfiler',
describe: 'Collect a profile using the internal gecko profiler',
default: false,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.geckoProfilerParams.features', {
alias: 'firefox.geckoProfilerParams.features',
describe: 'Enabled features during gecko profiling',
default: 'js,stackwalk,leaf',
type: 'string',
group: 'Firefox'
})
.option('browsertime.firefox.geckoProfilerParams.threads', {
alias: 'firefox.geckoProfilerParams.threads',
describe: 'Threads to profile.',
default: 'GeckoMain,Compositor,Renderer',
type: 'string',
group: 'Firefox'
})
.option('browsertime.firefox.geckoProfilerParams.interval', {
alias: 'firefox.geckoProfilerParams.interval',
describe: `Sampling interval in ms. Defaults to 1 on desktop, and 4 on android.`,
type: 'number',
group: 'Firefox'
})
.option('browsertime.firefox.geckoProfilerParams.bufferSize', {
alias: 'firefox.geckoProfilerParams.bufferSize',
describe: 'Buffer size in elements. Default is ~90MB.',
default: 1_000_000,
type: 'number',
group: 'Firefox'
})
.option('browsertime.firefox.powerConsumption', {
alias: 'firefox.powerConsumption',
type: 'boolean',
default: false,
describe:
'Enable power consumption collection (in Wh). To get the consumption you also need to set firefox.geckoProfilerParams.features to include power.',
group: 'Firefox'
})
.option('browsertime.firefox.geckodriverArgs', {
alias: 'firefox.geckodriverArgs',
describe:
'Flags passed to Geckodriver see https://firefox-source-docs.mozilla.org/testing/geckodriver/Flags.html. Use it like --firefox.geckodriverArgs="--marionette-port" --firefox.geckodriverArgs=1027 ',
type: 'string',
group: 'Firefox'
})
.option('browsertime.firefox.windowRecorder', {
alias: 'firefox.windowRecorder',
describe:
'Use the internal compositor-based Firefox window recorder to emit PNG files for each ' +
'frame that is a meaningful change. The PNG output will further be merged into a ' +
'variable frame rate video for analysis. Use this instead of ffmpeg to record a video (you still need the --video flag).',
default: false,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.disableSafeBrowsing', {
alias: 'firefox.disableSafeBrowsing',
describe: 'Disable safebrowsing.',
default: true,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.disableTrackingProtection', {
alias: 'firefox.disableTrackingProtection',
describe: 'Disable Tracking Protection.',
default: true,
type: 'boolean',
group: 'Firefox'
})
.option('browsertime.firefox.android.package', {
alias: 'firefox.android.package',
describe:
'Run Firefox or a GeckoView-consuming App on your Android device. Set to org.mozilla.geckoview_example for default Firefox version. You need to have adb installed to make this work.',
group: 'Firefox'
})
.option('browsertime.firefox.android.activity', {
alias: 'firefox.android.activity',
describe: 'Name of the Activity hosting the GeckoView.',
group: 'Firefox'
})
.option('browsertime.firefox.android.deviceSerial', {
alias: 'firefox.android.deviceSerial',
type: 'string',
describe:
'Choose which device to use. If you do not set it, first device will be used.',
group: 'Firefox'
})
.option('browsertime.firefox.android.intentArgument', {
alias: 'firefox.android.intentArgument',
describe:
'Configure how the Android intent is launched. Passed through to `adb shell am start ...`; ' +
'follow the format at https://developer.android.com/studio/command-line/adb#IntentSpec. ' +
'To add multiple arguments, repeat --firefox.android.intentArgument once per argument.',
group: 'Firefox'
})
.option('browsertime.firefox.profileTemplate', {
alias: 'firefox.profileTemplate',
describe:
'Profile template directory that will be cloned and used as the base of each profile each instance of Firefox is launched against. Use this to pre-populate databases with certificates, tracking protection lists, etc.',
group: 'Firefox'
})
.option('browsertime.firefox.collectMozLog', {
alias: 'firefox.collectMozLog',
type: 'boolean',
describe: 'Collect the MOZ HTTP log',
group: 'Firefox'
})
.option('browsertime.chrome.args', {
alias: 'chrome.args',
describe:
'Extra command line arguments to pass to the Chrome process. If you use the command line, leave out the starting -- (--no-sandbox will be no-sandbox). If you use a configuration JSON file you should keep the starting --. ' +
'To add multiple arguments to Chrome, repeat --browsertime.chrome.args once per argument. See https://peter.sh/experiments/chromium-command-line-switches/',
group: 'Chrome'
})
.option('browsertime.chrome.timeline', {
alias: 'chrome.timeline',
describe:
'Collect the timeline data. Drag and drop the JSON in your Chrome detvools timeline panel or check out the CPU metrics.',
type: 'boolean',
default: false,
group: 'Chrome'
})
.option('browsertime.chrome.appendToUserAgent', {
alias: 'chrome.appendToUserAgent',
type: 'string',
describe: 'Append to the user agent.',
group: 'Chrome'
})
.option('browsertime.chrome.android.package', {
alias: 'chrome.android.package',
describe:
'Run Chrome on your Android device. Set to com.android.chrome for default Chrome version. You need to have adb installed to run on Android.',
group: 'Chrome'
})
.option('browsertime.chrome.android.activity', {
alias: 'chrome.android.activity',
describe: 'Name of the Activity hosting the WebView.',
group: 'Chrome'
})
.option('browsertime.chrome.android.process', {
alias: 'chrome.android.process',
describe:
'Process name of the Activity hosting the WebView. If not given, the process name is assumed to be the same as chrome.android.package.',
group: 'Chrome'
})
.option('browsertime.android.enabled', {
alias: ['android.enabled'],
type: 'boolean',
default: false,
describe:
'Short key to use Android. Will automatically use com.android.chrome for Chrome and stable Firefox. If you want to use another Chrome version, use --chrome.android.package'
})
.option('browsertime.android.rooted', {
alias: ['androidRooted', 'browsertime.androidRooted'],
type: 'boolean',
default: false,
describe:
'If your phone is rooted you can use this to set it up following Mozillas best practice for stable metrics.',
group: 'Android'
})
.option('browsertime.android.batteryTemperatureLimit', {
alias: [
'androidBatteryTemperatureLimit',
'browsertime.androidBatteryTemperatureLimit'
],
type: 'integer',
describe:
'Do the battery temperature need to be below a specific limit before we start the test?',
group: 'Android'
})
.option('browsertime.android.batteryTemperatureWaitTimeInSeconds', {
alias: [
'androidBatteryTemperatureWaitTimeInSeconds',
'browsertime.androidBatteryTemperatureWaitTimeInSeconds'
],
type: 'integer',
default: 120,
describe:
'How long time to wait (in seconds) if the androidBatteryTemperatureWaitTimeInSeconds is not met before the next try',
group: 'Android'
})
.option('browsertime.android.verifyNetwork', {
alias: ['androidVerifyNetwork', 'browsertime.androidVerifyNetwork'],
type: 'boolean',
default: false,
describe:
'Before a test start, verify that the device has a Internet connection by pinging 8.8.8.8 (or a configurable domain with --androidPingAddress)',
group: 'Android'
})
.option('browsertime.chrome.android.deviceSerial', {
alias: 'chrome.android.deviceSerial',
type: 'string',
describe:
'Choose which device to use. If you do not set it, the first found device will be used.',
group: 'Chrome'
})
.option('browsertime.chrome.collectNetLog', {
alias: 'chrome.collectNetLog',
type: 'boolean',
describe: 'Collect network log from Chrome and save to disk.',
group: 'Chrome'
})
.option('browsertime.chrome.traceCategories', {
alias: 'chrome.traceCategories',
describe: 'Set the trace categories.',
type: 'string',
group: 'Chrome'
})
.option('browsertime.chrome.traceCategory', {
alias: 'chrome.traceCategory',
describe:
'Add a trace category to the default ones. Use --chrome.traceCategory multiple times if you want to add multiple categories. Example: --chrome.traceCategory disabled-by-default-v8.cpu_profiler',
type: 'string',
group: 'Chrome'
})
.option('browsertime.chrome.enableTraceScreenshots', {
alias: 'chrome.enableTraceScreenshots',
describe:
'Include screenshots in the trace log (enabling the trace category disabled-by-default-devtools.screenshot).',
type: 'boolean',
group: 'Chrome'
})
.option('browsertime.chrome.collectConsoleLog', {
alias: 'chrome.collectConsoleLog',
type: 'boolean',
describe: 'Collect Chromes console log and save to disk.',
group: 'Chrome'
})
.option('browsertime.chrome.binaryPath', {
alias: 'chrome.binaryPath',
describe:
'Path to custom Chrome binary (e.g. Chrome Canary). ' +
'On OS X, the path should be to the binary inside the app bundle, ' +
'e.g. "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"',
group: 'Chrome'
})
.option('browsertime.chrome.chromedriverPath', {
alias: 'chrome.chromedriverPath',
describe:
"Path to custom ChromeDriver binary. Make sure to use a ChromeDriver version that's compatible with " +
"the version of Chrome you're using",
group: 'Chrome'
})
.option('browsertime.chrome.cdp.performance', {
alias: 'chrome.cdp.performance',
type: 'boolean',
default: true,
describe:
'Collect Chrome performance metrics from Chrome DevTools Protocol',
group: 'Chrome'
})
.option('browsertime.chrome.collectLongTasks', {
alias: 'chrome.collectLongTasks',
type: 'boolean',
describe: 'Collect CPU long tasks, using the Long Task API',
group: 'Chrome'
})
.option('browsertime.chrome.CPUThrottlingRate', {
alias: 'chrome.CPUThrottlingRate',
type: 'number',
describe:
'Enables CPU throttling to emulate slow CPUs. Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc)',
group: 'Chrome'
})
.option('browsertime.chrome.ignoreCertificateErrors', {
alias: 'chrome.ignoreCertificateErrors',
type: 'boolean',
default: true,
describe: 'Make Chrome ignore certificate errors. Defaults to true.',
group: 'Chrome'
})
.option('thirdParty.cpu', {
type: 'boolean',
describe:
'Enable CPU time spent data to Graphite/Grafana per third party tool.',
group: 'Chrome'
})
.option('browsertime.chrome.includeResponseBodies', {
alias: 'chrome.includeResponseBodies',
describe: 'Include response bodies in the HAR file.',
default: 'none',
choices: ['none', 'html', 'all'],
group: 'Chrome'
})
.option('browsertime.chrome.blockDomainsExcept', {
alias: 'chrome.blockDomainsExcept',
describe:
'Block all domains except this domain. Use it multiple time to keep multiple domains. You can also wildcard domains like *.sitespeed.io. Use this when you wanna block out all third parties.',
group: 'Chrome'
})
.option('browsertime.edge.edgedriverPath', {
alias: 'edge.edgedriverPath',
describe: 'To run Edge you need to supply the path to the msedgedriver',
group: 'Edge'
})
.option('browsertime.edge.binaryPath', {
alias: 'edge.binaryPath',
describe: 'Path to custom Edge binary',
group: 'Edge'
})
.option('browsertime.safari.ios', {
alias: 'safari.ios',
default: false,
describe:
'Use Safari on iOS. You need to choose browser Safari and iOS to run on iOS. Only works on OS X Catalina and iOS 13 (and later).',
type: 'boolean',
group: 'Safari'
})
.option('browsertime.safari.deviceName', {
alias: 'safari.deviceName',
describe:
'Set the device name. Device names for connected devices are shown in iTunes.',
group: 'Safari'
})
.option('browsertime.safari.deviceUDID', {
alias: 'safari.deviceUDID',
describe:
'Set the device UDID. If Xcode is installed, UDIDs for connected devices are available via the output of "xcrun simctl list devices" and in the Device and Simulators window (accessed in Xcode via "Window > Devices and Simulators")',
group: 'Safari'
})
.option('browsertime.safari.deviceType', {
alias: 'safari.deviceType',
describe:
'Set the device type. If the value of safari:deviceType is `iPhone`, safaridriver will only create a session using an iPhone device or iPhone simulator. If the value of safari:deviceType is `iPad`, safaridriver will only create a session using an iPad device or iPad simulator.',
group: 'Safari'
})
.option('browsertime.safari.useTechnologyPreview', {
alias: 'safari.useTechnologyPreview',
type: 'boolean',
default: false,
describe: 'Use Safari Technology Preview',
group: 'Safari'
})
.option('browsertime.safari.diagnose', {
alias: 'safari.diagnose',
describe:
'When filing a bug report against safaridriver, it is highly recommended that you capture and include diagnostics generated by safaridriver. Diagnostic files are saved to ~/Library/Logs/com.apple.WebDriver/',
group: 'Safari'
})
.option('browsertime.safari.useSimulator', {
alias: 'safari.useSimulator',
describe:
'If the value of useSimulator is true, safaridriver will only use iOS Simulator hosts. If the value of safari:useSimulator is false, safaridriver will not use iOS Simulator hosts. NOTE: An Xcode installation is required in order to run WebDriver tests on iOS Simulator hosts.',
default: false,
type: 'boolean',
group: 'Safari'
})
.option('browsertime.requestheader', {
alias: ['r', 'requestheader'],
describe:
'Request header that will be added to the request. Add multiple instances to add multiple request headers. Use the following format key:value. Only works in Chrome, Firefox and Edge.',
group: 'Browser'
})
.option('browsertime.cookie', {
alias: ['cookie'],
group: 'Browser',
describe:
'Cookie that will be added to the request. Add multiple instances to add multiple cookies. Use the following format cookieName=cookieValue. Only works in Chrome and Firefox.'
})
.option('browsertime.block', {
alias: 'block',
describe:
'Domain or URL or URL pattern to block. If you use Chrome you can also use --blockDomainsExcept (that is more performant). Works in Chrome/Edge. For Firefox you can only block domains.',
group: 'Browser'
})
.option('browsertime.basicAuth', {
describe:
'Use it if your server is behind Basic Auth. Format: username@password. Only works in Chrome and Firefox.',
group: 'Browser',
alias: 'basicAuth'
})
.option('browsertime.proxy.http', {
alias: 'proxy.http',
type: 'string',
describe: 'Http proxy (host:port)',
group: 'proxy'
})
.option('browsertime.proxy.https', {
alias: 'proxy.https',
type: 'string',
describe: 'Https proxy (host:port)',
group: 'proxy'
})
.option('browsertime.flushDNS', {
alias: 'flushDNS',
describe:
'Flush the DNS between runs (works on Mac OS and Linux). The user needs sudo rights to flush the DNS.',
group: 'Browser'
})
.option('browsertime.headless', {
alias: 'headless',
type: 'boolean',
default: false,
group: 'Browser',
describe:
'Run the browser in headless mode. This is the browser internal headless mode, meaning you cannot collect Visual Metrics or in Chrome run any WebExtension (this means you cannot add cookies, requestheaders or use basic auth for headless Chrome). Only works in Chrome and Firefox.'
})
.option('browsertime.iqr', {
describe:
'Use IQR, or Inter Quartile Range filtering filters data based on the spread of the data. See https://en.wikipedia.org/wiki/Interquartile_range. In some cases, IQR filtering may not filter out anything. This can happen if the acceptable range is wider than the bounds of your dataset. ',
type: 'boolean',
default: false
})
.option('browsertime.preWarmServer', {
alias: 'preWarmServer',
type: 'boolean',
default: false,
describe:
'Do pre test requests to the URL(s) that you want to test that is not measured. Do that to make sure your web server is ready to serve. The pre test requests is done with another browser instance that is closed after pre testing is done.'
})
.option('browsertime.preWarmServerWaitTime', {
type: 'number',
default: 5000,
describe:
'The wait time before you start the real testing after your pre-cache request.'
})
/*
Crawler options
*/
.option('crawler.depth', {
alias: 'd',
describe:
'How deep to crawl (1=only one page, 2=include links from first page, etc.)',
group: 'Crawler'
})
.option('crawler.maxPages', {
alias: 'm',
describe: 'The max number of pages to test. Default is no limit.',
group: 'Crawler'
})
.option('crawler.exclude', {
describe: String.raw`Exclude URLs matching the provided regular expression (ex: "/some/path/", "://some\.domain/"). Can be provided multiple times.`,
group: 'Crawler'
})
.option('crawler.include', {
describe: String.raw`Discard URLs not matching the provided regular expression (ex: "/some/path/", "://some\.domain/"). Can be provided multiple times.`,
group: 'Crawler'
})
.option('crawler.ignoreRobotsTxt', {
type: 'boolean',
default: false,
describe: 'Ignore robots.txt rules of the crawled domain.',
group: 'Crawler'
})
.option('scp.host', {
describe: 'The host.',
group: 'scp'
})
.option('scp.destinationPath', {
describe:
'The destination path on the remote server where the files will be copied.',
group: 'scp'
})
.option('scp.port', {
default: 22,
describe: 'The port for ssh when scp the result to another server.',
group: 'scp'
})
.option('scp.username', {
describe:
'The username. Use username/password or username/privateKey/pem.',
group: 'scp'
})
.option('scp.password', {
describe: 'The password if you do not use a pem file.',
group: 'scp'
})
.option('scp.privateKey', {
describe: 'Path to the pem file.',
group: 'scp'
})
.option('scp.passphrase', {
describe: 'The passphrase for the pem file.',
group: 'scp'
})
.option('scp.removeLocalResult', {
default: true,
describe:
'Remove the files locally when the files has been copied to the other server.',
group: 'scp'
})
.option('grafana.host', {
describe: 'The Grafana host used when sending annotations.',
group: 'Grafana'
})
.option('grafana.port', {
default: 80,
describe: 'The Grafana port used when sending annotations to Grafana.',
group: 'Grafana'
})
.option('grafana.auth', {
describe:
'The Grafana auth/bearer value used when sending annotations to Grafana. If you do not set Bearer/Auth, Bearer is automatically set. See http://docs.grafana.org/http_api/auth/#authentication-api',
group: 'Grafana'
})
.option('grafana.annotationTitle', {
describe: 'Add a title to the annotation sent for a run.',
group: 'Grafana'
})
.option('grafana.annotationMessage', {
describe:
'Add an extra message that will be attached to the annotation sent for a run. The message is attached after the default message and can contain HTML.',
group: 'Grafana'
})
.option('grafana.annotationTag', {
describe:
'Add a extra tag to the annotation sent for a run. Repeat the --grafana.annotationTag option for multiple tags. Make sure they do not collide with the other tags.',
group: 'Grafana'
})
.option('grafana.annotationScreenshot', {
default: false,
type: 'boolean',
describe:
'Include screenshot (from Browsertime) in the annotation. You need to specify a --resultBaseURL for this to work.',
group: 'Grafana'
})
.option('graphite.host', {
describe: 'The Graphite host used to store captured metrics.',
group: 'Graphite'
})
.option('graphite.port', {
default: 2003,
describe: 'The Graphite port used to store captured metrics.',
group: 'Graphite'
})
.option('graphite.auth', {
describe:
'The Graphite user and password used for authentication. Format: user:password',
group: 'Graphite'
})
.option('graphite.httpPort', {
describe:
'The Graphite port used to access the user interface and send annotations event',
default: 8080,
group: 'Graphite'
})
.option('graphite.webHost', {
describe:
'The graphite-web host. If not specified graphite.host will be used.',
group: 'Graphite'
})
.option('graphite.proxyPath', {
describe:
'Extra path to graphite-web when behind a proxy, used when sending annotations.',
default: '',
group: 'Graphite'
})
.option('graphite.namespace', {
default: 'sitespeed_io.default',
describe: 'The namespace key added to all captured metrics.',
group: 'Graphite'
})
.option('graphite.includeQueryParams', {
default: false,
describe:
'Whether to include query parameters from the URL in the Graphite keys or not',
type: 'boolean',
group: 'Graphite'
})
.option('graphite.arrayTags', {