lighthouse/report
Connor Clark 674283e274 convert crq to tree details in lh compat 2023-03-03 11:22:45 -08:00
..
assets update style names 2023-03-03 11:22:45 -08:00
clients misc: rename lighthouse-(core,cli) folders (#14242) 2022-07-29 13:55:41 -07:00
generator core: merge `api.js` into `index.js`, new report generator api (#14531) 2022-11-15 09:43:14 -08:00
renderer convert crq to tree details in lh compat 2023-03-03 11:22:45 -08:00
test core(prioritize-lcp-image): better identify lcp request (#14804) 2023-02-16 16:03:46 -06:00
test-assets report: fix compat for older lighthouse reports (#14617) 2023-01-23 10:49:46 -08:00
types core: restructure types for direct import and publishing (#14441) 2023-01-19 14:31:43 -08:00
.eslintrc.cjs misc: move ES modules lint rules to root (#14349) 2022-09-02 13:45:55 -07:00
README.md core: finalize master => main branch rename (#14409) 2022-09-27 14:59:53 -07:00
tsconfig.json misc: split lhr compat code to lib/lighthouse-compatibility.js (#14701) 2023-01-31 16:30:18 -08:00

README.md

Lighthouse HTML Report Renderer

Overview

Lighthouse has an independent report renderer that takes the LHR (Lighthouse Result object) and creates a DOM tree of the report. It's all done client-side.

Example standalone HTML report, delivered by the CLI: dbwtest-3.0.3.html (View the source! 📖)

Report Renderer components

  1. report/generator/report-generator.js is the entry point for generating the HTML from Node. It compiles together the HTML string with everything required within it.
    • It runs natively in Node.js but can run in the browser after a compile step is applied during our bundling pipeline. That compile step uses inline-fs, which takes any fs.readFileSync() calls and replaces them with the stringified file content.
  2. report/renderer are all client-side JS files. They transform an LHR object into a report DOM tree. They are all executed within the browser.
  3. report/assets/standalone-template.html is where the client-side build of the DOM report is typically kicked off (with these four lines) However, see Current Uses.. below for more possibilities.

Data Hydration

innerHTML is deliberately not used. The renderer relies on basic createElement as well as multiple components defined in <template> tags that are added via document.importNode() and filled in via the querySelector/textContent combo.

Examples:

Current uses of report renderer

The renderer was designed to be portable across various environments.

  1. LH CLI: It creates the HTML as the runner finishes up and saves it to disk.
  2. Chrome DevTools Lighthouse Panel: The renderer files are rolled into the Chromium repo, and they execute within the DevTools context. The audits panel receives the LHR object from a WebWorker, through a postMessage and then runs the renderer within DevTools UI, making a few simplifications.
  3. Hosted Lighthouse Viewer: It's a webapp that has the renderer (along with some additional features) all compiled into a main-XXX.js file. Same basic approach there.