Skip to content

Instantly share code, notes, and snippets.

@vikramvi
Created March 14, 2018 16:43
Show Gist options
  • Save vikramvi/90f04717baf5bb7f348bb74ab75d8882 to your computer and use it in GitHub Desktop.
Save vikramvi/90f04717baf5bb7f348bb74ab75d8882 to your computer and use it in GitHub Desktop.
lh1.js ( not working - this is as per documentation )
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
// process.env.args = " --veiw --disable-network-throttling --disable-cpu-throttling"
// console.log(process.env.args);
function launchChromeAndRunLighthouse(url, opts, config = null) {
return chromeLauncher.launch({chromeFlags: opts.chromeFlags}).then(chrome => {
opts.port = chrome.port;
console.log(lighthouse)
return lighthouse(url, opts, config).then(results => {
// The gathered artifacts are typically removed as they can be quite large (~50MB+)
delete results.artifacts;
return chrome.kill().then(() => results)
});
});
}
const opts = {
view: true,
disableDeviceEmulation: true,
disableCpuThrottling: true,
chromeFlags: ['--show-paint-rects']
};
// Usage:
launchChromeAndRunLighthouse('https://www.smava.de', opts).then(results => {
console.log("HIiiiiiiii"); // Use results!
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment