【问题标题】:How to get only specific metrics from Google Lighthouse?如何仅从 Google Lighthouse 获取特定指标?
【发布时间】:2019-12-10 12:16:55
【问题描述】:

假设我只想从Google Lighthouse 获取first-meaningful-paint metric

我正在使用下面的 sn-p 代码,它会进行完整的审计(这需要很长时间,因为我只对一个指标感兴趣)。如何更改以下代码以告诉 Lighthouse 只为我获取一个指标?

(基于this的源码sn-p)

const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
const urlLib = require('url').URL;

async function run() {
    const browser = await puppeteer.launch({
        headless: false,
        defaultViewport: null
    });

    const { lhr } = await lighthouse("https://www.google.com", {
        port: (new urlLib(browser.wsEndpoint())).port,
        logLevel: 'info',
        output: 'json'
    });

    console.log(lhr);
}

run();

【问题讨论】:

    标签: puppeteer lighthouse


    【解决方案1】:

    在配置的settings 对象中,您可以指定要运行的审核。调用lighthouse 时,配置作为第三个参数提供(更多信息在docs)。

    代码示例

    lighthouse('...', { /* ... */ }, {
      extends: 'lighthouse:default',
      settings: {
        onlyAudits: ['first-meaningful-paint'],
      }
    });
    

    这只会运行first-meaningful-paint 审计。

    【讨论】:

    • 如何在报告中显示审计 -> 网络请求数据?您能帮我进行自定义审核配置设置吗?
    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2020-08-02
    • 1970-01-01
    • 2018-03-11
    • 2022-06-22
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多