@浏览器无/灯塔:使用木偶机进行无浏览器灯塔集成.
见 灯塔部分 我们的网站有更多信息.
安装
使用 npm :
npm install @browserless/lighthouse --save
关于
此软件包提供 谷歌灯塔集成 对于无浏览器,允许您使用您现有的无浏览器设置运行性能,访问,SEO,以及任何URL上的最佳做法审核.
这个软件包做什么
这个 @browserless/lighthouse 软件包允许您 :
- 运行灯塔审计 具有充分性能、可获取性、标准作业程序和PWA分析
- 生成报告 以 JSON 、 HTML 或 CSV 格式
- 使用灯塔预设 用于桌面或移动配置
- 定制审计 选择特定类别或跳过某些检查
- 重用您已有的无浏览器实例 审计
使用量
const createLighthouse = require('@browserless/lighthouse')
const createBrowser = require('browserless')
// Create a browserless instance
const browser = createBrowser()
// Create the lighthouse function with teardown support
const lighthouse = createLighthouse(async teardown => {
const browserless = await browser.createContext()
teardown(() => browserless.destroyContext())
return browserless
})
// Run an audit
const report = await lighthouse('https://example.com')
console.log(report.categories.performance.score)
选项
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
output | string | 'json' | 报告格式 : 'json', (中文(简体) ), 'html',或 'csv' |
timeout | number | —— 说 | 审计超时( 毫秒) |
preset | string | —— 说 | 灯塔预设: 'lr-desktop', (中文(简体) ), 'lr-mobile'等 (中文(简体) ). |
flags | object | —— 说 | 灯塔旗帜 |
onlyAudits | string[] | —— 说 | 只进行特定审计 |
skipAudits | string[] | —— 说 | 略去具体审计 |
onlyCategories | string[] | —— 说 | 只运行特定类别 |
输出格式
// JSON (default) - returns the Lighthouse Result object (lhr)
const jsonReport = await lighthouse(url, { output: 'json' })
console.log(jsonReport.categories.performance) // 0.95
// HTML - returns the full HTML report as a string
const htmlReport = await lighthouse(url, { output: 'html' })
await fs.writeFile('report.html', htmlReport)
// CSV - returns CSV-formatted data
const csvReport = await lighthouse(url, { output: 'csv' })
灯塔预设
常见配置使用内置灯塔预设:
// Desktop configuration (higher viewport, no throttling)
const report = await lighthouse(url, { preset: 'lr-desktop' })
// Mobile configuration (smaller viewport, CPU/network throttling)
const report = await lighthouse(url, { preset: 'lr-mobile' })
定制审计
// Run only specific audits
const report = await lighthouse(url, {
onlyAudits: ['first-contentful-paint', 'largest-contentful-paint']
})
// Run only specific categories
const report = await lighthouse(url, {
onlyCategories: ['performance', 'accessibility']
})
// Skip specific audits
const report = await lighthouse(url, {
skipAudits: ['uses-http2', 'bf-cache']
})
报告结构(JSON)
在使用JSON输出时,报告包括:
const report = await lighthouse(url)
// Categories with scores (0-1)
report.categories.performance.score // Performance score
report.categories.accessibility.score // Accessibility score
report.categories.seo.score // SEO score
report.categories['best-practices'].score // Best practices score
report.categories.pwa.score // PWA score (if applicable)
// Individual audits
report.audits['first-contentful-paint'].numericValue // FCP in ms
report.audits['largest-contentful-paint'].numericValue // LCP in ms
report.audits['cumulative-layout-shift'].numericValue // CLS score
report.audits['total-blocking-time'].numericValue // TBT in ms
// Configuration used
report.configSettings
如何适合在单体
这个 扩展功能包 业绩审计:
| 消费者 | 目的 |
|---|---|
@browserless/cli | 权力 browserless lighthouse 命令 |
依赖关系
| 软件包 | 目的 |
|---|---|
lighthouse | 谷歌灯塔核心图书馆 |
许可证
@ 无眉/ 灯塔 © 微链接,在 麻省理工学院 执照.
作者和维护者 微链接 由来自 捐助者。 。 。 .
微链接.io • GitHub 软件 微链克 • X @microlinkhq (英语)