How to get the web socket (WS) tab data programmatically? - c#

I want to get information from a web socket running on a website. however since I am not aware of handshaking process I am unable to establish a successful connection to the websocket and retrieve the information being published on the websocket. I assume this falls on the website confidentiality and unless they provide me the documents it is highly unlikely I can get the data directly from the websocket (please correct me if I am wrong).
However since I can view the data from "WS" tab in network section of the chrome (developer mode). I was wondering if there is a way to replicate this programmatically using selenium or any headless browser and I get this information inside my program. my main objective is to get the information using C# however I am open to any other way to get this data.
This is the sample picture of a WS
I have also found this extension "chrome.devtools.network" but I am not sure if it can do the thing I want. I am still searching any advice or help is highly appreciated

With new versions of Selenium webdrive (version 4 - It's beta version) you can create a devtool session of the driver
driver.getDevTools().createSession();
With wich you can send any devtool commands. You should create a web socket event and send the request through it. You can refer this link for Network Domain Chrome DevTools Protocol.
Also, you can use logging preferences properties and intercept performance logs to fetch messages sent and received through websocket.
driver.manage().logs().get(LogType.PERFORMANCE);
I tried the last solution using Java ang get this result for requesting this link
Complete source code is provided here
Note that you should wait until the chrome driver quit. Then in console you'll see the sent and received messages

Related

Intercepting data from WebSockets in WebBrowser

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...
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...

Application send data to web page

I have a web page for data processing. Web page waits for data to process.
And I have a C# application for data. I want to send data to open web page. But I don't want to use socket, Post/Get methods or any web request.
Web page and C# application are client side. They run in same Windows at the same time.
I want to send data to web page from C# app. This operation need to be done with Windows OS or some command line based trigger mechanism.
Web page (Chrome tab or Firefox tab; it doesn't matter) should have tab id the work on. With using this id I may be able to send data to web page from C# app.
But I couldn't really find anything useful.
Is there any way to do this? Is it even possible?
Any advice appreciated.
The way I would approach this is this, assuming you are using either WinForms or WPF:
In your application, embed a web browser:
WPF: https://www.wpf-tutorial.com/misc-controls/the-webbrowser-control/
WinForms: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/webbrowser-control-windows-forms?view=netframeworkdesktop-4.8
Load the web page in that browser
Establish a two-way communication between your client application and the web page:
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/implement-two-way-com-between-dhtml-and-client?view=netframeworkdesktop-4.8
If using other technologies let me know and I'll update answer.
One solution is Raw TCP/IP connection on browser but it's not yet fully supported and implemented. If by Web requests you mean online requests then what #DevRacker said is the best I know, too.
However consider TCP/IP, Web sockets and even REST-APIs are frequently used for Inter-Process Communication (IPC) too, when there is no online transmission of data and the data/command is only transmitted over a local machine.
If I were you, I would use Web sockets or maybe a simpler solution such as Socket-IO.

Capture network traffic through proxy with Appium and C#

I have spent a lot of time browsing for a solution to my problem: I am testing an Android app and will be testing the same app on iOS too very soon, using Appium and C#. My app receives response from the server, which I would want to go through a proxy so that I can sniff as part of my NUnit test to ensure that the response returned from the server is correct and compare it with the response I receive on the app (through SDK).
I understand I can use BrowserMob (using Automated Tester C# library) to do this on desktop browsers using Selenium but I cant find any info for doing this using Appium.
1. Firstly, is it possible to sniff network traffic going to the mobile app?
2. Are there any other possibilities that I should consider to achieve my goal?
I want the response to pass through the proxy so that I can assert my tests at run time. Please help/suggest.
U can try burp proxy or Charles proxy to sniff the requests through the mobile
I was able to do this using FiddlerCore library. A lot of usage documentation can be found here: Rick Stahl's web log
Configured fiddlerCore to constantly listen on port 8888 and loop back address and starts running when my test is started and interecepts the traffic going to or coming from the server.

Creating webplugins

I am trying to create a program that will be passed input data from events a user fires from a webpage on their browser. I am aiming at google-chrome currently with the program being in either java or C#. I know this is possible because Spotify does this, so does the Battlefield 3 PC gui. How can I go about doing this? Does the user need to install an extension or can I get that information straight from google-chrome? Note: The webpage is not being run on localhost.
You're going to want to look into web sockets. Web sockets are just cool. I got a huge grin on my face the first time I got demo working. :D
Here's a tutorial that helped me out:
http://www.developerfusion.com/article/143158/an-introduction-to-websockets/
You can create a socket listen in your appilcation then connect to it from javascript, passing whatever data you desire. It's nicer then ajax as it's a persistent open connection and you don't have the overhead of http calls.

Control Internet connection data

I want to control internet connection programmatically, (I use Visual Studio .net (C#)). I want to process all the requests that are sent to the internet.
For example, if a user on any browser type "google.com", I want to get this request before it's sent to the internet.
Simply, it's a process that Windows uses to send and retrieve data from a communication port, please do any one have a simple article that explain this process, also does any one have an idea how to control the data flow on communication ports using dot net.
You may want to check out how Fiddler, a transparent proxy that automatically adds itself to the WININET chain so that it can see every request being made, works.
According to this MSDN article:
...the program registers itself as the
system proxy for Microsoft Windows
Internet Services (WinInet), the HTTP
layer used by Internet Explorer,
Microsoft Office, and many other
products.
Additionally, take a look at the answers to this question - How to create a simple Proxy in C#.

Categories