tags:

views:

928

answers:

4

I have a WPF application that uses the WPF WebBrowser control to display interesting web pages to our developers on a flatscreen display (like a news feed).

The trouble is that I occasionally get a HTML script error that pops up a nasty IE error message asking if I would like to "stop running scripts on this page". Is there a way to suppress this error checking?

NOTE: I have disabled script debugging in IE settings already.

A: 

The problem here is that the WPF WebBrowser did not implement this property as in the 2.0 control.

Your best bet is to use a WindowsFormsHost in your WPF application and use the 2.0's WebBrowser property: SuppressScriptErrors. Even then, you will need the application to be full trust in order to do this.

Not what one would call ideal, but it's pretty much the only option currently.

Kyle Rozendo
A: 

Hi Kyle,

I know your answer is a few months old ;) but I hope you still note my additional question on this topic.

I also really need to suppress script errors (and any other messagebox that is opened by the webpage) in my WPF application. It works fine when unsing WinForms and setting SuppressScriptErrors to true - but of course not in WPF.

Now, I used a WindowsFormsHost, placed a WinForms Webbrowser control in it and set the SuppressScriptErrors to true. As far as I know when running a WPF app directly out of Visual Studio, it will be executed with full trust.

But, unfortunately, messageboxes opened by the website still pop up. I also tried to sign my assembly with a test certificate as signed assemblies should always gain full trust ... but still nothing. I can set the property to true, but it still seems to have no effect at all.

As it seems you really know what you are talking about :) ... have you any other idea what could be going wrong here?

Would really appreciate your feedback, I really don't want to throw away all the work I have done on the WPF client and switch back to WinForms because of this problem.

Thank you! b.

Bernhard König
A: 

Here is a solution i just made with reflection. Solves the issue :) I run it at the Navigated event, as it seems the activeX object is not available until then.

What it does it set the .Silent property on the underlying activeX object. Which is the same as the .ScriptErrorsSuppressed property which is the Windows forms equivalent.

 public void HideScriptErrors(WebBrowser wb, bool Hide) {
    FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
    if (fiComWebBrowser == null) return;
    object objComWebBrowser = fiComWebBrowser.GetValue(wb);
    if (objComWebBrowser == null) return;
    objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { Hide });
 }
Wolf5
A: 

I've this problem in the past and finally resolved it with an injection of a Javascript script that suppress error handling. Hope this could help you too.

Disable Javascript errors in WEbBrowsercontrol

Alkampfer