用 Lighthouse Node API 时怎么指定设备类型?

程序员江洁 阅读 42

我在用 Lighthouse 的 Node API 做性能测试,但默认好像是桌面端的配置。我想模拟移动端访问,查了文档说可以用 emulatedFormFactor,但加进去没效果,还是按桌面跑的。

我试过这样写:

const options = {
  extends: 'lighthouse:default',
  settings: {
    emulatedFormFactor: 'mobile'
  }
};

结果报错说 Unknown setting: emulatedFormFactor,这参数到底该怎么用?是不是还要配别的?

我来解答 赞 1 收藏
二维码
手机扫码查看
2 条解答
端木素伟
我之前也碰到过这个问题。emulatedFormFactor 确实是用来设置设备类型的,但是它应该放在 config 对象里,而不是 settings 里面。你可以试试这样写:

const options = {
extends: 'lighthouse:default',
config: {
settings: {
emulatedFormFactor: 'mobile'
}
}
};


注意看,我把 emulatedFormFactor 放在了 config.settings 里面。这样应该就能正确地指定设备类型为移动端了。希望这能解决问题!
点赞
2026-03-22 20:31
上官伊芃
嗯,这个问题我遇到过。emulatedFormFactor 确实是用来设置设备类型的,但是得放在正确的配置里。你试试这样写:

const options = {
extends: 'lighthouse:default',
formFactor: 'mobile',
settings: {
// 其他设置...
}
};


注意 formFactor 直接放在根级别,而不是 settings 里。这样应该就可以了。
点赞
2026-03-20 21:19