Web browser control continues script execution without script error warning window

I need to call a third-party CRM system. There are some problems in their javascript code, but the webpage is functioning correctly in IE9.

If I have ScriptErrorsSuppressed set to false, I will get the error message “There was an error in this script on this page,” and below it, “Do you want to continue running scripts on this page?”

If I click "Yes", the web page will work correctly, "No" on the other hand will not correctly connect jquery with objects.

If I set ScriptErrorsSuppressed to true, the error message will not appear, however this will stop the script from executing and the web page will not work correctly.

IE9 may display script errors, but continue to execute the script. Is there a way to emulate the same behavior?

  • I tried all the solutions used in stack overflow, but they stop script execution
  • Web browser control works in IE9 mode, I set the registry value to force IE9

Thank. -Maigais

+4
source share
1 answer

We have almost the same tasks. I tried everything, including WebBrowser.ScriptErrorsSuppressed = true. And that was not what I was looking for because all JavaScripts stopped working after an exception occurred. But the following worked for me:

    public PageWithWebBrowser()
    {
            WebBrowser.DocumentCompleted += OnWebBrowserDocumentCompleted;
            WebBrowser.Navigate("http://www.example.com");             
    }

    private void OnWebBrowserDocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
            WebBrowser.Document.Window.Error += OnWebBrowserDocumentWindowError;
    }

    private void OnWebBrowserDocumentWindowError(object sender, System.Windows.Forms.HtmlElementErrorEventArgs e)
    {
            //Suppresses a dialog and continues running scripts on the page
            e.Handled = true;
    }

, System.Windows.Forms.WebBrowser, , WPF WebBrowser.

, .

-1

Source: https://habr.com/ru/post/1535686/


All Articles