How to hide HTMLViewer page errors?

  1. 3 months ago
    Edited 3 months ago

    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 <script></script> tags with comments tags <!--- and --->, respectively.

    https://www.w3schools.com/jsref/jsref_replace.asp

    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.

  2. Michel B

    Jun 4 Pre-Release Testers, Xojo Pro Answer RubberViews.com

    In a browser, you could disable JavaScript.

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

    https://www.w3schools.com/jsref/jsref_replace.asp

    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.

  3. Michel B

    Jun 4 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 3 months ago

    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.

  4. Michael D

    Jun 4 Pre-Release Testers, Xojo Pro
    Edited 3 months ago

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

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

or Sign Up to reply!