Last active
September 29, 2020 14:22
-
-
Save svkrclg/0f7403f256e2bdc307e5853fb87cc4f2 to your computer and use it in GitHub Desktop.
Lighthouse score for different network throttling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const lighthouse = require('lighthouse'); | |
const chromeLauncher = require('chrome-launcher'); | |
(async () => { | |
const chrome = await chromeLauncher.launch(); | |
const options = {logLevel: 'info', output: 'json', onlyCategories: ['performance'], port: chrome.port}; | |
const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75; | |
const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9; | |
const mobileRegular3g = { | |
extends: 'lighthouse:default', | |
settings: { | |
maxWaitForFcp: 15 * 1000, | |
maxWaitForLoad: 35 * 1000, | |
emulatedFormFactor: 'desktop', | |
throttling: { | |
rttMs: 300, | |
throughputKbps: 700, | |
requestLatencyMs: 300 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR, | |
downloadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, | |
uploadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, | |
} | |
} | |
}; | |
const mobileSlow4G = { | |
extends: 'lighthouse:default', | |
settings: { | |
maxWaitForFcp: 15 * 1000, | |
maxWaitForLoad: 35 * 1000, | |
emulatedFormFactor: 'desktop', | |
throttling: { | |
rttMs: 150, | |
throughputKbps: 1.6 * 1024, | |
requestLatencyMs: 150 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR, | |
downloadThroughputKbps: 1.6 * 1024 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, | |
uploadThroughputKbps: 750 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, | |
} | |
} | |
}; | |
const desktopDense4g = { | |
extends: 'lighthouse:default', | |
settings: { | |
maxWaitForFcp: 15 * 1000, | |
maxWaitForLoad: 35 * 1000, | |
emulatedFormFactor: 'desktop', | |
throttling: { | |
rttMs: 40, | |
throughputKbps: 10 * 1024, | |
requestLatencyMs: 0, | |
downloadThroughputKbps: 0, | |
uploadThroughputKbps: 0, | |
} | |
} | |
}; | |
const runnerResult = await lighthouse('https://browserstack.com', options, mobileRegular3g); | |
// `.report` is the HTML report as a string | |
const report = runnerResult.report; | |
fs.writeFileSync('finalReport.json', report); | |
// `.lhr` is the Lighthouse Result as a JS object | |
console.log('Report is done for', runnerResult.lhr.finalUrl); | |
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100); | |
await chrome.kill(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment