Url Load Error Event Handler

1,791 views
Skip to first unread message

awsmith

unread,
Sep 18, 2012, 3:58:30 PM9/18/12
to cefs...@googlegroups.com
At some of our customer's locations, their networks are fairly unreliable.  (understatement)  I've been looking for some example code on how to add an event handler in my c# code so that I can throw a pretty error screen for things like network connection timeouts when CefSharp cannot load a page for whatever reason.  Would love a few (code-related) suggestions...

Thanks,
Alex  

Jack O'Connor

unread,
Sep 18, 2012, 5:37:18 PM9/18/12
to cefs...@googlegroups.com
On your WebView, you can set a LoadHandler object which implements ILoadHandler. That interface is just one method, OnLoadError, which is exactly what you want. Once you've set the LoadHandler, it will get called for things like network timeouts, and you can do whatever you want at that point. (For example, you can have the browser Load an HTML string containing an error message.)

Note that server errors are handled differently. If the server returns e.g. Error 500, that isn't a load error. To catch those, you would need to implement OnResourceResponse as part of the IRequestHandler interface, and then look at the status codes it returns. If you do this, you will probably want to distinguish between errors in your actual pageload and errors in the resources your page fetches (images, stylesheets, etc.). Unfortunately, the only way to tell which is which is by the URL, which you might need to catch in OnBeforeBrowse or something. I'm curious if others have found a good way to solve this problem.

--
You received this message because you are subscribed to the Google Groups "CefSharp" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cefsharp/-/raF0U-u9HOoJ.
To post to this group, send email to cefs...@googlegroups.com.
To unsubscribe from this group, send email to cefsharp+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cefsharp?hl=en.

Czarek Tomczak

unread,
Sep 19, 2012, 2:24:39 AM9/19/12
to cefs...@googlegroups.com
Jack, how about creating an issue in CEF issue tracker, http://code.google.com/p/chromiumembedded/issues/list , to add a new parameter to OnResourceResponse called isPageload or isNavigation? Maybe it's an easy fix for Marshall, at least we will know. I haven't yet played with this method (but I plan to), so better for you to report this.

Czarek.

Jack O'Connor

unread,
Sep 21, 2012, 7:40:12 PM9/21/12
to cefs...@googlegroups.com
I just started a thread in the CEF forum, on the off chance that there's a good solution for this that I don't know about.

To view this discussion on the web visit https://groups.google.com/d/msg/cefsharp/-/19cSyIVPqS4J.
Reply all
Reply to author
Forward
0 new messages