Фильтр CDP Сетевые запросы - Puppteer - PullRequest
0 голосов
/ 03 февраля 2020

Я пытаюсь получить время для определенного сетевого запроса c с Puppteer.

Есть ли способ отфильтровать запросы из Chrome протокола DevTools в Puppteer, так что responseReceived будет запущен только когда этот указанный c сетевой ответ получен?

Мой фактический код для этой задачи:

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 предлагает изменить сетевые запросы.

...