1

我正在使用 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');
});
});
4

0 回答 0