You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

octoper-lighthouse-viewer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

octoper-lighthouse-viewer

Package with the lighthouse-viewer files from the official repositories of Lighthouse

0.0.2
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Lighthouse Viewer

This is the code extracted from the lighthouse original repository and packaged as an ES Modules for convenience and tree shaking.

The code for this repository is automatically generated every time is built, copying the files, adding the imports and exports for every file.

This is only for convenience, and it would be cool if some day the people from Lighthouse could export this code as well.

Getting started

  • Install it using npm i lighthouse-viewer
  • In your code, import the following modules:
import { DOM, ReportRenderer, ReportUIFeatures, Logger, template } from 'lighthouse-viewer';
import reportJson from './report.json';

const generateReport = (lighthouseReport) => {
  const dom = new DOM(document);
  const renderer = new ReportRenderer(dom);
  const container = document.querySelector('main.lighthouse-viewer');
  renderer.renderReport(lighthouseReport, container);
  const features = new ReportUIFeatures(dom);
  features.initFeatures(lighthouseReport);
};

const mountViewer = () => {
  const htmlTemplate = document.createElement('div');
  htmlTemplate.innerHTML = template;
  const htmlTemplateElement = document.getElementById('html-template');
  if (htmlTemplateElement) {
    htmlTemplateElement.appendChild(htmlTemplate);

    document.addEventListener('lh-log', (e) => {
      const lhLogElement = document.querySelector('#lh-log');
      if (lhLogElement) {
        const logger = new Logger(lhLogElement);
        switch (e.detail.cmd) {
          case 'log':
            logger.log(e.detail.msg);
            break;
          case 'warn':
            logger.warn(e.detail.msg);
            break;
          case 'error':
            logger.error(e.detail.msg);
            break;
          case 'hide':
            logger.hide();
            break;
          default:
        }
      }
    });
  }

  generateReport(reportJson);
};

mountViewer();
  • And in your HTML
<div>
    <div class="lh-root lh-vars">
        <div id="html-template"></div>
        <main class="lighthouse-viewer"></main>
        <div id="lh-log"></div>
    </div>
</div>

All the credits to the Lightouse Authors

If there is any issue with the license or the copyrights, please let me know. There is no other intentions behind this besides making it easy to find.

Keywords

lighthouse

FAQs

Package last updated on 30 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.