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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lighterhouse

v4.2.6

Published

Playwright Lighthouse Audit

Readme

Disclaimer

This package is designed specifically for my own use cases and is actively in development, do not use in production. Big shout out to playwright-lighthouse and playwright-lighthouse-flow for their amazing work.

Lightherhouse Playwright - NPM Package

NPM release

Lighthouse is a tool developed by Google that analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.

Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

The purpose of this package is to produce web audit report for several pages in connected mode and in an automated (programmatic) way.

Usage

Installation

Add the lighterhouse, playwright & lighthouse & puppeteer libraries to your project:

$ npm install --save-dev lighterhouse playwright lighthouse pupperteer

Lighterhouse exposes a couple of functions to be used in your tests:

  • playAudit: to run Lighthouse audits on a page
  • report: to generate a report from the Lighthouse audit results
export const report = async (results: RunnerResult, type: OutputMode | OutputMode[], dir?: string, name?: string): Promise<void> => {
  const directory = dir || `${process.cwd()}/lighthouse`;
  const fileName = name || `lighthouse-${new Date().getTime()}`
  const reportBody = ReportGenerator.generateReport(results.lhr, type);
  await fs.mkdir(directory, { recursive: true });
  await fs.writeFile(`${dir}/${fileName}.${type}`, reportBody);
};
  • startFlow: to start a Lighthouse UserFlow
  • flowReport: to generate a html report from the Lighthouse UserFlow, with default dir and name values
export const flowReport = async (flow: UserFlow, dir?: string, name?: string): Promise<void> => {
  const directory = dir || `${process.cwd()}/lighthouse`;
  const fileName = name || `lighthouse-${new Date().getTime()}`
  const reportBody = await flow.generateReport();
  await fs.mkdir(directory, { recursive: true });
  await fs.writeFile(`${dir}/${fileName}.html`, reportBody);
};

In your code

How I'd use playAudit, with port and browser fixtures:

import getPort from 'get-port';
import { expect } from '@playwright/test'
import { config } from '@config'
import { playAudit } from 'lighterhouse'
import { chromium } from 'playwright';
import type { Browser } from 'playwright';

const lighthouseTest = baseTest.extend<{}, { port: number } >({
  port: [
    async ({}, use) => {
      // Assign a unique port for each playwright worker to support parallel tests
      const port = await getPort();
      await use(port);
    },
    { scope: 'worker' },
  ],
});

const lhsTest = lighthouseTest.extend<{}, { browser: Browser }>({
  browser: [
    async ({ port }, use) => {
      const browser = await chromium.launch({
        args: [`--remote-debugging-port=${port}`],
      });
      await use(browser);
    },
    { scope: 'worker' },
  ],
})

const thresholds = {
  performance: 80,
  accessibility: 80,
  'best-practices': 80,
  pwa: 80,
}

lhsTest.describe('Page Audit', () => {

  lhsTest.beforeEach(async ({ browser, login }) => { 
    browser 
    login 
  })

  lhsTest('Home', async ({ port, home }) => {
    const name = `home-page-audit`

    const result = await playAudit({
      page: home.page,
      port,
      thresholds,
      reports: {
        name,
        directory: config.audit
      },
    })

    expect(result.comparison.results).toEqual([])
  })
})

Use startFlow will have same setup as playAudit, with port and browser fixtures:

...
    const flow = await startFlow({
      cdpPort: port,
    })

    await flow.startTimespan({ name: 'Editing Template' })

    await test.step('Start flow on the page', async () => {
      await page.click()
    })

    await flow.endTimespan()
    await flowReport(flow, config.audit, name)
...