问题
Is there a way to intercept and mock WebSockets requests/responses with puppeteer?
page.on('request', request => {
console.log('Intercepting Request ', request, { depth: null });
request.continue();
});
page.on('response', response => {
console.log('Intercepting Response ', response, { depth: null });
response.abort();
});
does not show the requests/responses made through WebSocket.
This How to use puppeteer to dump WebSocket data is answering the question somewhat, but not by using puppeteer
but by using ws
.
回答1:
Did you set the request interception?
await page.setRequestInterception(true)
page.on('request', interceptedRequest => {
interceptedRequest.continue()
})
来源:https://stackoverflow.com/questions/55000827/intercept-and-mock-websockets-request-responses-with-pupeteer