Skip to main content
A Lighthouse plugin is a Node module that implements a set of checks run by Lighthouse and displayed as a new category in the report. Plugins have a stable, semver-versioned API and are easily distributed on npm.

Plugin vs. custom config

Before writing a plugin, decide whether you need the full flexibility of a custom config.
If you need to collect new data from the page (custom gatherers) or modify core Lighthouse categories, use a custom config instead.

Creating a plugin

1

Create package.json

A Lighthouse plugin is a Node module whose name starts with lighthouse-plugin-. Use peerDependencies to declare the Lighthouse version requirement — do not add Lighthouse as a direct dependency.
package.json
2

Create plugin.js

This is the configuration entry point for your plugin. It declares which audit files to load and defines the new category that will appear in the report.
plugin.js
3

Write your audit files

Each audit is a class with a static meta getter and a static audit() method. Place audit files in a subdirectory (e.g. audits/) and reference them by path in plugin.js.
audits/has-cat-images.js
4

Test locally

During development, set NODE_PATH to the parent of your plugin directory so that Lighthouse can resolve it as a module.
5

Publish to npm

Once your plugin is ready, publish it like any other npm package. Because the plugin name starts with lighthouse-plugin-, users can discover and install it directly.
Users install your plugin and then pass --plugins=lighthouse-plugin-example to their Lighthouse CLI invocations or programmatic API calls.

Plugin config API

The plugin.js export is an object with the following top-level properties.

audits

Declares the new audits the plugin adds. Type: Array<{path: string}> Each path should be an absolute module-style path that a consumer could pass to require — use the form lighthouse-plugin-<name>/path/to/audit.js.

category

Defines the display strings and scoring for the plugin’s report section.

groups

Optional. Groups allow you to visually cluster audits within a category in the HTML report.
Reference a group from auditRefs by setting the group property to the group key:

Plugin audit API

meta

A static getter returning the audit’s metadata.

audit(artifacts, context)

The function that computes results. Returns an object with at least a score property.
Scores above 0.9 are collapsed into the “Passed audits” section by default. Use this to signal a near-perfect result without fully passing.

Available artifacts

Lighthouse has additional internal artifacts not on this list. Those are considered experimental and may change without notice. Only use listed artifacts if you need a stable plugin.

Using network requests

Network request data is derived from DevtoolsLog at audit time using the NetworkRecords computed artifact. Pass context to allow Lighthouse to cache the result across audits.
audits/header-police.js

Naming best practices

Category titles

Keep category titles under 20 characters — ideally a single word or acronym. Avoid prefixes like “Lighthouse” or “Plugin”.

Audit titles

Write titles in the present tense that describe what the page is or is not doing. Do
  • “Uses HTTPS”
  • “Does not use HTTPS”
  • “Tap targets are sized appropriately”
Don’t
  • “Good job on alt attributes”
  • “Fix your headers”

Audit descriptions

Provide brief context for why the audit matters and link to guides. Markdown links are supported. Do
All sites should be protected with HTTPS, even ones that don’t handle sensitive data. HTTPS prevents intruders from tampering with communications. Learn more.
Don’t
Images need alt attributes.

Common mistakes

Forgetting to filter or normalize artifact data is a frequent source of bugs.
  • Forgetting to filter: Most audits have a specific use case, but edge cases come up frequently — blob:, data:, and file: URLs for network requests; non-JavaScript script types; 1×1 tracking pixel images.
  • Forgetting to normalize: Artifact values represent what was observed on the page. Header names and values, script type values, and src values may have leading/trailing whitespace, be mixed-case, or be relative URLs.

Examples