【问题标题】:How to set a custom configuration in Lighthouse programmaticaly?如何以编程方式在 Lighthouse 中设置自定义配置?
【发布时间】:2019-01-15 22:29:14
【问题描述】:

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

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

谁有任何示例可以分享,关于如何以编程方式为灯塔设置自定义配置文件(带有自定义收集器和审计)?

【问题讨论】:

    标签: javascript google-chrome lighthouse


    【解决方案1】:

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

    // 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
          }]
        }
      }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 2011-09-07
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 2011-11-11
      相关资源
      最近更新 更多