7

I have a simple program, and I am trying to load the kongregate chat into a WebBrowser, but it is not working...

When I first start it up, it navigates to a game, and then it gives me 4 Script Error, and the chat just sits there saying: "Joining room...". I don't think it is a problem with the browser settings, because it works on internet explorer. Is there something that is messed up with my WebBrowser? I have let it sit there for a few minutes, and it still does not work. I have set the suppressScriptErrors to true and false, and it still does not fix it.

FYI: I am not doing anything bad with my program, like cheating, or spamming, or anything like that, I just want the webpage to show up, and sometimes I like to be able to have things copied, so I put a few TextBoxes to the right of it, so I can paste it into chat, if I won't to post a few things...

Dozer789
  • 1,980
  • 2
  • 23
  • 43
  • I'm not aware of Kongregate internals, but could it be that the WebBrowser doesn't accept cookies while IE does, and that cookies are critical to this chat ? – C4stor Dec 10 '13 at 16:18
  • I think they do, but I am not sure about whether or not they do or don't. Is there any way to accept cookies in `WebBrowser`? – Dozer789 Dec 10 '13 at 19:10
  • After looking a bit more, it looks like the WebBrowser component is actually spawning an IE process, so it should behave all the same. Sorry for the mislead, I'm actually pretty curious of what's happening here :D – C4stor Dec 11 '13 at 10:26
  • 4
    how are you trying to access the chat? some code would be helpful – Lorentz Vedeler Dec 12 '13 at 20:00
  • Show some code, please. Unless we know what is causing the error, there is (almost) no way anyone could possibly help you. – AJMansfield Dec 16 '13 at 17:14
  • Start Fiddler2 and watch, what's happens. And could you show how you load a chat? – Dima Kurilo Dec 16 '13 at 17:42
  • I am accessing it from the way you would access it if you were accessing it if you were loading it in internet explorer or chrome. – Dozer789 Dec 17 '13 at 16:35
  • I discovered how to fix my problem with WebKitBrowser. I would like to post that answer as the other persons answer does not fix my problem, could this question please be re-opened. – Dozer789 Jan 17 '14 at 14:25

1 Answers1

-1

This article has the solution to your problem. It appears that the WebBrowser control in Visual Studio launches in IE7 mode by default. That's why you get javescript errors with the control but, not in your browser. I highly suggest you read the article linked that the top. Luckily, there is a fix. The following code was taken from another stackoverflow answer to a question that indirectly addresses your issue. Here is that link, and here is the code.

    string installkey = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
    string entryLabel = Path.GetFileName(Application.ExecutablePath);
    System.OperatingSystem osInfo = System.Environment.OSVersion;

    string version = osInfo.Version.Major.ToString() + '.' + osInfo.Version.Minor.ToString();
    uint editFlag = (uint)((version == "6.2") ? 0x2710 : 0x2328); // 6.2 = Windows 8 and therefore IE10

    RegistryKey existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, false); // readonly key

    if (existingSubKey == null) {
        existingSubKey = Registry.LocalMachine.CreateSubKey(installkey, RegistryKeyPermissionCheck.Default); // readonly key
    }

    if (existingSubKey.GetValue(entryLabel) == null) {
        existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, true); // writable key
        existingSubKey.SetValue(entryLabel, unchecked((int)editFlag), RegistryValueKind.DWord);
    }

Also, the article I mentioned up top says that you should create an entry for the VS host process for your app too or it won't work in debug mode. Good luck and I hope this solves your issue!

Community
  • 1
  • 1
drankin2112
  • 4,715
  • 1
  • 15
  • 20
  • I put that code in, but it is giving me a lot of errors. Where exactly is that code supposed to go? – Dozer789 Dec 17 '13 at 15:44
  • Also, I'm using windows 7, not 8, so what should the version be? – Dozer789 Dec 17 '13 at 15:44
  • you could put it in the constructor of your main form. also, the existing code covers IE 9 and 10 so you should be fine as is. BTW, this is not my code, I just coped it from the second link. It seems to have solved the problem for a lot of people. Also, once you put it in, use WebBrowser.ScriptErrorsSuppressed = true because that's also probably set in your browser properties. – drankin2112 Dec 17 '13 at 16:16
  • This is what my code looks like. It is giving me a lot of errors, what is wrong? http://prntscr.com/2bwe5d – Dozer789 Dec 17 '13 at 18:49
  • It still gives me errors. – Dozer789 Dec 17 '13 at 20:03
  • Error meaning it won't compile still? Did some of the red lines go away? What is still underlined? – drankin2112 Dec 17 '13 at 20:14
  • @Dozer789 See the updated code. It creates the registry key if it doesn't exist. Also, put the code inside the function! – drankin2112 Dec 17 '13 at 20:26
  • I didn't realize that the code needed to be inside the function. It compiles fine, but I still get javascript errors. – Dozer789 Dec 17 '13 at 20:47
  • Did you use `webBrowser.ScriptErrorsSuppressed` = true? Also, did you add entry for `AutoPostBot.vshost.exe` ? – drankin2112 Dec 17 '13 at 20:50
  • What do you mean "add entry"? – Dozer789 Dec 17 '13 at 23:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43379/discussion-between-drankin2112-and-dozer789) – drankin2112 Dec 17 '13 at 23:00
  • Well, he totally stopped helping me as soon as he got the bounty... It turns out that I needed to use WebKitBrowser to get it to work. – Dozer789 Jan 17 '14 at 14:23