Multiple Runs on a Single URL
See original GitHub issueI have been trying to write a script that allows me to pass in a list of URLs run each URL multiple times, collect the data grab the find the median for each URL then write out to a separate HTML/JSON file the processed data from the batch runs. With the script in its early stages I still can’t seem to get a successful run. It is giving me a
SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at Object.<anonymous> (.\Lighthouse\runLighthouseMulti.js:20:25)
This is my current code
`#!/usr/bin/env node
const spawnSync = require(‘child_process’).spawnSync; const lighthouseCli = require.resolve(‘./lighthouse/lighthouse-cli’); let urls = require(‘./Lighthouse/urls.json’); // The file where your list of urls lives let runs = 0
for (const url of urls) {
// console.log(url.url);
console.log(Running performance test ${runs + 1}
); // Logs this to the console just before it kicks off
try {
const { status = -1, stdout } = spawnSync(‘node’, [lighthouseCli,
‘https://www.example.com’,
‘–config-path=“./Lighthouse/custom-config.js”’,
--chrome-flags="--headless --user-agent='Custom'"
,
‘–emulated-form-factor none’,
‘–output=json’
]); // Executes this on the command line to run the performance test
console.log(stdout.toString());
console.log(JSON.parse(stdout));
}
catch(err) {
console.log(err)
console.log(Performance test ${runs + 1} failed
); // If Lighthouse happens to fail it’ll log this to the console and log the error message
break;
}
console.log(Finished running performance test ${url.fileName} ${runs + 1}
); // Logs this to the console just after it finishes running each performance test
runs++;
}
console.log(All finished
);`
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top GitHub Comments
https://github.com/GoogleChrome/lighthouse/blob/master/docs/variability.md#run-lighthouse-multiple-times / https://github.com/GoogleChrome/lighthouse#related-projects
We’re going to go ahead and close this out as there’s no action for Lighthouse to take here. Further direct questions might be better served by the community at Stack Overflow 😃