.NET bindings - websocket request handling

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

.NET bindings - websocket request handling

Postby sanjaykulkarni04 » Thu Mar 18, 2021 5:26 am

Hi,

I am using .NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework(https://github.com/cefsharp/CefSharp). Unfortunately OnBeforeResourceLoad is not being raised/called for WebSocket requests in custom RequestHandler. Can someone please assist me? Here is the sample code -

Code: Select all
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;
                return CefReturnValue.Continue;
            }

            return base.OnBeforeResourceLoad(chromiumWebBrowser, browser, frame, request, callback);
        }
    }
sanjaykulkarni04
Newbie
 
Posts: 1
Joined: Thu Jun 18, 2020 7:36 am

Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 1 guest