Chrome DevTools Protocol - intercepting and modifying websocket requests
Asked Answered
N

1

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?

Naturopathy answered 9/9, 2019 at 15:39 Comment(3)
The documentation says setRequestInterception is deprecated and suggests using Fetch. The latter has WebSocket in its RequestPattern type so maybe it can actually intercept it.Unseal
@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...Naturopathy
Bug report about not being able to use Fetch with WebSocket resource type: bugs.chromium.org/p/chromium/issues/detail?id=1283412Zinnia
N
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.

Naturopathy answered 12/9, 2019 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.