Run chrome lighthouse's audit from command line

↘锁芯ラ 提交于 2019-12-12 08:00:01

问题


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 ?


回答1:


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.




回答2:


You can use/test via npx:

npm i npx -g

Then, directly run from your terminal without using a package.json created or installing globally & without opening a chrome browser instance:

npx lighthouse <URL> --only-categories="performance,seo,Accessibility" --chrome-flags="--headless"


来源:https://stackoverflow.com/questions/47515808/run-chrome-lighthouses-audit-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!