npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lighthouse-js-batch

v1.0.0

Published

A Node JS package that runs multiple Lighthouse audit reports programmatically

Downloads

3

Readme

lighthouse-js-batch

A Node JS package that allows you to run multiple Lighthouse audit reports programmatically for multiple URLs. With this package, you can specify global or individual configurations per URL. You also can manipulate the resulting Lighthouse JS object and decide whether to output all reports or just use the JS object for other purposes.

When to use this package

This package is ideal for you if you want to run one or multiple Lighthouse audit reports programmatically as a Node module. The package comes with the necessary setup as indicated in the docs of using Lighthouse programmatically for running Chrome using chrome-launcher and using Lighthouse as a Node module, which gives you the ability to pass the Lighthouse flags, configs, and Chrome flags.

Here are some good use cases for this package:

  • Auditing multiple sites or URLs, to gather more than one report. (runs synchronously and in order)
  • Handle the Lighthouse results using Javascript.
  • Avoid outputting the results into report files and handle the results by yourself using Javascript. (Just don't pass any output data in the output flags field)
  • Ability to output corresponding file reports (CSV, JSON, and HTML) like the CLI.
  • Dynamic file name output reports, such as fileName: your_dynamic_filename_report_${new Date().toISOString()}`` (extensions are determined by the output format field)
  • Running audits with general configs, avoiding the need to create individual configs each time
  • Running individual configs on each URL/site passed

Installation

To install lighthouse-js-batch, you can use npm or yarn:

npm install lighthouse-js-batch
yarn add lighthouse-js-batch

Usage

const { runAudits } = require('lighthouse-js-batch');

runAudits({ urls, options }).then(results => {
  // do something with the results
});

CommonJS (CJS)

const ljsb = require('lighthouse-js-batch');

ljsb.runAudits({ urls, lhrDefaultFlags, lhrDefaultConfigs,chromeDefaultFlags, outputPath  }).then((results) => {
  // do something with the results
});

ECMAScript Modules (ESM)

import { runAudits } from 'lighthouse-js-batch';

runAudits({ urls, lhrDefaultFlags, lhrDefaultConfigs,chromeDefaultFlags, outputPath  }).then((results) => {
  // do something with the results
});

Parameters and Types of runAudits

  • parameters: an object of type RunAuditsParams

Return Value

An array of type LBResult[]

RunAuditsParams

An object with the following properties:

  • urls: an array of type UrlSetup[]
  • lhrDefaultFlags: a Partial<LH.CliFlags> object, default flags for the lighthouse reports
  • lhrDefaultConfigs: a Partial<LH.Config.Json> object, default configurations for the lighthouse reports
  • chromeDefaultFlags: an array of strings, default flags for chrome
  • outputPath: a string, output path

UrlSetup

An object with the following properties:

  • url: a string, URL to run the audit on
  • fileName: a string, name of the file
  • configs: an optional Partial<LH.Config.Json> object, configurations for the lighthouse report for this URL
  • flags: an optional Partial<LH.CliFlags> object, flags for the lighthouse report for this URL

LBResult

An object with the following properties:

  • fileName: an optional string, name of the file
  • reports: an optional string or array of strings, string reports in the corresponding format (JSON, CSV, html)
  • lhr: a required LH.Result object, JS object of the result of the lighthouse report
  • outputFormats: an optional string or array of strings, the output format of the report.

Contributing

If you want to contribute to the development of lighthouse-js-batch, please feel free to submit a pull request or open an issue. We welcome contributions of all kinds!

Note

Important links from the lighthouse repo