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 Users install your plugin and then pass
lighthouse-plugin-, users can discover and install it directly.--plugins=lighthouse-plugin-example to their Lighthouse CLI invocations or programmatic API calls.Plugin config API
Theplugin.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.
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.
Available artifacts
Page context artifacts
Page context artifacts
Host environment artifacts
Host environment artifacts
Page content artifacts
Page content artifacts
Network & trace artifacts
Network & trace 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 fromDevtoolsLog 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”
- “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. DoAll 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: Most audits have a specific use case, but edge cases come up frequently —
blob:,data:, andfile: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
typevalues, andsrcvalues may have leading/trailing whitespace, be mixed-case, or be relative URLs.
Examples
- Lighthouse Plugin Recipe — official minimal example
- Field Performance — displays Chrome UX Report data
- Publisher Ads Audits — a well-structured, full-featured plugin
- Green Web Foundation — checks which domains run on renewable power