Skip to main content

How to disable Script Error in WPF


Symptoms-



  • while the application launch after the  3 min  expiry of session expired and  the script generate an error like this



Video Captured Result -Application Error Like-this

Code Fix-Result




Work Around-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScriptErrorSuppress
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            browser.Navigate("https://accounts.google.com/signup/v2/webcreateaccount?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default&dsh=S-1979057207%3A1569564750984034&gmb=exp&biz=false&flowName=GlifWebSignIn&flowEntry=SignUp");
            browser.Navigated += new NavigatedEventHandler(WebBrowser_Navigated);
        }
     
        void WebBrowser_Navigated(object sender, NavigationEventArgs e)
        {
            HideJsScriptErrors((WebBrowser)sender);
        }
        public void HideJsScriptErrors(WebBrowser wb)
        {
            // IWebBrowser2 interface
            // Exposes methods that are implemented by the WebBrowser control
            // Searches for the specified field, using the specified binding constraints.
            FieldInfo fInfo = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fInfo == null)
                return;
            object obj = fInfo.GetValue(wb);
            if (obj == null)
                return;
            // Silent: Sets or gets a value that indicates whether the object can display dialog boxes.
            // HRESULT IWebBrowser2::get_Silent(VARIANT_BOOL *pbSilent);HRESULT IWebBrowser2::put_Silent(VARIANT_BOOL bSilent);
            obj.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, obj, new object[] { true });
        }


    }
}




Comments

Popular posts from this blog

How to execute Python Script in PyCharm-Configuration

Compile a VBScript into an EXE – iExpress

Sometimes you need to compile a vbscript into an EXE. There are a few applications that allow you to do this, however there is one already installed on the windows build called  iExpress . Before using this, you need to make sure your script works and launches what it is supposed to. E.g. if it launches Internet Explorer with a specific URL. Go to start menu > run and type  iExpress  and press enter. Next > until you are on  Package title . Here enter a title for your exe. Next > No prompt.  Next > Do not display a license.  Next > Add –  Here you will browse to your vbscript .  Next > In the install program section, you need to point to cscript.exe as this is what will run your script. So enter  C:\Windows\System32\cscript.exe “enter vbscript here.vbs” .  Next > Hidden.  Next > No message.  Next > Here you will select where you want to save your EXE files. Then ...