UNPKG

preload-links-by-lighthouse

Version:

Generate html with embedded preload links using lighthouse

22 lines 721 B
import { launch } from 'chrome-launcher'; import lighthouse from 'lighthouse'; const DEFAULT_OPTIONS = { output: 'json', onlyAudits: ['network-requests'], }; export async function auditNetworkRequest(url, lighthouseOptions) { const chrome = await launch({ chromeFlags: ['--headless'] }); const report = await lighthouse(url, { ...DEFAULT_OPTIONS, ...lighthouseOptions, port: chrome.port, }); await chrome.kill(); if (report === undefined) { throw new Error('Fail to generate report by lighthouse'); } const result = report.lhr; const items = result.audits['network-requests'].details.items; return items; } //# sourceMappingURL=lighthouse.js.map