“我认为是如下:json.lighthouseResult.categories.performance.score
返回一个最大为 1 的小数。所以你必须乘以 100 才能得到百分比。对我有用..但是我似乎每次都没有得到相同的价值。它会波动......”正如 Jeroen 所说。100% 正确
“这不可能是正确的。我已经检查了几页,json.lighthouseResult.categories.performance.score 比developers.google.com/speed/pagespeed/insights 的分数高得多 - 帕斯卡·巴约拉特"
这是不正确的,因为您看到的是桌面结果而不是移动结果。
90% 情况下的桌面 99 或 100。
试试这个:
URL: https://www.google.com/
Return-Fields: lighthouseResult/categories/*/score
* is a wildcard
Indentations (PrettyPrint): no
Strategy: Mobile
Categories:
Performance
Progressive Web App (PWA)
Best practices
Accessibility
SEO
使用这些参数,API URL 为:
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2Fstackoverflow.com%2F&fields=lighthouseResult%2Fcategories%2F*%2Fscore&prettyPrint=false&strategy=mobile&category=performance&category=pwa&category=best-practices&category=accessibility&category=seo
JSON-Response 看起来像这样:
{
"lighthouseResult": {
"categories": {
"performance": {
"score":0.87
},
"accessibility": {
"score":0.7
},
"best-practices": {
"score":0.77
},
"seo": {
"score":0.9
},
"pwa": {
"score":0.56
}
}
}
}