我正在使用Node JS以编程方式使用灯塔。以前设法得到结果,但现在我似乎无法得到结果。检查了端口并注意到网站已打开但灯塔未运行。
Chrome Launcher版本为“^ 0.10.2”,Lighthouse版本为^ 2.8.0
"use strict";
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
function launchChromeAndRunLighthouse(url, flags = {}, config = null) {
return chromeLauncher.launch(flags).then(chrome => {
flags.port = chrome.port;
console.log(chrome.port);
return lighthouse(url, flags, config).then(results =>
chrome.kill().then(() => results));
});
}
const flags = {
chromeFlags: ['disable-gpu','--headless']
};
launchChromeAndRunLighthouse('https://github.com', flags).then(results => {
fs.appendFile('result.txt', JSON.stringify(results), (err) => {
console.log('error appending to file example.txt');
});
});