Lighthouse devtools 网络记录中仅返回 GET 请求
Only GET requests are returned in lighthouse devtools network records
我正在尝试 运行 对网页在加载期间发出的网络请求进行某些审核,下面是我的审核示例代码。我面临一个问题,灯塔返回的所有网络记录都只针对 GET 请求。有什么方法可以获取 POST、PUT 等
的记录
示例代码:
class NetworkAudit extends Audit {
static get meta() {
return {
id: 'network-audit',
title: 'Network analysis',
failureTitle: 'Custom network stats failing',
description: 'Custom network stats ',
requiredArtifacts: ['devtoolsLogs'],
};
}
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const requests = await NetworkRecords.request(devtoolsLog, context);
for(request of requests ){
console.log(request.requestMethod)
}
找了一圈之后,我找到了一种捕获所有网络请求的方法,并创建了一个 npm 包 https://www.npmjs.com/package/lighthouse-network-gatherer
安装包后,使用非常简单,附上示例代码
class NetworkLogs extends networkGatherer{
constructor(){
super()
}
}
module.exports = NetworkLogs
我正在尝试 运行 对网页在加载期间发出的网络请求进行某些审核,下面是我的审核示例代码。我面临一个问题,灯塔返回的所有网络记录都只针对 GET 请求。有什么方法可以获取 POST、PUT 等
的记录示例代码:
class NetworkAudit extends Audit {
static get meta() {
return {
id: 'network-audit',
title: 'Network analysis',
failureTitle: 'Custom network stats failing',
description: 'Custom network stats ',
requiredArtifacts: ['devtoolsLogs'],
};
}
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const requests = await NetworkRecords.request(devtoolsLog, context);
for(request of requests ){
console.log(request.requestMethod)
}
找了一圈之后,我找到了一种捕获所有网络请求的方法,并创建了一个 npm 包 https://www.npmjs.com/package/lighthouse-network-gatherer
安装包后,使用非常简单,附上示例代码
class NetworkLogs extends networkGatherer{
constructor(){
super()
}
}
module.exports = NetworkLogs