Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,74 @@

The coach helps you find performance, best practice and privacy problems on your web page. *coach-core* holds the JavaScript functionality to analyse your page, the [Coach project](https://github.com/sitespeedio/coach) is the CLI.

Execute this code after running `npm run combine && npm run terser`
The command needs to be rerun after the code changes
```js
const coach = require('coach-core');
const fs = require('fs');
const coach = require('./lib/index.js');
// Alternatively:
// const coach = require('coach-core');

// Get the JavaScript code that will analyse a page
const domAdviceJavaScript = await coach.getDomAdvice();
// Take the *domAdviceJavaScript* and run it in your browser and take care of the result.
const domResult = ...

const har = // we get the HAR from a browser
// Copy and execute the code in your browser console or via Puppeteer, Selenium, etc.
console.log(domAdviceJavaScript);

// If your HARhar contains multiple pages (multiple runs etc) you can use the API
// Then save the result into the next line, it has to be a JSON object
const domResult = {
"advice": [
// ...
],
"errors": {
// ...
},
"url": "https://www.website.com/",
"version": "8.1.1"
};
// Alternatively as a file (e.g., domResult.json):
// const har = JSON.parse(fs.readFileSync('./domResult.json', 'utf8'));

// Get the HAR from a browser (e.g., from Chrome DevTools, Puppeteer, or WebDriver)
// Then save the result into the next line, it has to be a JSON object
const har = {
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "537.36"
},
"pages": [
{
"startedDateTime": "2025-01-01T00:00:00.000Z",
"id": "page_1",
"title": "https://www.website.com/",
"pageTimings": {
"onContentLoad": 123.456,
"onLoad": 456.789
}
}
],
"entries": [
// this should be a list of entries
]
}
}

// Alternatively as a file (e.g., website.har):
// const har = JSON.parse(fs.readFileSync('./website.har', 'utf8'));

// If your HAR contains multiple pages (multiple runs etc) you can use the API
// to get the page that you want
const firstPageHar = coach.pickAPage(har, 0);

const harResult = await coach.analyseHar(firstPageHar);

// Say that you got the result from the browser in domAdviceResult
// and the HAR result in harAdviceResult
// Say that you got the result from the browser in domResult
// and the HAR result in harResult
const coachResult = coach.merge(domResult, harResult);

console.log('Coach analysis result:', coachResult);
```

[travis-image]: https://img.shields.io/travis/sitespeedio/coach-core/master.svg?style=flat-square
Expand Down