Overview
Lighthouse CLI has been used to create many very useful tools for reviewing data from Google's Lighthouse audits.
This is instructions on how to install and use one of these variations, "lighthouse-batch". Lighthouse-batch will allow us to easily run lighthouse audits on multiple pages and accepts a lists of targets from a TEXT files.
Let us first go over how to install the required Node modules and then we can go over some of the commands and some links to documentation that may be helpful.
Installing lighthouse-batch
The required modules may be installed with npm by running the wollowing command:
npm install lighthouse-batch -g
Once everything is installed on your work station you can run an audit on either a comma separated list of urls in your command-line, or by referencing a txt file that contains a comma-separated list of urls.
Here are some example commands:
- manually list pages to audit in your command with the -s flag, this option takes a comma-separated list or urls to run reports on.
Example:
lighthouse-batch -s https://firm-media.com,https://firm-media.com/services/search-engine-optimization-seo/
- utilize a text file with the -f flag. This option allows the use of a .txt file that contains a list of urls, one-per-line as a value. This is useful for repeat audits.
Example:
- "-f" set sites from txt file at this location
- while "-f" is used "-s" is not needed. We will use one or the other.
lighthouse-batch -f sites.txt
There are many useful options that can be added onto these commands.
A full list may be found in the readme of the github repository here: https://github.com/mikestead/lighthouse-batch
Additional notes:
Within the available options in the lighthouse-batch module, there is one that allows you you utilize any option available in the lighthouse cli. This option can be used by adding the -p flag to your command and then following it with an option available to the lighthouse cli. This is because the lighthouse CLI is the primary dependency and the core of the lighthouse-batch module.
Here is a link to the repository where a full list if option may be found: lighthouse-cli options
Example 1:
This will run a lighthouse audit on a website in a mobile viewport, then save it in html format to a specified directory on your workstation.
- "-s" sets the site or sites (comma-separated)
- "-p" allows us to set lighthouse cli parameter for --form-factor=mobile
- "-h" will output the report in html format
- "-o" sets the path to where you wish to save it:
lighthouse-batch -s https://firm-media.com -h -o ./report/firm-media/mobile -p --form-factor=mobile
If you wish to use more than one paramater/option from the lighthouse cli module please add each setting prefixed with a -p flag.
Example 2:
More than one -p to set mutiple options/parameters from the lighthouse cli,
this adds 4 additional parameters to specify the screen emulation parameters to match an iphone 12 Pro
lighthouse-batch -s https://firm-media.com -h -o ./report/firm-media/mobile -p --form-factor=mobile -p --screenEmulation.mobile -p --screenEmulation.width=390 -p --screenEmulation.height=844
-p --screenEmulation.deviceScaleFactor=3
Example 3:
Specifically run report on desktop viewport for the front-page and the seo page of firm-media.com, output the reports in both html and json formats along with a summort of the pages in json format to a specified directory.
lighthouse-batch -s https://firm-media.com,https://firm-media.com/custom-website-design/ -h -o ./report/firm-media/desktop -p --preset=desktop
Final Notes:
There are a ton of options that can be set. I beleive this will be very useful to anyone that needs to evaluate multiple URLS in lighthouse quickly. The ability to narrow down the output will also allow for more focused statitics.
A few gotchas to consider while using this tool:
- While re-running your reports, the contents of the taget directory will be deleted and replace with each run.
- I found that to have consistent desktop vs mobile data accross the reports in all formats as well as the summary.json created it is needed to use one of the following:
- "--preset=desktop" (for desktop reporting)
- "--form-facctor=mobile" (for mobile reporting)
Have fun and dig into the documentation. I really hope that these tools help you create more performant webpages.