Intercepting data from WebSockets in WebBrowser

Viewed 20

I have to develop a WinForms app with embedded web browser. The browser could be either WebBrowser control or WebView2. Once I supply IP address to the address line the browser starts getting data from the server (of that IP) over WebSocket. I think the browser is the one that creates the WebSocket and connects to the server. My question is: how to I intercept the data that comes over the WebSocket from the server? Somehow I need to hookup to this web socket. Redundant to say that my code in the app is C#. I need to do some calculations on that data. I was thinking creating my own WebSocket or Socket in C# and connecting to the server with that IP, but I am not sure if the server accepts multiple connections...

1 Answers

Apparently it is possible to launch a browser with the page and then create CDP session (Chrome DevTools Protocol) that allows interacting with browser API and thus intercept a WebSocket communication. CDP is the foundation for Microsoft Edge DevTools, which is now in Preview. Meanwhile CDP can be used... Alternatively, I can also use open source PuppeteerSharp library that I can get via NuGet and it gives access to CDP... Anyway, that's the direction that I will be be digging in...

Related