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?





Awesomium is pretty outdated. Better use a more modern alternative like for example CefSharp.
– Sjoerd222888
Aug 16 at 13:32




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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)