灯塔报告生成,在吊舱中发出镀铬发射器问题

问题描述

正在使用lighthouse生成网站性能报告,并在node js中完成。

代码如下:

const lighthouse = require("lighthouse");
const chromeLauncher = require("chrome-launcher");
const fs = require('fs');

function generateAndPushLighthouseReport(url) {
  const parentDirName = sails.config.constants.lighthouseReportPath;    
  let dirName = parentDirName + '1234';
  
  if (!fs.existsSync(dirName)) {
    fs.mkdirsync(dirName,{
      recursive: true
    },err => {
      if (err) {
        logger.error(err);
        throw err;
      }
    });
  }

  return chromeLauncher.launch({chromeFlags: ['--headless']}).then(chrome => {
    const opts = {output: 'json',onlyCategories: ['performance'],port: chrome.port,emulatedFormFactor: 'desktop'};
    return lighthouse(url,opts).then(results => {
      fs.writeFile(
        `${dirName}/report.json`,results.report,err => {
            if (err) throw err;
        }
      );

      return chrome.kill().then(() => results.report);
    });
  });
}

通过这种方式,我能够很好地生成json格式的报告,但是当在linux服务器上的kubernetes pod中进行部署时,它会出现如下问题:

The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.

了解到Pod中的功能,我认为不会推出任何Chrome,但无法解决该处的情况。尽管在该项目中使用了DockerFile,但是如果有人这样做或有任何建议,请提供建议!

提前谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)