【问题标题】:CDP filter Network requests - PuppteerCDP 过滤网络请求 - Puppeteer
【发布时间】:2020-05-19 03:20:02
【问题描述】:

我正在尝试使用 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 建议修改网络请求。

【问题讨论】:

    标签: google-chrome-devtools puppeteer chrome-devtools-protocol


    【解决方案1】:

    为时已晚,希望您已经解决了这个问题。但是,发布以便任何人都可以从中受益。

    您可以参考here中显示的指标

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2018-10-26
      • 1970-01-01
      • 2017-07-01
      相关资源
      最近更新 更多