我正在尝试使用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建议修改网络请求。
发布于 2020-08-11 14:10:27
为时已晚,希望你已经解决了这个问题。然而,发帖让任何人都能从中受益。
您可以借助here中所示的指标
https://stackoverflow.com/questions/60038038
复制相似问题