google-chrome-devtools - CDP 过滤网络请求 - Puppteer
问题描述
我正在尝试使用 Puppteer 获取特定网络请求的时间。
有没有办法在 Puppteer 中过滤来自 Chrome DevTools 协议的请求,以便responseReceived
只有在收到这个特定的网络响应时才会触发?
我这个任务的实际代码是:
const client = await page.target().createCDPSession();
await client.send('Network.enable');
// this method is deprecated and I don't know if it was the right thing to use ( https://chromedevtools.github.io/devtools-protocol/tot/Network#method-setRequestInterception )
await client.send('Network.setRequestInterception', {
patterns: [
{
urlPattern: 'https://www.example.com/*task=customaction*',
resourceType: 'XHR',
interceptionStage: 'HeadersReceived'
}
]
});
client.on('responseReceived', (requestId, loaderId, timestamp, type, response, frameId) => {
console.log(`Debug data from: ${response.url} (${requestId})`)
console.log('Timing:')
console.log(response.timing)
detach()
})
该文档建议使用 Fetch 作为Network.setRequestInterception
(https://chromedevtools.github.io/devtools-protocol/tot/Fetch)的替代品,但看起来 Fetch Domain 建议修改网络请求。
解决方案
为时已晚,希望您已经解决了这个问题。但是,发布以便任何人都可以从中受益。
您可以使用此处显示的指标的帮助
推荐阅读
- documentation - 可以重新构建 CHM 文件以便所有 html 文件都是本地的吗?
- javascript - 尝试在 React Native Expo 中的空对象引用上调用虚拟方法 'byte[] java.lang.String.getBytes()'
- react-native - ld: 找不到 -lDoubleConversion 的库
- python - 在 databricks 的 Python Wheel 包中找不到依赖项
- java - 如何转换 Java Android 代码以转换 iOS Swift 代码中的图像文件以创建 JSON
- spring-boot - X509 身份验证适用于 TLS 1.1,但不适用于 1.2 和 1.3:无效签名
- json - 是否有人类可读的结构化日志记录格式?
- c++ - 如何应对 CUDA 中的共享内存大小和块数
- sql - 有没有办法找到哪个用户创建或最后修改了一个表?
- javascript - .sort getting value by a listener Javascript