Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket Handle (WSS) #2346

Closed
wurucu opened this issue Apr 5, 2018 · 5 comments
Closed

Websocket Handle (WSS) #2346

wurucu opened this issue Apr 5, 2018 · 5 comments

Comments

@wurucu
Copy link

wurucu commented Apr 5, 2018

How i can handle websocket ?
I need to send and receive packet from c# code behind.
Thank you. Sorry my english.

@welcome
Copy link

welcome bot commented Apr 5, 2018

Welcome! If you're reporting a bug, please make sure you have completed the bug report template see https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md#bug-report. Please make sure you provide enough detail that someone else can reproduce the issue you are experiencing.
We prefer to keep this issue track just for bug reports. If you have a question or need help with something I'd ask that you self close this issue and have a read over https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md it contains background information, details on where to ask your questions (hint, Gitter is one such place)
It's also reportant to remember that CefSharp is just a wrapper around the Chromium Embedded Framework(CEF), a lot of questions people have aren't actually CefSharp specific, they're generic to CEF and for those CEF has it's own support forum at http://magpcss.org/ceforum/index.php and issue tracker at https://bitbucket.org/chromiumembedded/cef

@amaitland
Copy link
Member

There is no specific functionality in CEF, see http://magpcss.org/ceforum/viewtopic.php?f=6&t=15034

This issue tracker is for bug reports only, thank you!

@sanjaykulkarni04
Copy link

sanjaykulkarni04 commented Mar 18, 2021

@amaitland OnBeforeResourceLoad unfortunately is not raised/called for WebSocket requests in custom ResourceRequestHandler. Can anyone please assist me? here is the sample code -

`private sealed class BearerAuthResourceRequestHandler : ResourceRequestHandler
{
readonly IAuthenticationCredentials credentials;

        public BearerAuthResourceRequestHandler(IAuthenticationCredentials credentials)
        {
            this.credentials = credentials;
        }

        protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
        {
            if (!string.IsNullOrEmpty(credentials.AccessToken))
            {
                var headers = request.Headers;
                headers["Authorization"] = $"Bearer {credentials.AccessToken}";
                request.Headers = headers;
                //request
                return CefReturnValue.Continue;
            }

            return base.OnBeforeResourceLoad(chromiumWebBrowser, browser, frame, request, callback);
        }
    }`

@amaitland
Copy link
Member

OnBeforeResourceLoad unfortunately is not raised/called for WebSocket requests in custom ResourceRequestHandler

Intercepting Websocket Requests is not currently supported via ResourceRequestHandler.

In theory you can access at least some of the WebSocket data via DevTools protocol.

https://chromedevtools.github.io/devtools-protocol/tot/Network/#event-webSocketClosed

This is not something I've tested, not do I have an example. Generic details on using DevTools directly are at #3165

@sanjaykulkarni04
Copy link

sanjaykulkarni04 commented Mar 18, 2021

Thank you @amaitland. Will see and try.

My requirement is, I would like to inject a token in the request header and pass the same to a web server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants