简体   繁体   中英

How to set a custom configuration in Lighthouse programmaticaly?

I'm trying to do the equivalent of this lighthouse command but I can't find out how.

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

Does anyone have any examples to share, on how to set a custom configuration file (with custom gatherers and audits) for lighthouse programmatically?

I managed to find out the answer myself so I am posting it below:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM