Skip to content

Commit

Permalink
docs: update docs/readme.md for 10.0 (#14457)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jan 25, 2023
1 parent e5a7c65 commit bda4a77
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ internals, see [Lighthouse Architecture](architecture.md).
The example below shows how to run Lighthouse programmatically as a Node module. It
assumes you've installed Lighthouse as a dependency (`yarn add --dev lighthouse`).

```javascript
const fs = require('fs');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
```js
import fs from 'fs';
import lighthouse from 'lighthouse';
import chromeLauncher from 'chrome-launcher';

(async () => {
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};
const runnerResult = await lighthouse('https://example.com', options);
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port};
const runnerResult = await lighthouse('https://example.com', options);

// `.report` is the HTML report as a string
const reportHtml = runnerResult.report;
fs.writeFileSync('lhreport.html', reportHtml);
// `.report` is the HTML report as a string
const reportHtml = runnerResult.report;
fs.writeFileSync('lhreport.html', reportHtml);

// `.lhr` is the Lighthouse Result as a JS object
console.log('Report is done for', runnerResult.lhr.finalDisplayedUrl);
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
// `.lhr` is the Lighthouse Result as a JS object
console.log('Report is done for', runnerResult.lhr.finalDisplayedUrl);
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);

await chrome.kill();
})();
await chrome.kill();
```

### Performance-only Lighthouse run
Expand All @@ -35,9 +33,8 @@ Many modules consuming Lighthouse are only interested in the performance numbers
You can limit the audits you run to a particular category or set of audits.

```js
// ...
const flags = {onlyCategories: ['performance']};
launchChromeAndRunLighthouse(url, flags).then( // ...
await lighthouse(url, flags);
```

You can also craft your own config (e.g. [experimental-config.js](https://github.com/GoogleChrome/lighthouse/blob/main/core/config/experimental-config.js)) for custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/main/docs/recipes/custom-audit).
Expand Down Expand Up @@ -68,8 +65,7 @@ the `logLevel` flag when calling `lighthouse`.

```javascript
const flags = {logLevel: 'info'};

launchChromeAndRunLighthouse('https://example.com', flags).then(...);
await lighthouse('https://example.com', flags);
```

## Configuration
Expand Down Expand Up @@ -147,7 +143,6 @@ As an example, here's a trace-only run that reports on user timings and critical
"user-timings",
"critical-request-chains"
],
"categories": {
"performance": {
"name": "Performance Metrics",
Expand Down

0 comments on commit bda4a77

Please sign in to comment.