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-cron

v1.0.4

Published

Tool to run light house cron jobs on multiple urls and ship results

Downloads

8

Readme

Lighthouse Cron

Cron multiple batch Lighthouse audits and emit results for sending to remote server.

Want to track your Lighthouse scores and metrics overtime? This module will allow you to write a simple script to perform multiple audits over time and allow you to transport the results.

Set up

npm install --save lighthouse-cron

Usage

const LighthouseCron = require('lighthouse-cron');
const lighthouseCron = new LighthouseCron(
  [
    {
      url: 'https://www.google.com/'
    }
  ],
  '00 00,15,30,45 * * * 0-6'
);

lighthouseCron.on('auditComplete', audit => {
  console.log(audit);
});

lighthouseCron.init();

Reference

new LighthouseCron(urls, cron, timezone, chromeFlags, lighthouseFlags, lighthouseConfig)

Create a new instance of lighthouse cron.

Parameters
  • urls - Required. Array of objects including the url as a property.
  • cron - String for cron pattern (Default: '00 00 * * * 0-6')
  • timezone - String for cron timezone (Default: 'Europe/London')
  • chromeFlags - Array of Chrome flags e.g. ['--headless']
  • lighthouseFlags - Object to enable Lighthouse flags
  • lighthouseConfig - Object describe custom configurations for lighthouse runs

init(autorun)

Initialise lighthouse cron.

Parameters
  • autorun - Boolean for if cron should do first run instantly (Default: false)

Events

auditComplete

After a lighthouse audit is complete on a url this event returns the results.

cronCycleComplete

After the cron job has been complete an event is emitted.

allAuditsComplete

After all lighthouse audits are complete an event is emitted.

error

If a an error occurs an event is emitted with the error returned.

Examples

Below is an example of how you could report performance metrics and lighthouse scores to the data analytics platform Keen.io.

const KeenTracking = require('keen-tracking');
const LighthouseCron = require('lighthouse-cron');

// Configuring Keen client
const keenClient = new KeenTracking({
  projectId: 'Your Project Id',
  writeKey: 'Your Write Key'
});

// Additional website and description fields added to improve your dashboards
const lighthouseCron = new LighthouseCron(
  [
    {
      website: 'Google',
      description: 'Homepage',
      url: 'https://www.google.com'
    },
    {
      website: 'YouTube',
      description: 'Homepage',
      url: 'https://www.youtube.com'
    }
  ],
  '00 00 * * * 0-6'
);

// listening for each audit to be complete
lighthouseCron.on('auditComplete', audit => {
  const report = generateTrackableReport(audit);
  keenClient.recordEvent('lighthouse audits', report);
});


// Pulling out the metrics we are interested in
function generateTrackableReport(audit) {
  const reports = [
    'first-meaningful-paint',
    'speed-index-metric',
    'estimated-input-latency',
    'time-to-interactive',
    'total-byte-weight',
    'dom-size'
  ];

  const obj = {
    metadata: audit.metadata,
    score: Math.round(audit.score),
    results: {}
  };

  reports.forEach(report => {
    obj.results[report] = getRequiredAuditMetrics(audit.results.audits[report]);
  });
  return obj;
}

// getting the values we interested in
function getRequiredAuditMetrics(metrics) {
  return {
    score: metrics.score,
    value: metrics.rawValue,
    optimal: metrics.optimalValue
  };
}

lighthouseCron.init();

This demo is also available to be run from this module however instead of reporting the metrics to Keen.io they are just printed to console.

npm run demo