Intercept and mock WebSockets request/responses with pupeteer

核能气质少年 提交于 2019-12-13 03:14:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!