12

Seriously - read the question all the way through before attempting to answer it. "Use a different browser" doesn't answer this question.

The question is this: How do I get a System.Windows.Forms.WebBrowser control to display a web page that has Javascript embedded in it when I have no control over the incoming page? I've already seen people suggest adding registry values for IE emulation (Allowing javascript to run on a windows form web browser) and altering the script settings in Internet Options/Security. Internet security options

I've done that already.

So, here's the test - use a System.Windows.Forms.WebBrowser control to access www.hulu.com.
Still getting this

And we're still getting this.

Any other ideas?

Community
  • 1
  • 1
rlranft
  • 162
  • 1
  • 1
  • 12
  • 3
    You don't need to use a different control. You need to tell `WebBrowser` control to don't use compatibility mode and use the latest version of IE document mode. Then it shows all modern contents well. Take a look at [this post](http://stackoverflow.com/a/38514446/3110834). – Reza Aghaei Dec 02 '16 at 00:21
  • 2
    Follow the instructions and you can see expected result in a Windows Forms application [like this](https://i.stack.imgur.com/cc2Vg.jpg). – Reza Aghaei Dec 02 '16 at 01:18
  • Yes. I did that. It did not work. – rlranft Dec 02 '16 at 15:28
  • 1
    Probably you didn't follow instructions correctly, read the linked post which I shared in the first comment carefully and don't forget to add yourapp.vshost.exe also. The only key which you need to change is here: `HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION `. The solution is not using another browser control. You can see the screenshot which I made from that site in WebBrowser control in the second comment. – Reza Aghaei Dec 02 '16 at 22:07
  • I've re-checked this three times - I followed those instructions precisely. Since it works with www.funimation.com and not www.hulu.com it's more likely that the installed version of IE on this system isn't compatible with something on Hulu's site. I'll have to check this on my home machine later (Win10 64 bit). – rlranft Dec 02 '16 at 22:53
  • What's the version of IE? Can you see the site when you open it directly in IE without using WebBrowserControl? – Reza Aghaei Dec 02 '16 at 22:53
  • To make sure if the settings will work for you, it's enough to try to browse the site in your OS IE browser, if it's showing correctly the settings will work, it it doesn't show correctly, you need to use a different browser control like CefSharp, for example for working with WhatsApp I was forced to use CefShapr, the site was not working in IE at all. – Reza Aghaei Dec 02 '16 at 23:05
  • Yes - Hulu.com and Funimation.com both work fine in I.E. but Hulu doesn't work in the control. – rlranft Dec 05 '16 at 15:06
  • So the problem description and the solution is exactly what I said. – Reza Aghaei Dec 05 '16 at 16:56
  • As I said earlier - "I followed those instructions precisely," - and "Since it works with www.funimation.com and not www.hulu.com it's more likely that the installed version of IE on this system isn't compatible with something on Hulu's site." Initially, those changes had no effect and then it "just fixed itself" after about three hours (while I was working on something else (maybe caching issue?). Also, Hulu.com and Funimation.com both worked in I.E. BEFORE the registry edits. – rlranft Dec 05 '16 at 18:12
  • When you see a site woks in IE in your OS, it means it will also work with `WebBrowser` control after changing settings. So your problem was caching or something like this. – Reza Aghaei Dec 05 '16 at 18:23
  • Using the info from @RezaAghaei, it worked like a charm. I did find though that i had to run the app a second time for it to read the registry entry again. Maybe add the entry before the form load is triggered. – Jakes Van Niekerk Dec 09 '20 at 11:19

3 Answers3

16

Set the property ScriptErrorsSuppressed of the WebBrowser control to true to suppress the JavaScript error message.


In order to allow the code on hulu.com to execute, you must run the Webbrowser control in a mode such that it runs with newer version features. This can only be done by setting registry entries.

See this question and the answers for details.


To specify: I have a demo application to open the hulu website with the embedded WebBrowser control named WindowsFormsApplication5.exe.

Without registry changes, I see a note by Hulu that JavaScript support is not enabled. When sniffing the network transfer with Fiddler, I see that the following request is sent to the Hulu server:

GET http://www.hulu.com/ HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: de-DE,de;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Creative AutoUpdate v1.41.09)
Host: www.hulu.com
Connection: Keep-Alive
Pragma: no-cache

Note the version number "7.0" in the User-Agent string.

I now add a registry key of type REG_DWORD with name "WindowsFormsApplication5.exe" and value 0x00002af9 (11001) in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION.

As a result, the Hulu Website is successfully displayed in my demo application and I see the following request being sent via Fiddler:

GET http://www.hulu.com/ HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer: http://www.hulu.com/
Accept-Language: de-DE,de;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: www.hulu.com
Connection: Keep-Alive

Notice the different User-Agent string after the registry changes.


Registry setting to use IE 11 in WebBrowser Control in Demo Application

Demo Application showing Hulu Website after registry changes

Community
  • 1
  • 1
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • This doesn't fix operability of sites that require Javascript. It's just hiding the error messages. – Xavier J Dec 01 '16 at 23:54
  • Your extended answer still doesn't work for me. I have updated the values for my application in HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION, HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION, and HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION. I still get the "your software is blocking javascript" message – rlranft Dec 02 '16 at 16:23
  • This method fails for me on 64 bit Windows 7 and 64 bit Windows 10. – rlranft Dec 02 '16 at 16:44
  • @rlranft Do NOT use the path with Wow6432Node! My test was in Windows 10 64bit. – NineBerry Dec 02 '16 at 16:53
  • Okay, I take it all back. This is working for www.funimation.com but not www.hulu.com for me where both were failing to load before. Thanks. – rlranft Dec 02 '16 at 16:59
  • Works for hulu.com as well over here and there is no reason why it shouldn't work when doing everything correctly. – NineBerry Dec 02 '16 at 17:39
  • Never fear - I only used the Wow6432Node keys on 64 bit systems.... Define "doing everything correctly" here - I'll have to wait until later to verify this on Win10 and I'm on Win7 at work (all 64 bit - I don't think I'll need to run this on 32 bit anything). – rlranft Dec 02 '16 at 19:51
  • Or are you saying that, contrary to the instructions you linked, I should not use the Wow6432Node keys regardless of my system architecture? – rlranft Dec 02 '16 at 19:55
0

Possible approaches:

Community
  • 1
  • 1
Xavier J
  • 4,326
  • 1
  • 14
  • 25
  • 1
    1) Using a different browser defeats the purpose of the question.... 2) As I stated before " I've already seen people suggest adding registry values for IE emulation (Allowing javascript to run on a windows form web browser) and altering the script settings in Internet Options/Security." and "I've done that already." – rlranft Dec 01 '16 at 23:57
  • @rlranft The proposed registry changes in the question linked to in your question and the one I linked to work. Try them again. – NineBerry Dec 01 '16 at 23:59
  • "Try them again...?" What, do they disappear? I took those screenshots after applying those changes and restarting the machine in question. Those registry entries and settings are still active. – rlranft Dec 02 '16 at 00:02
  • The WebBrowser control does not "emulate" IE - it **IS** IE. which is why that went right past me. The WebBrowser control is an ugly stepchild of an ActiveX control that's been around since IE4 (yes, I've been doing this a long time). There are no ways to pull off what you're attempting to do beside registry changes, because Javascript is a security concern in certain environments (think high-security places such as military installations or nuclear power plants), and that's why MS left no options to programatically enable it. Hence my suggestion to try a different browser. – Xavier J Dec 02 '16 at 00:02
  • 1
    I'm also aware it doesn't "emulate" IE, and I also have been doing this for a few minutes - since summer of 1992, actually (ActiveX wasn't even a dream yet). The reason using another browser doesn't answer the question is because the question wasn't "what browser should I use to correctly handle web pages with javascript." – rlranft Dec 02 '16 at 00:10
  • 1
    You know what? I'm accepting this answer - which is basically "you can't." Thanks for the input, I actually appreciate it - and I hope Microsoft fixes their garbage soon. – rlranft Dec 02 '16 at 00:14
  • @rlranft Their approach with this is no different than the Java Runtime disclaimer (at installation time) to not use it in aircraft or similar facilities. In the case of an incident, the attorneys would pulverize Microsoft to bits over leaving such a gaping security hole in their base product (installed with Windows!). The Javascript on/off switch didn't come around til IE6 or so. Good luck. – Xavier J Dec 02 '16 at 00:18
  • @rlranft See my extended answer. The registry changes DO change how the embedded WebBrowser control works. I have used this before and now tested it again to confirm it works to Show the Hulu website. – NineBerry Dec 02 '16 at 00:20
  • 1
    @codenoir You don't need to use a different control. You need to tell `WebBrowser` control to don't use compatibility mode and use the latest version of IE document mode. Then it shows all modern contents well. Take a look at [this post](http://stackoverflow.com/a/38514446/3110834). – Reza Aghaei Dec 02 '16 at 00:26
  • @RezaAghaei if your system is configured to not run Javascript in IE, compatibility mode is not magically going to change that. Compatibility mode is for rendering HTML elements, and has nothing to do with Javascript. – Xavier J Dec 02 '16 at 00:37
  • Your system never is set to not run javascripts. In such cases you can see the site without any problem using Internet Explorer, but using WebBrowser Control you just receive errors and a broken rendered page. The problem is with showing modern content and running modern javascripts in WebBrowser control which is set to not use latest IE document mode by default. Just check the solution which I described in linked post. – Reza Aghaei Dec 02 '16 at 00:39
  • @RezaAghaei You are 100% wrong. You have apparently missed the mention of the entire 'Security Settings' dialog at the top of this question. This dialog has available on EVERY windows box for years, and can be accessed from Control Panel or inside IE. The default is to allow Javascript, but it CAN be turned off. Go to Control Panel, Internet Properties. Find the "Security" tab. Click "Custom Level". See? – Xavier J Dec 02 '16 at 00:44
  • The dialog which you see in the question is what the user tried to solve the problem which is obviously wrong solution. I know you can change security settings, but you don't need in 99% cases. Just pay attention to the script which is trying to run *http://cdn.optimizely.com/...*. Then you will know you don't need to change security settings. In most cases you will see the site is OK in IE11, but using WebBrowser control you can't see the site. – Reza Aghaei Dec 02 '16 at 00:48
  • You're answer is partially true, but I shared this comment and the linked post with you just to know what the problem is and how you can setup `WebBrowser` control to show modern contents. – Reza Aghaei Dec 02 '16 at 00:49
  • 1
    @RezaAghaei again, you're missing the context. The OP is writing an application to be installed in places where he may not have control of whether Javascript is turned on or off in IE, and was seeking a workaround. – Xavier J Dec 02 '16 at 00:50
  • 1
    If the site the control goes to doesn't need Javascript, then it's not a problem. – Xavier J Dec 02 '16 at 00:51
  • The user is trying to browse http://www.hulu.com . You can try to see the site in IE then in WebBrowser control. Then you will understand what I am talking about :) – Reza Aghaei Dec 02 '16 at 00:54
  • In those dialog screenshots, the user is telling while I have set all scripting features enabled, why I receive script errors. Did you get it? – Reza Aghaei Dec 02 '16 at 00:55
  • Did you get it? I tried what I said and I get expected result. Let me know if you had any problem applying the solution. – Reza Aghaei Dec 02 '16 at 01:13
0

Only add this line in the top

this.webBrowser1.ScriptErrorsSuppressed = true;
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103