Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run chrome lighthouse's audit from command line

I would like to write a script which run (from the chrome's binary) its lighthouse's audit with a url given. I didn't manage to find how to do it, but since there is even a chrome extension doing I assume it should be feasible right ?

like image 837
Scipion Avatar asked Nov 27 '17 16:11

Scipion


People also ask

How do I run a Lighthouse programmatically?

One of the simplest ways to run Lighthouse is through Chrome's DevTools Lighthouse panel. If you open your site in Chrome and then open Chrome's DevTools, you should see a “Lighthouse” tab. From there, if you click “Generate Report”, you should get a full report of your site's quality metrics.


1 Answers

Google Lighthouse can be ran using the command line. To run it from the command line, you must first install:

  • Google Chrome for Desktop
  • Node.js v6 or later.

To install the Lighthouse CLI, open a command line and type the following command:

npm install -g lighthouse

To run an audit with Lighthouse, type:

lighthouse https://example.com

By default, Lighthouse writes the report to an HTML file. You can control the output format by passing flags.

You will notice that a Chrome window is opened every time you run Lighthouse. If you don't want a window to be opened, you can run it in headless mode:

lighthouse https://example.com/ --chrome-flags="--headless"

For the complete list of options, type:

lighthouse --help

Take a look at the Lighthouse source code repository for additional documentation and examples.

like image 187
ncardeli Avatar answered Sep 22 '22 10:09

ncardeli