Monday, February 10, 2014

WPF - Supressing Script Errors in WPF WebBrowser control

When Web sites hosted in Webbrowser controls are throwing JScript errors then we have to hide them. WebBrowser controls don't have the property to hide script errors so we have to handle it explicitly or we have to use WinForms WebBrowser control.
 
For the first approach we can use the below method in the browsers navigated event.

private void HideScriptErrors(WebBrowser webBrowser, bool hide)
{FieldInfo fieldInfo = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null)
return;
object objectWebBrowser = fieldInfo.GetValue(webBrowser);
if (objectWebBrowser == null)
return;
objectWebBrowser.GetType().InvokeMember("silent", BindingFlags.SetProperty, null, objectWebBrowser, new object[] { hide });
}

You can look at the original post here.

This worked for me. Hope it will for you as well !!! :)

No comments:

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...