How to hide HTMLViewer page errors?

How to hide the HTMLViewer page errors?
When I load web pages, sometimes errors are generated. These errors are displayed with pop-ups that block the execution.
I need to hide the popup errors and the program continues to run.

In a browser, you could disable JavaScript.

In HTMLViewer, you could replace all tags with comments tags <!— and —>, respectively.

That can be achieved with ExecuteJavaScript.

This could work (untested):

dim js as string js = js + "var str = document; var res = str.replace(/<script>/gi, '<!---'); document = res; " js = js + "var str = document; var res = str.replace(/<script>/gi, '--->'); document = res;" HTMLViewer1.ExecuteJavaScript(js)

Of course, disabling scripts is kind of a hammer to swat a fly. It may impair the page.

Follow up. I had a few minutes to test the code. Placed in the DocumentComplete event, it very effectively suppresses JavaScript, including JavaScript errors, but also those pesky boxes, like “subscribe now” in some websites.

On Windows, using the native HTMLVIewer, you can do this:

  #if TargetWindows
     Me._ole.Content.Silent = True  ' prevent JavaScript Error popup