web性能检测工具lighthouse

About Automated auditing, performance metrics, and best practices for the web.

Lighthouse 可以自动检查Web页面的性能。

你可以以多种方式使用它。

浏览器插件

作为浏览器插件,访问chrome网上商店 搜索Lighthouse 插件安装。以两种方式使用。

  • 方式一

安装成功后,访问想要检查的页面,开发插件,点击Generate report,稍等片刻,你将会得到一份页面的检查报告。

  • 方式二

访问想要检查的页面,打开开发者工具,切换到Lighthouse 标签使用。

Node CLI

以Node CLI方式使用Lighthouse可以得到最大灵活性,Lighthouse提供了许多参数使用。

Linghthouse 需要Node 14 LTS(14.x) 或更高版本。

  • 安装
> npm install -g lighthouse

AI生成项目

  • 查看帮助
> lighthouse --help

AI生成项目

  • 使用
 
  1. > lighthouse https://www.baidu.com --output html --output-path ./report.html

  2. √ We're constantly trying to improve Lighthouse and its reliability.

  3. ...

--output 指定报告的类型;--output-path 指定报告的路径。

以编程模式使用

创建lighthouse_demo.js 文件,脚本如下:

 
  1. const fs = require('fs');

  2. const lighthouse = require('lighthouse');

  3. const chromeLauncher = require('chrome-launcher');

  4. (async () => {

  5. const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});

  6. const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};

  7. const runnerResult = await lighthouse('https://www.baidu.com/', options);

  8. // `.report` is the HTML report as a string

  9. const reportHtml = runnerResult.report;

  10. fs.writeFileSync('lhreport.html', reportHtml);

  11. // `.lhr` is the Lighthouse Result as a JS object

  12. console.log('Report is done for', runnerResult.lhr.finalUrl);

  13. console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);

  14. await chrome.kill();

  15. })();

有没有自动化既视感,还可以设置 headless模式。

  • 运行
> node lighthouse_demo.js

AI生成项目

最终,会在当前目录下生成 lhreport.html 结果文件。

Web网站

有一些Web网站基于lighthouse 提供服务,你可以登录这些网站输入URL检测网络性能。

...

以 web page test 为例:

感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值