Handle dialog message from WPF's Webbrowser programmatically?

1

I have a WPF application that displays 3 websites with 3 separate webbrowser controls. I have no control over the websites, they are 3rd party. Two of them I manipulate the DOM to only show the elements my client is interested in. And the third I log into it and manipulate the DOM to show specific graphs. Currently this all works autonomously and acts as a sort of display only kiosk.

However, on occasion one of the sites will have some JavaScript issue that will prompt the browser to display the message "Stop running this script? A script on this page is causing your web browser to run slowly. If it continues to run, your computer might become unresponsive" With a choice of Yes/No. Either would be fine as the page is refreshed on an interval. (One hour)

Because there is no user interaction, how do I handle this message? I can't find an event that fires either.

I have implemented the silent mode for the ActiveX control. It works great for suppressing other messages. Just not this one.

I have edited the registry to cause the webcontrols to act as IE11. That made the pages look nicer, but did not prevent the issue.

The issue does not happen immediately, nor is it predictable or inducable. I have logged the websites memory usage with Chrome's tools. There is no leak, until something happens and I get the message. So I figure some event that the 3rd party JavaScript handles fails suddenly.

I've tried logging on the application, but its not an application error until the browser can't reload the page because the dialog is blocking action. This blocking action is what is causing the application to fail. So I would like to handle this dialog message to prevent the exception or handle the exception better. Although my preference is to handle the message.

--Edit to add: TO be more clear the message in question looks like the one here: https://superuser.com/questions/408886/stop-running-this-script-is-this-legit

and not the one featured here: https://www-01.ibm.com/support/docview.wss?uid=swg21680774

The exception message looks like this:

The requested resource is in use. (Exception from HRESULT: 0x800700AA)e.Exception.Message.
   at MS.Win32.UnsafeNativeMethods.IWebBrowser2.Navigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
   at System.Windows.Controls.WebBrowser.DoNavigate(Uri source, Object& targetFrameName, Object& postData, Object& headers, Boolean ignoreEscaping)
   at TVdisplay.MainWindow.reload_bi(Object sender, EventArgs e) in C:\Users\...\MainWindow.xaml.cs:line 201

I have try blocks wrapped around code ran when I manipulate the DOM. It has not caused an exception yet. Only when I am trying to Navigate with (I presume) is the webbrowser control with the shortest timer to refreash.

private void reload_bi(object sender, EventArgs e)
{
    try
    {                
        webbrowser.Navigate("http://somewebsite.com"); //line 201
    }
    catch (Exception error)
    {
        logThoseErrors(DateTime.Now.ToString());
        logThoseErrors(error.Message.ToString());
        logThoseErrors(error.StackTrace.ToString());                
    }          
}

Thanks

c#
wpf
webbrowser-control
asked on Stack Overflow Apr 24, 2019 by David.S.B • edited Apr 25, 2019 by David.S.B

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0