首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CDP过滤网络请求-木偶

CDP过滤网络请求-木偶
EN

Stack Overflow用户
提问于 2020-02-03 19:11:41
回答 1查看 708关注 0票数 0

我正在尝试使用Puppteer获取特定网络请求的时间。

有没有办法在Puppteer中过滤来自Chrome DevTools协议的请求,以便只有在收到这个特定的网络响应时才会触发responseReceived

我执行此任务的实际代码是:

代码语言:javascript
复制
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建议修改网络请求。

EN

回答 1

Stack Overflow用户

发布于 2020-08-11 14:10:27

为时已晚,希望你已经解决了这个问题。然而,发帖让任何人都能从中受益。

您可以借助here中所示的指标

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60038038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档