Last active
September 29, 2020 13:41
-
-
Save svkrclg/f3ec93c8c64037646a93afef49908058 to your computer and use it in GitHub Desktop.
Lighthouse Throttle run
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
/*Need to change fetch different value from url array manually. | |
Because performance degrades with continous run. | |
*/ | |
//Tested for regular 3G | |
const fs = require('fs'); | |
const lighthouse = require('lighthouse'); | |
const chromeLauncher = require('chrome-launcher'); | |
const url = ["https://www.amazon.in/", "https://twitter.com/", "https://www.snapdeal.com/", "https://abc.com/", "https://www.ticket.at/de/home" ]; | |
const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75; | |
const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9; | |
(async () => { | |
element = url[3] | |
const chrome = await chromeLauncher.launch(); | |
const options = {logLevel: 'silent', output: 'json', onlyCategories: ['performance'], port: chrome.port}; | |
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 runnerResult = await lighthouse(element, options, mobileRegular3g); | |
// `.report` is the HTML report as a string | |
const report = runnerResult.report; | |
const file_name = "throttle_"+element.split('/')[2]+".json" | |
fs.writeFileSync(file_name, report); | |
console.log("URL: "+element+ ", " +runnerResult.lhr.categories.performance.score * 100, "runtime: "+ JSON.parse(report).timing.total); | |
await chrome.kill(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment