0

I am trying to get timing of a specific network request with Puppteer.

Is there any way to filter requests from Chrome DevTools Protocol in Puppteer, so that responseReceived will be fired only when this specific network response is received?

My actual code for this task is:

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()
})

The documentation suggests to use Fetch as replacement of Network.setRequestInterception(https://chromedevtools.github.io/devtools-protocol/tot/Fetch), but it looks like that Fetch Domain propose is modify network requests.

ccpizza
  • 28,968
  • 18
  • 162
  • 169
alessionossa
  • 923
  • 2
  • 15
  • 41

1 Answers1

0

It's too late and hope you already solved this. However, posting so that anyone can benefit this.

You can take help of metrics as shown in here

Satya Arya
  • 95
  • 6