不确定我是否做错了什么或缺少配置设置,但当我在Chrome扩展中运行LH时,我的页面会收到94,但当我在节点LH中运行相同的页面时,我会得到88。我想出了在台式机和移动端运行它的方法,但我不确定我还遗漏了什么,才能得到相同或更相似的分数。
我当前的代码
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info', output: 'html', onlyCategories: ['accessibility'], port: chrome.port};
// emulatedFormFactor:'desktop'
const config = { extends: 'lighthouse:default', settings: {formFactor: 'desktop', screenEmulation:{mobile:false}} }
const runnerResult = await lighthouse(, options, config);我预计两者之间会有细微的差异,但我认为6分有点戏剧性。我注意到两者的节流率不同,但不确定如何更改设置或配置。

右边是Chrome浏览器,左边是节点保存的页面
发布于 2021-05-25 21:45:52
在做了大量的谷歌搜索后,我终于找到了答案,让我的节点灯塔使用与Chrome扩展版本相同的参数。
下面是最终的代码:
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const flags = {logLevel: 'info', output: 'html', onlyCategories: ['accessibility'], port: chrome.port};
const config = {
extends: 'lighthouse:default',
settings: {
formFactor: 'desktop',
throttling: {
rttMs: 40,
throughputKbps: 10240,
cpuSlowdownMultiplier: 1,
requestLatencyMs: 0,
downloadThroughputKbps: 0,
uploadThroughputKbps: 0
},
screenEmulation: {
mobile: false,
width: 1350,
height: 940,
deviceScaleFactor: 1,
disabled: false
},
emulatedUserAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Safari/537.36 Chrome-Lighthouse'
}
}
const runnerResult = await lighthouse('https://yourawesomesite.com', flags, config);希望这能帮助其他人自动化他们的灯塔测试。
https://stackoverflow.com/questions/67678943
复制相似问题