大佬教程收集整理的这篇文章主要介绍了在灯塔期间重定向请求或注入脚本,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要对网站进行灯塔测试。我们的产品是一个 JavaScript 文件,由客户在页面上使用 a 注入。现在我想评估“xyz.com”站点(上面没有我们的脚本)的性能。我需要在运行时在此站点上注入我们的脚本并将其传递给 lighthouse 以评估站点的分数和性能。 我尝试使用 puppeteers 注入脚本,然后将其交给 npm 灯塔,但这只会为移动设备生成结果。我需要桌面性能分数。
示例代码:
const fs = require('fs');
console.log('Done fs');
const lighthouse = require('lighthouse');
console.log('Done lighthouse')
const chromeLauncher = require('Chrome-launcher');
(async () => {
const chrome = await ChromeLauncher.launch({ChromeFlags: ['--headless']});
const options = {logLevel: 'info',output: 'HTML',onlyCategorIEs: ['perfoRMANce'],port: Chrome.port,stratergy: "desktop"};
const runnerResult = await lighthouse('xyz.com/',options);
// `.report` is the HTML report as a String
const reportHTML = runnerResult.report;
fs.writefileSync('lhreport.HTML',reportHTML);
// `.lhr` is the lighthouse Result as a Js object
console.log('Report is done for',runnerResult.lhr.finalUrl);
console.log('PerfoRMANce score was',runnerResult.lhr.categorIEs.perfoRMANce.score * 100);
await Chrome.kill();
})();```
I have also trIEd
```preset: "desktop"```
I am also not using
```config-path```
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的在灯塔期间重定向请求或注入脚本全部内容,希望文章能够帮你解决在灯塔期间重定向请求或注入脚本所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。