0

I have a WPF application that uses the WPF WebBrowser control to display an online game. The trouble is that I keep getting the same script error and it's annoying. I have tried adding a REG_DWORD in the register changing the browser emulation version of Visual Studio but it keeps appearing. I'm using this class:

public class InternetExplorerBrowserEmulation
{
    private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer";
    private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION";


    public static int GetInternetExplorerMajorVersion()
    {
        int result;

        result = 0;

        try
        {
            RegistryKey key;

            key = Registry.LocalMachine.OpenSubKey(InternetExplorerRootKey);

            if (key != null)
            {
                object value;

                value = key.GetValue("svcVersion", null) ?? key.GetValue("Version", null);

                if (value != null)
                {
                    string version;
                    int separator;

                    version = value.ToString();
                    separator = version.IndexOf('.');
                    if (separator != -1)
                    {
                        int.TryParse(version.Substring(0, separator), out result);
                    }
                }
            }
        }
        catch (SecurityException)
        {
            // The user does not have the permissions required to read from the registry key.
        }
        catch (UnauthorizedAccessException)
        {
            // The user does not have the necessary registry rights.
        }

        return result;
    }

    public static bool SetBrowserEmulationVersion(BrowserEmulationVersion browserEmulationVersion)
    {
        bool result;

        result = false;

        try
        {
            RegistryKey key;

            key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true);

            if (key != null)
            {
                string programName;

                programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);

                if (browserEmulationVersion != BrowserEmulationVersion.Default)
                {
                    // if it's a valid value, update or create the value
                    key.SetValue(programName, (int)browserEmulationVersion, RegistryValueKind.DWord);
                }
                else
                {
                    // otherwise, remove the existing value
                    key.DeleteValue(programName, false);
                }

                result = true;
            }
        }
        catch (SecurityException)
        {
            // The user does not have the permissions required to read from the registry key.
        }
        catch (UnauthorizedAccessException)
        {
            // The user does not have the necessary registry rights.
        }

        return result;
    }

    public static bool SetBrowserEmulationVersion()
    {
        int ieVersion;
        BrowserEmulationVersion emulationCode;

        ieVersion = GetInternetExplorerMajorVersion();

        if (ieVersion >= 11)
        {
            emulationCode = BrowserEmulationVersion.Version11;
        }
        else
        {
            switch (ieVersion)
            {
                case 10:
                    emulationCode = BrowserEmulationVersion.Version10;
                    break;
                case 9:
                    emulationCode = BrowserEmulationVersion.Version9;
                    break;
                case 8:
                    emulationCode = BrowserEmulationVersion.Version8;
                    break;
                default:
                    emulationCode = BrowserEmulationVersion.Version7;
                    break;
            }
        }

        return SetBrowserEmulationVersion(emulationCode);
    }

    public static BrowserEmulationVersion GetBrowserEmulationVersion()
    {
        BrowserEmulationVersion result;

        result = BrowserEmulationVersion.Default;

        try
        {
            RegistryKey key;

            key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true);
            if (key != null)
            {
                string programName;
                object value;

                programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
                value = key.GetValue(programName, null);

                if (value != null)
                {
                    result = (BrowserEmulationVersion)Convert.ToInt32(value);
                }
            }
        }
        catch (SecurityException)
        {
            // The user does not have the permissions required to read from the registry key.
        }
        catch (UnauthorizedAccessException)
        {
            // The user does not have the necessary registry rights.
        }

        return result;
    }


    public static bool IsBrowserEmulationSet()
    {
        return GetBrowserEmulationVersion() != BrowserEmulationVersion.Default;
    }
}

I think it's something about the security of the game and I need to install a certificate but I'm not sure. Thanks in advice

Andrea
  • 3
  • 5
  • Did you try this? https://stackoverflow.com/questions/6138199/wpf-webbrowser-control-how-to-supress-script-errors – mm8 Jun 05 '17 at 12:12
  • Yes I tried and it seems to work, but the problem is that when the game is about to loading the webbrowser keeps refreshing and the game can't load – Andrea Jun 05 '17 at 12:29
  • What error messages are you seeing? – JWP Jun 05 '17 at 13:26
  • "The objects doesn't support propriety or method 'on'", then "Script error", again "Script error", "Expected identifier, string or number", and so on for 3 times, and then if I accept every time it logs on the game – Andrea Jun 05 '17 at 14:38

0 Answers0