cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.89k stars 2.92k forks source link

Websocket stop working on page after OnBeforeBrowse #1814

Closed rutony closed 8 years ago

rutony commented 8 years ago

WinForms + CefSharp 51.0.0

I have page with Websocket. Then I open any link in external browser. Page still worked fine. But websocket stop recieve any information, but have status Ok. What am I doing wrong?

    public class RequestHandler : IRequestHandler {
         bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)         {
            if (request.Url.ToString().ToLower() != new Uri(ProgramProps.dir_theme + @"\template.html").ToString().ToLower()
              && request.Url.ToString().ToLower() != new Uri("http://localhost:" + ProgramProps.port + @"/themes/" + ProgramProps.currentTheme + @"/template.html").ToString().ToLower()
              && request.Url != @"chrome-devtools://devtools/inspector.html") {
                Process.Start(request.Url.ToString());
                return true;
            } else {
                return false;
            }
         }

        CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) {               
            return CefReturnValue.Continue;
        }

        bool IRequestHandler.OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
            return false;
        }
        protected virtual bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
            return false;
        }
        bool IRequestHandler.OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) {
            return false;
        }
        void IRequestHandler.OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath) {
        }

        bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) {
            callback.Dispose();
            return false;
        }

        void IRequestHandler.OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status){
        }

        bool IRequestHandler.OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback) {
            return false;
        }

        void IRequestHandler.OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl) {
        }

        bool IRequestHandler.OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) {
            return url.StartsWith("mailto");
        }

        void IRequestHandler.OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) {
        }

        bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response){
            return false;
        }
        IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) {
            return null;
        }
        void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength){}            
    }
amaitland commented 8 years ago

How do I investigate my issue further?

It's important to remember that CefSharp is just a wrapper around the Chromium Embedded Project (CEF), the upstream CEF forum is a valuable resource. Also CEF has it's own Issue Tracker. Please take the time to research your own problem, including Googling, searching on ceforum, etc.

Finding more info

How do I download cefclient?

This next part is key

amaitland commented 8 years ago

What am I doing wrong?

return true will cancel your request, that maybe causing you a problem. Beyond that you'll have to do your own research, maybe ask on ceforum.

amaitland commented 8 years ago

We'd like to keep issues exclusively for bug reports, so please ask your questions on Gitter

https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md

rutony commented 8 years ago

I found that this is due to call onbeforeonload page. Another question is how to prevent onbeforeonload call, when I call OnBeforeBrowse?

amaitland commented 8 years ago

Ask on ceforum