如何以编程方式在 Lighthouse 中设置自定义配置?

How to set a custom configuration in Lighthouse programmaticaly?

我正在尝试执行与此灯塔命令等效的操作,但我不知道如何操作。

lighthouse --config-path=custom-config.js https://www.example.com

关于如何以编程方式为 Lighthouse 设置自定义配置文件(使用自定义收集器和审计),是否有人可以分享任何示例?

我自己找到了答案,所以我把它贴在下面:

// This how I call lighthouse programmatically
const lhr = await lighthouse(url, config.lighthouseFlags, config.lighthouseConfigs);

var url = "https://www.example.com";
var config = {};
// The 2nd parameter in the lighthouse function is some of the flags you can pass to lighthouse. I'm posting a few examples below:
conig.lighthouseFlags = {
  "output": [
    "html"
  ],
  "emulatedFormFactor": "none",
  "disableStorageReset": "true",
  "disableDeviceEmulation": "true"
};
// The 3rd parameter includes the configuration on how to run the tests in lighthouse
conig.lighthouseConfigs = {
  "extends": "lighthouse:default",
  "passes": [{
    "passName": "defaultPass",
    "gatherers": [
      "gatherer_more_seo"
    ]
  }],
  "audits": [
    "audit_seo_something"
  ],
  "categories": {
    "more_seo": {
      "title": "Friendly title",
      "description": "Friendly description",
      "auditRefs": [{
        "id": "more-seo-field",
        "weight": 1
      }]
    }
  }
};