C# Code Snippets  C# Code Snippets
 C# Code Snippets  C# Code Snippets
 C# Code Snippets  C# Code Snippets
 C# Code Snippets  C# Code Snippets

Saturday, December 22, 2007

How to Suppress / Disable Script Errors in WebBrowser Control

Hi all

I am currently writing an application that uses the WebBrowser control to perform operations on web pages. Unfortunately I stumbled upon a very annoying problem, sometimes an Internet explorer script error window pops up and stops all execution until you click the OK button. I've searched the web for hours and the same answer came up:

it's easy (so easy, yeah...) just do this:

WebBrowser.Silent = true;

the problem is that WebBrowser does not have a property named silent!!!!!! Maybe it did, but no more! if you don't believe me take a a look at the MSDN.

What you should do is use

WebBrowser.ScriptErrorsSuppressed = true;

which does exists...

Hope this helps some frustrated people (like me).

Happy holidays

Amit

AddThis Social Bookmark Button

17 comments:

Anonymous said...

"What you should do is use

WebBrowser.ScriptErrorsSuppressed = true;"
...but it makes things worse
Instead of Script Error Window, You got Visual Studio's debug window (twice per page)

Amit Raz said...

hey dave.
I am not getting this window but i will try and check it out for you

have a great weekend

Amit

Unknown said...

You will get it if you'll uncheck both "Disable Script debugging" in the IE advanced settings.

I'm still looking for a way to load html into mshtml object with webcontrol without popping up messages. If you know about a way to load ihtmldocument2 without using webcontrol, it would be great.

Assaf

Amit Raz said...

Why do you want it without the WebControl?

y said...

it really worked for me
nice work man
thanks alot

Anonymous said...

Thank god! this helped alot!
Love you and google!

Anonymous said...

Thank your very much. This is a main bug for my programe.

It can fix in 1 line ! It work.

Anonymous said...

wer do u add the peice of code?

Anonymous said...

I would imagine it would go in where your web browser code is, If your web browser is named "WebBrowser" Go to your code window and click on WebBrowser to expand it and then place that under the rest of the code in there. Hope im right!

john said...

Cool!

Murat Tunaboylu said...

You can try WatIn instead of web browser control. It is getting better and a good tool for aspnet integration tests.

Thanks for the post!

ghafoori said...

thanks a lot

Unknown said...

Thanks a lot +100 to your carma :)

Anonymous said...

reflector to the rescue:

FieldInfo fieldInfo = browser.GetType().GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);

dynamic activexObject = fieldInfo.GetValue(browser);

activexObject.Silent = true;


that works fine on my side (.net 4.0 for the dynamic part) otherwise cast approprietly

Anonymous said...

Keep in mind that using WebBrowser.ScriptErrorsSuppressed = true suppresses ALL message boxes for this WebBrowser control. that includes password entry dialogs.

Yasir said...

thanks a lot man.
it solved my problem.
nice work

Isuru said...

Thanks a lot. Saved me lot of time..Sharing is caring.. :)