7

I'm trying to use the Chrome DevTools Protocol (CDP) to intercept web requests and modify them.

The problem is that I need to modify the headers of a WebSocket request. Is this possible?

I can modify the headers of "normal" requests easily by first sending messages:

Network.enable
Network.setRequestInterception

and then listening for the Network.requestIntercepted message and replying with an appropriate Network.continueInterceptedRequest message.

However, Network.requestIntercepted does not get called for WebSockets. I can listen for Network.webSocketWillSendHandshakeRequest but this only lets me read the request, I don't see any way to modify it.

Is there a way to do this, or is this impossible at the moment?

Master_T
  • 7,232
  • 11
  • 72
  • 144
  • The documentation says setRequestInterception is deprecated and suggests using [Fetch](https://chromedevtools.github.io/devtools-protocol/tot/Fetch). The latter has WebSocket in its RequestPattern type so maybe it can actually intercept it. – wOxxOm Sep 10 '19 at 05:50
  • 1
    @wOxxOm: thanks for your comment, but it doesn't seem to work.... I tried using it (tried both with and without an explicit pattern), but like the old version it only seems to intercept "normal" requests, not websocket ones... – Master_T Sep 10 '19 at 07:31
  • 2
    Bug report about not being able to use Fetch with WebSocket resource type: https://bugs.chromium.org/p/chromium/issues/detail?id=1283412 – teg_brightly Dec 30 '21 at 13:14

1 Answers1

2

After further testing of all possible combinations, I came to the conclusion that this cannot be done, unfortunately.

If I'm wrong, feel free to correct me and I'll accept your answer and delete this one.

Master_T
  • 7,232
  • 11
  • 72
  • 144