以自动化方式获得灯塔的总体评分

时间:2019-10-30 07:32:12

标签: pagespeed google-pagespeed lighthouse pagespeed-insights

我正在尝试自动获取许多不同页面的分数。但是api似乎不像网络版本那样提供整体评分。

我尝试使用Lighthouse API v5和v4,但似乎都没有得分,我可能错过了。我通过在pagespeed见解网站上使用puppeteer使它正常工作,但此后该软件停止了工作,并希望在再次尝试对其进行修复之前检查我是否没有遗漏任何东西

2 个答案:

答案 0 :(得分:0)

您的设置必须存在一些问题。尝试通过铬运行它,对我来说以下工作正常:

安装铬和灯塔:

sudo install --y chromium-browser
sudo npm install -g lighthouse
lighthouse --output-path=./Production-lighthouse-report.html URL

通过无头镶边在所需网址上运行Lighthouse测试的脚本:

lighthouse --chrome-flags="--headless" --output-path=./Production-lighthouse-report.html URL

答案 1 :(得分:0)

返回的JSON在lighthouseResult下有一个称为categories的部分。

categories内,您会看到performance,然后score是一个孩子,那里的分数超过1(所以89的分数为0.89)。

"lighthouseResult": {
......
    "categories": {
        "performance": {
            "id": "performance",
            "title": "Performance",
            "score": 1.00, <- here is the score.
            "auditRefs":
......
相关问题