Giter VIP home page Giter VIP logo

react-lighthouse-viewer's Introduction

react-lighthouse-viewer

If you have generated lighthouse report using lighthouse CLI, you can use this component to render the JSON report inside React.

Installation

yarn add react-lighthouse-viewer

Usage

import React from 'react';
import { render } from 'react-dom';
import ReportViewer from 'react-lighthouse-viewer';

import jsonReport from './report.json';

const App = () => (
    <ReportViewer json={jsonReport} />
);
render(<App />, document.getElementById("root"));

To generate lighthouse reports, use CLI

Install lighthouse globally

npm install -g lighthouse

Run CLI: lighthouse https://blencorp.com --output=json --output-path=./report.json

By default, Lighthouse writes the report to an HTML file. You can control the output format by passing flags.

CLI options

$ lighthouse --help

lighthouse <url>

Logging:
  --verbose  Displays verbose logging                                                                                                      [boolean]
  --quiet    Displays no progress, debug logs or errors                                                                                    [boolean]

Configuration:
  --save-assets                  Save the trace & devtools log to disk                                                                     [boolean]
  --list-all-audits              Prints a list of all available audits and exits                                                           [boolean]
  --list-trace-categories        Prints a list of all required trace categories and exits                                                  [boolean]
  --print-config                 Print the normalized config for the given config and options, then exit.                                  [boolean]
  --additional-trace-categories  Additional categories to capture with the trace (comma-delimited).
  --config-path                  The path to the config JSON.
  --chrome-flags                 Custom flags to pass to Chrome (space-delimited). For a full list of flags, see
                                 http://peter.sh/experiments/chromium-command-line-switches/.

                                 Environment variables:
                                 CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of
                                 Chromium version 66.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
                                                                                                                                       [default: ""]
  --port                         The port to use for the debugging protocol. Use 0 for a random port                                    [default: 0]
  --preset                       Use a built-in configuration.                                            [choices: "full", "perf", "mixed-content"]
  --hostname                     The hostname to use for the debugging protocol.                                              [default: "localhost"]
  --max-wait-for-load            The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue.
                                 WARNING: Very high values can lead to large traces and instability                                 [default: 45000]
  --emulated-form-factor         Controls the emulated device form factor (mobile vs. desktop) if not disabled                      [choices: "mobile", "desktop", "none"] [default: "mobile"]
  --enable-error-reporting       Enables error reporting, overriding any saved preference. --no-enable-error-reporting will do the opposite. More:
                                 https://git.io/vFFTO
  --gather-mode, -G              Collect artifacts from a connected browser and save to disk. If audit-mode is not also enabled, the run will quit
                                 early.                                                                                                    [boolean]
  --audit-mode, -A               Process saved artifacts from disk                                                                         [boolean]

Output:
  --output       Reporter for the results, supports multiple values                        [choices: "csv", "json", "html"] [default: "html"]
  --output-path  The file path to output the results. Use 'stdout' to write to stdout.
                 If using JSON or CSV output, default is stdout.
                 If using HTML output, default is a file in the working directory with a name based on the test URL and date.
                 If using multiple outputs, --output-path is appended with the standard extension for each output type. "reports/my-run" -> "reports/my-run.report.html", "reports/my-run.report.json", etc.
                 Example: --output-path=./lighthouse-results.html
  --view         Open HTML report in your browser                                                                                          [boolean]

Options:
  --help                        Show help                                                                                                  [boolean]
  --version                     Show version number                                                                                        [boolean]
  --blocked-url-patterns        Block any network requests to the specified URL patterns                                                     [array]
  --disable-storage-reset       Disable clearing the browser cache and other storage APIs before a run                                     [boolean]
  --disable-device-emulation    Disable all device form factor emulation. Deprecated: use --emulated-form-factor=none instead              [boolean]
  --throttling-method                  Controls throttling method         [choices: "devtools", "provided", "simulate"]
  --throttling.rttMs                   Controls simulated network RTT (TCP layer)
  --throttling.throughputKbps          Controls simulated network download throughput
  --throttling.requestLatencyMs        Controls emulated network RTT (HTTP layer)
  --throttling.downloadThroughputKbps  Controls emulated network download throughput
  --throttling.uploadThroughputKbps    Controls emulated network upload throughput
  --throttling.cpuSlowdownMultiplier   Controls simulated + emulated CPU throttling
  --extra-headers               Set extra HTTP Headers to pass with request                                                                 [string]

Examples:
  lighthouse <url> --view                                                   Opens the HTML report in a browser after the run completes
  lighthouse <url> --config-path=./myconfig.js                              Runs Lighthouse with your own configuration: custom audits, report
                                                                            generation, etc.
  lighthouse <url> --output=json --output-path=./report.json --save-assets  Save trace, devtoolslog, and named JSON report.
  lighthouse <url> --disable-device-emulation                               Disable device emulation and all throttling.
    --throttling-method=provided
  lighthouse <url> --chrome-flags="--window-size=412,660"                   Launch Chrome with a specific window size
  lighthouse <url> --quiet --chrome-flags="--headless"                      Launch Headless Chrome, turn off logging
  lighthouse <url> --extra-headers "{\"Cookie\":\"monster=blue\"}"          Stringify\'d JSON HTTP Header key/value pairs to send in requests
  lighthouse <url> --extra-headers=./path/to/file.json                      Path to JSON file of HTTP Header key/value pairs to send in requests

For more information on Lighthouse, see https://developers.google.com/web/tools/lighthouse/.

Cool Guide by Brad Stiff

A guide to building a React component with webpack 4, publishing to npm, and deploying the demo to GitHub Pages Read more ๐Ÿ‘


Hacked with โค๏ธ by BLEN Corp in Washington, DC.

react-lighthouse-viewer's People

Contributors

dependabot[bot] avatar j-mendez avatar naodya avatar tanas0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-lighthouse-viewer's Issues

Dynamic JSON report

Is there a way to use fetch to load in a JSON report instead of import, so that the JSON report can be dynamic?

This is a general question, I just added some code that I am using below to share a bit.

Thanks!!

`import React from 'react';
import { render } from 'react-dom';
import ReportViewer from '../../../src/index.js';
import jsonReport from "../../../example/src/report5.json";
import { Component } from 'react';

//console.log(drupalSettings.pfizer_lighthouse);

/**

  • App
    */
    class App extends React.Component {

    constructor(props) {
    super(props);
    this.state = {
    report: null,
    loaded: false,
    };
    }

    /**

    • Load articles via Drupal JSON:API.
      */
      componentDidMount() {

      fetch('/sites/default/files/lighthouse-reports/pfpfizeruscom-stage.pfizersite.io-20200512T112713.json?sdasds')
      .then(data => this.setState({ report: data, loaded: true }));
      }

    render() {

     const { report, loaded } = this.state;
    
     if (!loaded) {
         return <p>Loading ...</p>;
     }
     if (report.length === 0) {
         return <p>No results</p>;
     }
    
    
     console.log(report);
    
     return <ReportViewer json={report} />;
    

    }
    }

export default App;
`

SyntaxError: Unexpected token .

The component does not work. What the conflict in work with styles. Do you know how to solve it?

SyntaxError: Unexpected token .
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/Users/kodix/Documents/lighthhause-git/light-house/node_modules/react-lighthouse-viewer/dist/index.js:33:1)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)

CSS Broken , module not working

Error on front-end and console:

Failed to compile...
./node_modules/react-lighthouse-viewer/dist/report-styles.css (./node_modules/css-loader??ref--6-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./node_modules/react-lighthouse-viewer/dist/report-styles.css)
Unclosed bracket (754:19)

752 | flex-grow: 0;
753 | flex-shrink: 0;

754 | flex-basis: calc(3 * var(--report-font-size);
| ^
755 | }
756 |
757 |

Fix : remove the below line from css :
file: react-lighthouse-viewer/dist/report-styles.css

initial code :
.lh-audit--load-opportunity .lh-audit__display-text {
text-align: right;
flex: 0 0 calc(3 * var(--report-font-size));
}

final code to update:

.lh-audit--load-opportunity .lh-audit__display-text {
text-align: right;
flex: calc(3 * var(--report-font-size));
}

CSS is broken

The component is loading. but, CSS is broken. does it require a CSS loader?

image

image

Lighthouse 5

Hello there,

I am trying to use your component with a JSON report generated using the latest version of lighthouse (version 5).

I tried setting it up in different ways, but I am facing issues with the rendering and an error message.

I was wondering, if you are supporting Lighthouse 5? If not, are you planning to do so? And if not also, what would be the steps to support Lighthouse 5, since they had some breaking changes?
I am seriously interested in supporting Lighthouse 5 as a feature.

The error states:

TypeError: " is not a valid URL."

Screenshot from 2019-08-05 09-08-31

I tried going through the source looking for that error message, or the mounted hook that React complains about, but couldn't find anything.

I would appreciate any clarification you could bring and thanks in advance

Publishing without styles?

Thank you for the work done on the repo. I was trying to figure out how the source code and package dist have some differences. In the source theres a css file thats being loaded but, in the dist its removed and inlined with the template. I tried using yarn transpile to see if it would properly build the dist but, it looks like some things where mainly stitched together? Trying to make a fork with some small changes for use with next.js.

Report not rendering.....

Thanks for the 2.8 release.
Report not rendering when I'm using <ReportViewer json={JSONREPORTMOB} /> two times on the same page one for desktop report and other for mobile report.
<ReportViewer id="mobile" /> must accept custom id as props or auto-generate id,

From below code I'm getting report of {JSONREPORTMOB} in first tab <ReportViewer json={JSONREPORTDESK} />
**Note: Im not getting error in console but template id is same for both report ** <ReportViewer />
Find code below:

<TabContent activeTab={this.state.activeTab}> <TabPane tabId="1"> <Card> <CardBody> <ReportViewer json={JSONREPORTDESK} /> </CardBody> </Card> </TabPane> <TabPane tabId="2"> <Card> <CardBody> <ReportViewer json={JSONREPORTMOB} /> </CardBody> </Card> </TabPane> </TabContent>

Background
Screenshot from 2020-04-15 19-45-51

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.