3

I'm trying to load the Chromecast background website into a c# WebBrowser but am getting: enter image description here

I assumed it was happening because the webbrowser is using IE7 by default(?) which might not play well with the JS in the website. I tried to updated the registery FEATURE_BROWSER_EMULATION to 9000 hoping force the webbrowser to use IE9 framework. But I still get the same errors.

Is the webbrowser to basic for this task or is there a way around this problem?

EDIT:

So when I print the webbrowser.version I get: Version: 11.0.9600.16518. Which is the current version of IE I have. If I open IE11 and navigate to the url its works great. Not sure why the webbroswer is having an issue.

I tried to inject a JSON Parser into the webpage with this code:

HtmlDocument doc = webBrowser1.Document;
            Console.WriteLine(doc);
            HtmlElement head = doc.GetElementsByTagName("head")[0];
            HtmlElement s = doc.CreateElement("script");
            s.SetAttribute("type", "text/javascript");
            s.SetAttribute("src", "http://192.168.1.23:10000/JSON-js-master/json2.js");
            head.AppendChild(s);

I tried with local and external ips referencing the host file. Didn't seem the make a difference.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Nick
  • 9,285
  • 33
  • 104
  • 147
  • Wow, yeah I would say IE7 is too old! Can you use a different browser? – Mike Schwartz Mar 09 '14 at 18:02
  • When you updated the registry, you included the proper name of your process, right? http://msdn.microsoft.com/en-us/library/ee330730.aspx#browser_emulation – Brad Rem Mar 09 '14 at 18:06
  • The WebBrowser control _is_ IE. It is always the same version of IE that is running on your computer. Upgrade IE and you will be upgrading the control. Also, try the site by using the browser directly and see what happens. – John Saunders Mar 09 '14 at 18:34
  • @JohnSaunders, I just ran a WebBrowser control navigating to the page Nick linked to in his question and I get the same results as he does. Clicking on the link in IE is successful. Interestingly, putting IE in compatibility mode causes very similar problems that the WebBrowser generates. – Brad Rem Mar 09 '14 at 18:46
  • I put it in the registry for both 32bit and 64bit. Didn't seem to make a difference. I have IE11 installed on my computer now which as @BradRem said displays the page fine. So i'm at a loss why the `webbroswer` is having issues with the site. – Nick Mar 09 '14 at 19:06
  • IE's broswer emulation mode isn't reliable. I've seen things work during emulation that do not work on the real version – CSharper Mar 09 '14 at 19:08
  • @nick, can you inject the missing json into the WebBrowser control? Check this SO solution out which is essentially your problem: http://stackoverflow.com/a/17322464/1243316 – Brad Rem Mar 09 '14 at 19:18
  • @BradRem I tried the injection to no avail. I get the same errors. See the edit for what I did. – Nick Mar 09 '14 at 19:50
  • @BradRem: which version of IE are you using? If this happens with IE11, then his use of IE7 is a red herring. – John Saunders Mar 09 '14 at 19:53
  • @JohnSaunders, I am using IE11. I was really hoping injecting the json would have helped. – Brad Rem Mar 09 '14 at 20:09
  • First of all, you need to find out what is meant by "'JSON' is undefined". I suspect that some script did not load, so that the calling script is expecting a function named `JSON` or a variable named `JSON` and it is not defined. But searching for JSON parsers or worrying about compatibility is premature until you know what that error means. – John Saunders Mar 09 '14 at 20:14
  • 1
    @Nick, Because I have IE 11 installed, I set the browser emulation setting to 11001 and it works. – Brad Rem Mar 09 '14 at 20:42

1 Answers1

7

Apparently when the WebBrowser control runs, it runs in in the version of IE installed on the computer, but it runs in IE7 compatibility mode. Trying to load the link you listed requires a more modern browser. As a matter of fact, the page you requested needs IE10 or higher.

You do need to change the browser emulation settings in the registry so that the WebBrowser control users a more modern IE feature set:

Internet Feature Controls

As you already said in your question, the two areas in the registry that need to be adjusted are:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

In each of those two locations, the process name of your applications is included with a DWORD value set indicating the level of compatibility. The specific values are found on the Internet Feature Controls help page. The names of the file is the name of you application "MyApplication1.exe", or if you're running from within Visual Studio, it is "MyApplication1.vshost.exe".

Because I have IE 11 installed, I set the browser emulation setting to 11001 and it worked for your linked webpage.

Brad Rem
  • 6,036
  • 2
  • 25
  • 50