0

So I know about FEATURE_BROWSER_EMULATION, but either it isn't working for me, or it only controls the Browser Mode and not the Document Mode.

I have a lot of info specific to my case below, but the general question that I think/hope should have an easy answer that applies to lots of people is: How do I get the WebBrowser control to render exactly like whatever version of IE the user has installed? I think this comes down to control over the "Document Mode"


I'm trying to get the WebBrowser control to render HTML the same way IE10 does, without modifying the HTML (because that isn't robust). My app is an email client that displays HTML email, and here is what a typical email from GMail might look like:

<div dir="ltr"><div id="" team-id="21062" dir="ltr"><div id="email-body-container" style="width:96%; padding:0; margin:2%; border:solid 1px #E7E7E7;">
  <div id="email-body-header" style="width:94%; padding:3% 3% 2% 3%; background-color:#f5f5f5; border-bottom:solid 1px #eaeaea;">
    <img src="http://www.google.com/adwords/htp/static/legacy/adwords_logo_grey_166x28.png" alt="Google AdWords" width="166" height="28" style="outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; display:block;">
  </div>
</div></div>

I have that exact HTML in a file named c:\test.htm, and I load it in IE by entering that in the address bar, and then I load it in the webbrowser control using Navigate("c:\\test.htm"), and they don't render the same.

I know it isn't valid HTML because it doesn't even include an html tag, body tag, etc, but this is how GMail does things and I have no control over that (or other weird stuff email clients do). The only thing I do know is that Internet Explorer always seems to display them nicely (probably most people test with IE, that's why). However, they don't display nicely in the WebBrowser control. Here is the above HTML in IE10 (Win8) and in a simple WinForms app using the WbeBrowser control:

enter image description here

The WinForms app has a scrollbar when one isn't needed, and also the border doesn't match the background color size. Using IE developer tools I can try every combination of Browser Mode (IE7 through IE10) and every combo of Document Mode (standards, quirks, IE7 - IE9 standards) and the only way I can get IE to render like the WebBrowser control is to set the Document Mode to "IE5 quirks". In which case it renders the same as the WebBrowser control even if Browser Mode is set to IE10.

I've set this registry value: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WindowsFormsApplication2.exe

I've tried setting it to 10000, 10001, 9999, 8888, 9000, and a few other values (decimal, not hex) and they have no effect on this issue. My EXE name is WindowsFormsApplication2.exe, and I've set my build to x64 and confirmed it is running as a 64-bit process, so that I don't have to worry about setting Wow6432Node instead (but I even tried setting that also).

So I'm thinking that only controls the Browser Mode, but not the Document Mode? I tried the obsolete FEATURE_NATIVE_DOCUMENT_MODE setting also, no change.

Note, I tagged this as TWebBrowser also because I originally found this issue using that, but since hardly anyone uses that I made sure I could recreate in a real simple .NET C# WinForms app.


Added May 17th:

Here is a reg export (I deleted everything under HKCU just to make sure it wasn't overriding anything in HKLM):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"prevhost.exe"=dword:00001f40
"HelpPane.exe"=dword:00002710
"sllauncher.exe"=dword:00001f40
"test.exe"=dword:00002710
"iexplore.exe"=dword:00002711
"windowsformsapplication2"=dword:00002710
"windowsformsapplication2.exe"=dword:00002710
"test"=dword:00002710

Here is what my "test.exe" looks like in Task Manager:

enter image description here

eselk
  • 6,764
  • 7
  • 60
  • 93
  • p.s.-Sorry for the long question, but I've spent several days on this and not sure where else to go for help or how to make the question shorter/better. – eselk May 15 '14 at 23:01
  • Interesting, if I rename my EXE to iexplore.exe it renders like IE. Don't think that is a solution for me though, that would be pretty virus-like if I was to rename my EXE like that, and a pain for our tech support dept. – eselk May 15 '14 at 23:23
  • So, what is the actual IE version, is it v11? If so, you could also try playing with the User Agent string: http://stackoverflow.com/a/19601064/1768303 – noseratio May 15 '14 at 23:56
  • IE10, I just want the WebBrowser control to do what I thought it would do, render the way whatever version of IE they have installed does. That's why I started using the control in the first place, ~10 years ago, and it used to render like IE5, but now they added all the compatibility/legacy stuff and I just want to turn it all off. – eselk May 16 '14 at 20:22
  • @eselk apparently, the values `0x2710` and `0x2711` are not identical. – stanleyxu2005 May 19 '14 at 08:49

1 Answers1

3

According to MSDN

10001 (0x2711)  Internet Explorer 10. Webpages are displayed in IE10 Standards 
                mode, regardless of the !DOCTYPE directive.

10000 (0x2710)  Internet Explorer 10. Webpages containing standards-based 
                !DOCTYPE directives are displayed in IE10 Standards mode. 
                Default value for Internet Explorer 10.

The MSIE on your machine uses 0x2711, which means it will always renders the document in standard mode. Your application uses 0x2710. As your test document does not have a !doctype, it will be rendered in Quirks mode. This is the root cause why the webpage looks differently.

Note that windowsformsapplication2.exe is a valid entry for Registry.

On Windows 7

Both MSIE and my app have a scrollbar there. Sorry, I have no idea how to make the scrollbar looks exactly the MSIE does yet. But I'm sure the look and feel of scrollbar has nothing to do with FEATURE_BROWSER_EMULATION

stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94
  • 1
    Well, that gives me hope anyway. I added a reg export and a task manager screen shot to the bottom of my question. Do you see anything wrong? It does look like you are on Win7, I wonder if this no longer works on Win8. – eselk May 18 '14 at 01:43
  • 1
    @eselk I tried it on Windows 8. If you add ` ` at the beginning of the test document, both MSIE and my application render well. Otherwise both browser render unexpectedly. – stanleyxu2005 May 18 '14 at 09:12
  • 1
    It is probably something silly like this, and since it works for you (and I assume others since no other answers/comments), I'm going to assume for now this is the answer. I'm pretty sure I tried both 10001 and 10000 for my EXE, and also was seeing the same thing before I added iexplore.exe to the registry. Sadly I've been put on another project for the next few weeks, but hopefully I can come back and update this when I get back to it. – eselk May 21 '14 at 22:54