How to use lighthouse - 10 common examples

To help you get started, we’ve selected a few lighthouse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shakyShane / actor-js / fixtures / launcher.js View on Github external
init() {

        this.launcher = new ChromeLauncher({
            port: 9222,
            autoSelectChrome: true, // False to manually select which Chrome install.
            additionalFlags: ['--headless']
        });

        return fromPromise(this.launcher.run())
            .catch(err => {
                // console.log(err);
                return this.stop();
            });
    }
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / first-ad-render.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {
      devtoolsLog,
      trace,
      settings: context.settings,
    };
    const {timing} = await ComputedAdRenderTime.request(metricData, context);

    if (!(timing > 0)) { // Handle NaN, etc.
      context.LighthouseRunWarnings.push(runWarning.NoAdRendered);
      return auditNotApplicable.NoAdRendered;
    }

    const scoreOptions =
      context.options[global.isLightrider ? 'default' : 'lightrider'];

    return {
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / serial-header-bidding.js View on Github external
static async audit(artifacts, context) {
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const unfilteredNetworkRecords =
      await NetworkRecords.request(devtoolsLog, context);
    if (!unfilteredNetworkRecords.length) {
      return auditNotApplicable.NoRecords;
    }

    const mainResource =
        await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);

    // Filter out requests without responses, image responses, and responses
    // taking less than 50ms.
    const networkRecords = unfilteredNetworkRecords
        .filter(isPossibleBid)
        .filter((r) => r.frameId == mainResource.frameId);

    // We filter for URLs that are related to header bidding.
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / bid-request-from-page-start.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {trace, devtoolsLog, settings: context.settings};

    const {timing} = await ComputedBidRequestTime.request(metricData, context);
    if (!(timing > 0)) { // Handle NaN, etc.
      return auditNotApplicable.NoBids;
    }

    return {
      numericValue: timing * 1e-3,
      score: Audit.computeLogNormalScore(
        timing,
        context.options.scorePODR,
        context.options.scoreMedian
      ),
      displayValue: str_(UIStrings.displayValue, {timeInMs: timing}),
github thegreenwebfoundation / lighthouse-plugin-greenhouse / src / audits / greenhouse-audit.js View on Github external
static async audit(artifacts, context) {
    // Artifacts requested in `requiredArtifacts` above are passed to your audit.
    // See the "API -> Plugin Audits" section below for what artifacts are available.

    try {
      const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
      const requests = await NetworkRecords.request(devtoolsLog, context);

      let domains = new Set()
      requests.forEach(req => {
        domains.add(new URL(req.url).host)
      })

      // the spread syntax turns our deduped set into an array, then makes sure they're long enough to check
      const domainArray = [...domains].filter(domain => domain.length > 2)

      const checkResults = await Greencheck.checkDomains(domainArray)

      const greyDomainResults = checkResults.greenChecks.filter(res => res.green == false)
      const tableDetails = GreenAudit.convertToTableDetails(checkResults.greenChecks)
      return {
        score: checkResults.score,
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / ad-render-blocking-resources.js View on Github external
static async audit(artifacts, context) {
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const networkRecords = await NetworkRecords.request(devtoolsLog, context);
    const tag = networkRecords.find((req) => isAdTag(new URL(req.url)));
    if (!tag) {
      return auditNotApplicable.NoTag;
    }

    /** @type {Map} */
    const timingsByRecord =
      await getTimingsByRecord(trace, devtoolsLog, context);

    // NOTE(warrengm): Ideally we would key be requestId here but LinkElements
    // don't have request IDs.
    /** @type {Set} */
    const blockingElementUrls = new Set();
    for (const link of artifacts.LinkElements) {
      // TODO(warrengm): Check for media queries? Or is the network filter below
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / bid-request-from-page-start.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const metricData = {trace, devtoolsLog, settings: context.settings};

    const {timing} = await ComputedBidRequestTime.request(metricData, context);
    if (!(timing > 0)) { // Handle NaN, etc.
      return auditNotApplicable.NoBids;
    }

    return {
      numericValue: timing * 1e-3,
      score: Audit.computeLogNormalScore(
        timing,
        context.options.scorePODR,
        context.options.scoreMedian
      ),
      displayValue: str_(UIStrings.displayValue, {timeInMs: timing}),
    };
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / idle-network-times.js View on Github external
static async audit(artifacts, context) {
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const networkRecords = await NetworkRecords.request(devtoolsLog, context);
    /** @type {LH.Artifacts.TaskNode[]} */ let mainThreadTasks = [];
    try {
      mainThreadTasks = await MainThreadTasks.request(trace, context);
    } catch (e) {
      // Ignore tracing errors.
    }
    const {timings} = await TraceOfTab.request(trace, context);

    const timerEvents =
        trace.traceEvents.filter((t) => t.name.startsWith('Timer'));

    const pageStartTime = getPageStartTime(networkRecords);
    const blockingRequests =
      await computeAdRequestWaterfall(trace, devtoolsLog, context);
    if (!blockingRequests.length) {
      return auditNotApplicable.NoAdRelatedReq;
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / serial-header-bidding.js View on Github external
static async audit(artifacts, context) {
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const unfilteredNetworkRecords =
      await NetworkRecords.request(devtoolsLog, context);
    if (!unfilteredNetworkRecords.length) {
      return auditNotApplicable.NoRecords;
    }

    const mainResource =
        await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);

    // Filter out requests without responses, image responses, and responses
    // taking less than 50ms.
    const networkRecords = unfilteredNetworkRecords
        .filter(isPossibleBid)
        .filter((r) => r.frameId == mainResource.frameId);

    // We filter for URLs that are related to header bidding.
    // Then we create shallow copies of each record. This is because the records
    // by default have circular structure, which causes an error to be thrown
github googleads / publisher-ads-lighthouse-plugin / lighthouse-plugin-publisher-ads / audits / ad-render-blocking-resources.js View on Github external
static async audit(artifacts, context) {
    const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
    const trace = artifacts.traces[Audit.DEFAULT_PASS];
    const networkRecords = await NetworkRecords.request(devtoolsLog, context);
    const tag = networkRecords.find((req) => isAdTag(new URL(req.url)));
    if (!tag) {
      return auditNotApplicable.NoTag;
    }

    /** @type {Map} */
    const timingsByRecord =
      await getTimingsByRecord(trace, devtoolsLog, context);

    // NOTE(warrengm): Ideally we would key be requestId here but LinkElements
    // don't have request IDs.
    /** @type {Set} */
    const blockingElementUrls = new Set();
    for (const link of artifacts.LinkElements) {
      // TODO(warrengm): Check for media queries? Or is the network filter below
      // sufficient?