Click here to Skip to main content
14,603,943 members
Rate this:
Please Sign up or sign in to vote.
Hello,

I know similar problems have been posted here before. I know this because I've searched this site for solutions, but the ones I've found haven't worked out for me.

I have a problem with the web browser control. Right now, it renders pages like an old version of Internet Explorer. I need it to render them as Microsoft Edge or Chrome would have. Some of the solutions I found to other people's versions of the same problem include inserting the HTML tag. That did not work for me.

The other solution, which seems to do the trick for a lot of people, is to create a value in the registry database with the name of your application (e.g. myApp.exe) and a integer value representing what Internet Explorer-version you want the web browser control to behave as - the decimal value 10001, apparently, being Edge and 8888 and 9999 being the most recent versions of Internet Explorer.

That's when I wrote this code, which still doesn't work. According to one website, whose url I'm going to provide, the JavaScript member document.documentMode should equal 11 for Edge when it works (that is, when the web browser control behaves as Edge due to the 10001 value in the registry database). Needless to say, here documentMode is set to 5, like it completely ignores the registry values I've set. I've created both relative and absolute paths to my EXE (a Visual Studio debug build) in both the 32-bit and 64-bit parts of regedit, and in both HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE. I wasn't allowed to touch the latter with C#. Running my app without administrator privileges threw an exception; with admin privileges it just ignored my attempt to create a value in HKEY_LOCAL_MACHINE.

This is the code I wrote:

public partial class MainForm : Form
{
	const string regValue32cu = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
	const string regValue64cu = @"HKEY_CURRENT_USER\Software\wow6432node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
	const string regValue32lm = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
	const string regValue64lm = @"HKEY_LOCAL_MACHINE\Software\wow6432node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";

	const uint value = 10001U;

	public MainForm()
	{
		InitializeComponent();
	}

	private void MainForm_Load(object sender, EventArgs e)
	{
		Microsoft.Win32.Registry.SetValue(
			regValue64cu,
			@"C:\Users\Thomas\source\C#\regedit\bin\Debug\YouseeLoader.exe",
			value,
			Microsoft.Win32.RegistryValueKind.DWord);

		Microsoft.Win32.Registry.SetValue(
			regValue64cu,
			@"YouseeLoader.exe",
			value,
			Microsoft.Win32.RegistryValueKind.DWord);

		browser.DocumentText = "<script>document.write('Document Mode: ' + document.documentMode);</script>";
		//browser.Navigate("https://tv.yousee.dk/tv-guide");
	}
}


What am I doing wrong? My exe is called YouseeLoader.exe. It is not a part of the PATH environment variable. The goal of my app is to be able to extract the part of https://tv.yousee.dk/tv-guide[^] that is being inserted in the <div id="mount"></div> element in Edge and Chrome, but not in older versions of Internet Explorer, but for now, I just want the web browser control to render properly like Edge and Chrome.

Thank you in advance,
- Thomas

What I have tried:

Controlling WebBrowser Control Compatibility | Microsoft Docs[^] (article using document.documentMode with pictures)

internet explorer 8 - How to set FEATURE_BROWSER_EMULATION to IE8 mode? - Stack Overflow[^] (32- and 64-bit registry keys)

Internet Feature Controls (B..C) (Internet Explorer) | Microsoft Docs[^] (MSDN article on browser emulation and value description)
Posted
Updated 23-Jan-20 4:45am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Those appear to be the correct registry keys and values:
Web Browser Control & Specifying the IE Version - Rick Strahl's Web Log[^]

I suspect the MainForm_Load event is too late to set them; the control will already have been initialized by this point. You could try updating the registry from your Main method instead.

You'll also need to load a standards-compliant document, to prevent the control from switching back to quirks mode. Try adding a doctype to the start of your document.
browser.DocumentText = "<!DOCTYPE html><script>document.write('Document Mode: ' + document.documentMode);</script>";

Alternatively, you could switch to CefSharp[^] or Microsoft Edge WebView[^] - the latter only works in Windows 10.

Or there's a preview version of Microsoft Edge WebView 2[^] which uses the new Chromium-based Edge browser, but that requires a pre-release version of the browser.

NB: Confusingly, what's referred to as "edge" in the Internet Explorer document modes doesn't actually mean the new Microsoft Edge browser; it just means "the latest version of IE available".
   
Comments
deXo-fan 23-Jan-20 14:13pm
   
Actually, your html code (!DOCTYPE html ......) worked in that documentMode is now set to 11 when I specify ie=edge. But the page I want to render already has a tag, and still it doesn't work. Perhaps you could try it and see for yourself by navigating with the web browser control to tv.yousee.dk/tv-guide.

About MainForm_Load being too late: the thought crossed my mind at one point, but wouldn't it work from the second run and on of the application? I mean, if the registry values are set too late during the first run but saved and ready to be read during the second run, you'd think it would work as I've run my app many times.

But thank you for the quick response. It has to run on Windows 7 unfortunately, but I might take a look at CefShark.

Edit: Changing the value to 11000 worked instantly, it now sets document.documentMode to 11, and without the <!DOCTYPE> tag. But it still doesn't render the page quite right. There are much fewer script error popups than before, but it doesn't display the content that is being loaded with AJAX calls by the page. If you could try and get it to display the page right when you have the time I would really appreciate it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100