Catch network errors using Awesomium
Catch network errors using Awesomium
I am creating a headless browser using Awesomium. I want the browser to return Network Error codes, so I know how/why it's breaking.
using (WebSession session = WebCore.CreateWebSession(new WebPreferences() CustomCSS = "::-webkit-scrollbar visibility: hidden; " ))
using (WebView browserTab = WebCore.CreateWebView(1100, 600, session))
Console.WriteLine($"Starting WebCore vWebCore.Version");
BadExample(browserTab, baseURL);
static void BadExample(WebView browser, Uri url)
browser.Source = (url + "/anyhing").ToUri();
browser.LoadingFrameComplete += (sender, returnFrame) =>
//NetError Code
;
How do I use enum NetError to return the values I want?
1 Answer
1
You should subscribe to event IWebView.LoadingFrameFailed
(browser in your case).
IWebView.LoadingFrameFailed
As long as there can be many frames on a page, the event will fire for every frame. Below is a snippet that I use in my project.
private void ViewOnLoadingFrameFailed(object sender, LoadingFrameFailedEventArgs e)
if (e.IsMainFrame)
var error = (NetError) e.ErrorCode;
Logger.ErrorFormat("main frame loading failed: 0-1", e.ErrorCode, e.ErrorDescription);
else
Logger.WarnFormat("frame #0 loading failed: 1 - 2", e.FrameId, e.ErrorCode, e.ErrorDescription);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Awesomium is pretty outdated. Better use a more modern alternative like for example CefSharp.
– Sjoerd222888
Aug 16 at 13:32