How to intercept any open websocket with cefsharp winform?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to intercept any open websocket with cefsharp winform?

Postby fabiano1024 » Thu Apr 06, 2017 8:50 am

Hi all,

My question is how to intercept any previously open websocket with cefsharp (winform)?

Context:

I connect to a site where it transmit stock market information via WebSocket.

I would like to capture this information without going through a event listener in javascript which is both a heavy load for the processor.

The only track I had, is it to capture the headers via IRequestHandler. But I have no concrete example!

If however you have an example or advice to give me, this will help me considerably to finish my project.

Thank you in advance for your help ;)
fabiano1024
Newbie
 
Posts: 5
Joined: Thu Apr 06, 2017 8:27 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fddima » Thu Apr 06, 2017 10:06 am

Request handler currently handles only http-websocket handshake/connection upgrade, everything other (i.e. message tranafers) will remains inside.

This turns you that only JS is a way that currently available.

Capturing data via JS should not be much heavier than capturing same data via other mechanics.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fabiano1024 » Thu Apr 06, 2017 2:43 pm

Thank you for your reply.

For moment I try to scan all port that use my application and then the objective is to listen to everything that happens passing through this port with TcpListener, but now I have any problem to shared port (single use of each socket address)!

Do you have idea how to resolve this problem?

Sorry for my english ;)
fabiano1024
Newbie
 
Posts: 5
Joined: Thu Apr 06, 2017 8:27 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fddima » Thu Apr 06, 2017 3:40 pm

fabiano1024 wrote:Thank you for your reply.

For moment I try to scan all port that use my application and then the objective is to listen to everything that happens passing through this port with TcpListener, but now I have any problem to shared port (single use of each socket address)!

Do you have idea how to resolve this problem?

Sorry for my english ;)

It depends what you actually want achieve...

If you want to be man in middle for some reason - then you can use own proxy server for this purposes. This works for "private" infrastucture and/or for development purposes.

Then really simple, if you own page - then you can add message capturing from JS. There is simplest. You even can notify native side with any available JS integration mechanism.

If you not own page, you can override web sockets implementation in JS (from OnContextCreated) with simple proxy object which can also perform only monitoring stuff or intrusive changes in messages.

There is 3 common ways available just now without any CEF or Chromium patching.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fabiano1024 » Thu Apr 06, 2017 4:11 pm

Thanks again for your availability ;)

I will try the proxy solution with OnContextCreated via JS. Do you have any documentation, link or example for this case?

Thanks in advance.
fabiano1024
Newbie
 
Posts: 5
Joined: Thu Apr 06, 2017 8:27 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fddima » Thu Apr 06, 2017 7:28 pm

fabiano1024 wrote:Thanks again for your availability ;)

I will try the proxy solution with OnContextCreated via JS. Do you have any documentation, link or example for this case?

Thanks in advance.


No, i have no ready to use samples. If you unfamiliar with this CEF part, then start from CEF wiki, mostly from JavaScript Integration page. Basically from OnContextCreated you can prepare JS world as you need.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fabiano1024 » Fri Apr 07, 2017 9:19 am

If I use an ISchemeHandlerFactory I can register a scheme to intercept the ws and / or wss schemes?
fabiano1024
Newbie
 
Posts: 5
Joined: Thu Apr 06, 2017 8:27 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fddima » Fri Apr 07, 2017 9:28 am

fabiano1024 wrote:If I use an ISchemeHandlerFactory I can register a scheme to intercept the ws and / or wss schemes?

As i stated before, best that you can intercept is only handshake. So probably you should not intercept this to keep them working as expected (i.e. if you return own resource handler from scheme handler) it degrades to standard http request-reply and no connection upgrade will be maden.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: How to intercept any open websocket with cefsharp winfor

Postby fabiano1024 » Fri Apr 07, 2017 10:19 am

Ok, I will follow your advice in JS (from OnContextCreated).

Thank you so much for your help.

best regards
fabiano1024
Newbie
 
Posts: 5
Joined: Thu Apr 06, 2017 8:27 am


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 70 guests