.Net Webbrowser Control not displaying accurately [duplicate] - c#

I recently upgraded to IE9-beta. Now, In my .Net (3.5) WinForm application I want to use WebBrowser control.
So my question is, whether the WebBrowser control will exhibit all properties and functions of IE9?
My concern is, I want to render some SVG graphics on it.

WebBrowser control will use whatever version of IE you have installed, but for compatibility reasons it will render pages in IE7 Standards mode by default.
If you want to take advantage of new IE9 features, you should add the meta tag <meta http-equiv="X-UA-Compatible" content="IE=9" > inside the <head> tag of your HTML page.
This meta tag must be added before any links to CSS, JavaScript files etc that are also in your <head> to work properly though (only other <meta> tags or the <title> tag can come before it).
An alternative is to add a registry entry to:
HKLM > SOFTWARE > Microsoft > Internet Explorer > Main > FeatureControl > FEATURE_BROWSER_EMULATION
And in there add 'myApplicationName.exe' with value '9000' to force the WebBrowser control to display pages in IE9 mode. Though there are other values you can use too too, note that these docs aren't entirely accurate as it does not seem possible to get a page to render in IE 8 mode whatever value you use.
Adding the registry key to the same path in HKCU instead of HKLM will also work - this is useful as writing to HKLM requires admin privileges where as HKCU does not.

The IE9 "version" of the WebBrowser control, like the IE8 version, is actually several browsers in one. Unlike the IE8 version, you do have a little more control over the rendering mode inside the page by changing the doctype. Of course, to change the browser mode you have to set your registry like the earlier answer. Here is a reg file fragment for FEATURE_BROWSER_EMULATION:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"contoso.exe"=dword:00002328
Here is the complete set of codes:
9999 (0x270F) - Internet Explorer 9.
Webpages are displayed in IE9
Standards mode, regardless of the
!DOCTYPE directive.
9000 (0x2328) - Internet Explorer 9. Webpages containing standards-based !DOCTYPE
directives are displayed in IE9 mode.
8888 (0x22B8) -Webpages are
displayed in IE8 Standards mode,
regardless of the !DOCTYPE directive.
8000 (0x1F40) - Webpages containing
standards-based !DOCTYPE directives
are displayed in IE8 mode.
7000 (0x1B58) - Webpages containing
standards-based !DOCTYPE directives
are displayed in IE7 Standards mode.
The full docs:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation

Thank goodness I found this. The following is extremely important:
<meta http-equiv="X-UA-Compatible" content="IE=9" >
Without this, none of the reports I'd been generating would work post IE9 install despite having worked great in IE8. They would show up properly in a web browser control, but there would be missing letters, jacked up white space, etc, when I called .Print(). They were just basic HTML that should be capable of being rendered even in Mosaic. heh Not sure why the IE7 compatibility mode was going haywire. Notably, you could .Print() the same page 5 times and have it be missing different letters each time. It would even carry over into PDF output, so it's definitely the browser.

A note about 64bit Windows which seems to trip up a few folks.
If your app is running under 64bit Windows, you likely have to set the DWORD under [HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] instead.

Just to be complete...
For 32 bit OS you must add a registry entry to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
*******OR*******
For 64 bit OS you must add a registry entry to:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
This entry must be a DWORD, with the name being the name of your executable, that hosts the Webbrowser control; i.e.:
myappname.exe (DON'T USE "Contoso.exe" as in the MSDN web page...it's just a placeholder name)
Then give it a DWORD value, according to the table on:
http://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
I changed to 11001 decimal or 0x2AF9 hex --- (IE 11 EMULATION) since that isn't the DEFAULT value (if you have IE 11 installed -- or whatever version).
That MSDN article contains notes on several other Registry changes that affects Internet Explorer web browser behavior.

I know this thread is old and there are already comprehensive answers.
Just in case you don't know this:
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
You don't have to hardcode IE version number as
<meta http-equiv="X-UA-Compatible" content="IE=9" >

I totally agree with the solution provided, but I think a little clarification is important I think, might be necessary.
For each process (read also: vshost.exe, yourWinformApplication.exe.svchost, or the name of your application.exe) that will need to add a DWORD with the value provided, in my case I leave 9000 (in decimal) in application name and running smoothly and error-free script.
the most common mistake is to believe that it is necessary to add "contoso.exe" AS IS and think it all work!

Yes, WebBrowser control uses whatever version of IE you have installed. This means of course that if you run your application on a machine with IE 8 then the IE 9 features you depend on will not be available.

I came to this solution and it did not worked for me! Because I was using 64bit I had to replace the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
Instead of the one that everyone talks about:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]

I liked the (C#) code in the following which sets the registry settings for your app. Not sure if it will cut it after installation though if permissions are required. For me it solved an issue with WebSocket not being available inside a WebBrowser control in WPF.
C# webbrowser Ajax call

I had the same problem, and the registry answers here didn't work.
I had a browser control in new version of my program that worked fine on XP, failed in Windows 7 (64 bit).
The old version worked on both XP and Windows 7.
The webpage displayed in the browser uses some strange plugin for showing old SVG maps (I think its a Java applet).
Turns out the problem is related to DEP protection in Windows 7.
Old versions of dotnet 2 didn't set the DEP required flag in the exe, but from dotnet 2, SP 1 onwards it did (yep, the compiling behaviour and hence runtime behaviour of exe changed depending on which machine you compiled on, nice ...).
It is documented on a MSDN blog NXCOMPAT and the C# compiler. To quote : This will undoubtedly surprise a few developers...download a framework service pack, recompile, run your app, and you're now getting IP_ON_HEAP exceptions.
Adding the following to the post build in Visual Studio, turns DEP off for the exe, and everything works as expected:
all "$(DevEnvDir)..\tools\vsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"
Editbin documentation
Dumpbin /headers will display the DEP setting on a exe.

Regarding whitehawk's accepted answer.
I am just trying to add a bit hands on experience. Was just trying to add a comments, but SO complains it's too long.
Basically, without IE 9 installed, the registry switch FEATURE_BROWSER_EMULATION won't work AT ALL.
For example, my own experience today I was trying to get the .net webcontrol to work with IE10 mode because one html I am trying to render won't work with .netControl under VS2012, and not even work when I load the html to IE8 directly, still css won't render properly(even after I say allow blocked content). But I have tested the same html ok with IE10 on a friend's win 8 machine. That's why I am trying to set the .net webControl to IE 10 mode but just keeps failing...
Now I figured this is bcos my win 7 machine only have IE8 installed, so regardless which value I set to the FEATURE_BROWSER_EMULATION switch(value to IE9, IE10 IE11), it just won't work AT ALL !
Then I downloaded and installed IE 10 on my win 7 machine. Still it won't work, then I added the FEATURE_BROWSER_EMULATION, it started working !
Also I noticed regardless which value I set , even set it to value 0 by default, the webControl is still using IE 10 mode which still works for me.
So to summarise,
If you have IE X installed but you want your .Net webControl to work under IE (X+N) N>0 modo, TWO things you need to do:
Go to MS website & download and install IE (X+N) on your machine,
you will need to reboot after installation.
apply whitehawk's answer.
Basically:
To control the value of this feature by using the registry, add the name of your executable file to the following setting and set the value to match the desired setting.
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
FEATURE_BROWSER_EMULATION
contoso.exe = (DWORD) 00009000
Windows Internet Explorer 8 and later. The FEATURE_BROWSER_EMULATION feature defines the default emulation mode for Internet Explorer and supports the following values.
Value Description
11001 (0x2AF9 Internet Explorer 11. Webpages are displayed in IE11
edge mode, regardless of the !DOCTYPE directive.
11000 (0x2AF8) IE11. Webpages containing standards-based !DOCTYPE
directives are displayed in IE11 edge mode. Default value for IE11.
10001 (0x2711) Internet Explorer 10. Webpages are displayed in IE10
Standards mode, regardless of the !DOCTYPE directive.
10000 (0x02710) Internet Explorer 10. Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode. Default value for Internet Explorer 10.
9999 (0x270F) Windows Internet Explorer 9. Webpages are displayed in
IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328) Internet Explorer 9. Webpages containing
standards-based !DOCTYPE directives are displayed in IE9 mode.
Default value for Internet Explorer 9.
Important In Internet Explorer 10, Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode.
8888 (0x22B8) Webpages are displayed in IE8 Standards mode,
regardless of the !DOCTYPE directive.
8000 (0x1F40) Webpages containing standards-based !DOCTYPE directives
are displayed in IE8 mode. Default value for Internet Explorer 8
Important In Internet Explorer 10, Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode.
7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives
are displayed in IE7 Standards mode. Default value for applications
hosting the WebBrowser Control.
Full ref here

Related

Unsupported browser in visual studio 2010 C#

I want to display GPS coordinates on Google Maps. For this purpose I chose web browser from the toolbox. But it show an error of unsupported browser. I tried updating my Internet Explorer.
I also set Google Chrome as the Debugging Browser in Visual Studio but it didn't work.
This is the part of code where I am accessing the web browser.
try
{
StringBuilder queryaddress = new StringBuilder();
queryaddress.Append("https://maps.google.com/maps?q=");
if (lat != string.Empty)
{
queryaddress.Append(lat + "," + "+");
}
webBrowser1.Navigate(queryaddress.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
Error
You seem to be using an unsupported browser. Old browsers can put your
security at risk, are slow and don't work with newer Google Maps
features. To access Google Maps, you'll need to update to a modern
browser.
What is the best way to do this.?
You are getting this message since the WebBrowser control is emulating an older version of Internet Explorer on your machine:
By default, this feature is enabled for Windows Internet Explorer and
for applications hosting the WebBrowser Control. To disable this
feature by using the registry, add the name of your executable file to
the following setting.
This can be changed via Registry settings:
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
FEATURE_BEHAVIORS
contoso.exe = (DWORD) <VALUE>
where VALUE is
11001 (0x2AF9) Internet Explorer 11. Webpages are displayed in IE11
edge mode, regardless of the declared !DOCTYPE directive. Failing to
declare a !DOCTYPE directive causes the page to load in Quirks.
11000 (0x2AF8) IE11. Webpages containing standards-based !DOCTYPE
directives are displayed in IE11 edge mode. Default value for IE11.
10001 (0x2711) Internet Explorer 10. Webpages are displayed in IE10
Standards mode, regardless of the !DOCTYPE directive.
10000 (0x02710) Internet Explorer 10. Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode. Default value for Internet Explorer 10.
9999 (0x270F) Windows Internet Explorer 9. Webpages are displayed in
IE9 Standards mode, regardless of the declared !DOCTYPE directive.
Failing to declare a !DOCTYPE directive causes the page to load in
Quirks.
9000 (0x2328) Internet Explorer 9. Webpages containing
standards-based !DOCTYPE directives are displayed in IE9 mode.
Default value for Internet Explorer 9. Important In Internet
Explorer 10, Webpages containing standards-based !DOCTYPE directives
are displayed in IE10 Standards mode.
8888 (0x22B8) Webpages are displayed in IE8 Standards mode,
regardless of the declared !DOCTYPE directive. Failing to declare a
!DOCTYPE directive causes the page to load in Quirks.
8000 (0x1F40) Webpages containing standards-based !DOCTYPE directives
are displayed in IE8 mode. Default value for Internet Explorer 8
Important In Internet Explorer 10, Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode.
7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives
are displayed in IE7 Standards mode. Default value for applications
hosting the WebBrowser Control.
Follow this article for a more details.

NoSuchWindowException was unhandled : Unable to find element on closed window. IE 11 - Selenium C#

May be this question has been asked many times before. But i went through all the related questions in stackoverflow , but couldn't find any satisfactory solution.
Well i'am writing a selenium automation code in VS2010 using C#, IE11 is my web browser on which i'am performing testing. Using IEDriverServer 32bit version in Windows 7 to open IE instance.
I already knew that there is some compatibility kind of issue between selenium and IE 11, but still my code worked fine up till now when i started getting this Error - " NoSuchWindowException was unhandled : Unable to find element on closed window."
Below are my steps:-
IWebDriver driver = new InternetExplorerDriver("D:\\");
driver.Navigate().GoToUrl("http://aiaw00572.belldev.dev.bce.ca:8060/UTM_MechHDTool_UserWebApp");
driver.FindElement(By.Id("ctl00_cpMainContent_radcboTaskType_Input"), 10).Click();
driver.FindElement(By.XPath("//div[#id='ctl00_cpMainContent_radcboTaskType_DropDown']/div/ul/li[2]")).Click(); (this step select a drop down option which performs a postback on the page)
driver.FindElement(By.Id("ctl00_cpMainContent_utmTaskGrid_ctl00_ctl06_imgbtnStartWorking")).Click();//Getting error on this step. Earlier i was not getting it anywhere
I searched for the solutions for this problem and came to know about one solution in which some registry change has to be done to solve it, though that also does not confirm that it will solve the problem. But the problem here i can't even check this solution as i don't have any administrator privilege in my system.
So just wanted to know if someone else has also faced the problem and came with some solution, so he/she can share it here please as i badly need a solution in here for this situation.
Worked for me after running IEDriverServer as admin or setting protected mode for all zones (https://stackoverflow.com/a/21373224/217408)
Error:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
Step1. Change Windows registry.
If you use Internet Explorer 11 x64 (64 bit),
create file ie11_win64.reg has content:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BFCACHE]
"iexplore.exe"=dword:00000000
Then run it.
If you use Internet Explorer 11 x86 (32 bit),
create file ie11_win32.reg has content:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BFCACHE]
"iexplore.exe"=dword:00000000
Then run it.
Step2. Setting in internet explorer. Uncheck all (or Check all, must be the same for zones: Internet, Local intranet, Trusted sites, Restricted sites)
For me the aswear was to download this registry file from http://heliumhq.com/docs/internet_explorer and to run it
In our case tests were based on Jbehave and Serenity. The First test always pass and second fails with mentioned exception. Opening new Webdriver instance for each scenario helps to resolve issue.

RDLC Report not displaying in IE 11

I am using report viewer control for reports. Now we are facing the problem in IE 11, Report not displaying in IE 11. Its showing only loading icon all time.
You are probably usign ReportViewer version 10 or below. Probably it craches in Chrome and Firefox too.
I don't know why by in this case if you inspect the network traffic in you prefered dev tools in the browser you will see that it try to download an image that is missing and it break the code.
To sove this problem you need to update your ReportViewer dlls to the version 11 (2012) at least and take into account some problems it can bring. They are these:
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll
Is possible that after the update you will need to reference Microsoft.SqlServer.Types.dll too.
You will need to change your .config file too, basically changing the version number to 11.
To be clear, I didn't update it on the server but changed these dll to Copy To Local in Visual Studio so they are published togheter in the bin folder.
Please get in touch if you need further help. I lost a lot of time searching for this but can't remember all steps I did to solve.

Allowing javascript to run on a windows form web browser

I want to use a Web Browser to access a website that uses JavaScript on load. I understand that Web Browser is a wrapper of the current installed version of Internet Explorer. However, testing the website on Internet Explorer yields no errors but does not work if I use the Web Browser to access the content.
I have also looked at my internet security settings to ensure it is enabled.
The issue I get is;
Awkwardly enough, I found the answer moments after posting this but I thought anyone who comes across the same problem as me will find solace in this answer;
It seems downloading the latest version of Internet Explorer is not enough and you must explicitly specify the version of IE to use by adding a new registry key.
HTML fix;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
... other headers
</head>
<body>
... content
</body>
</html>
Via registry;
Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION for 64-bit or 32-bit only machines.
Or go to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION for 32-bit on 64-bit systems (It cannot hurt to add keys to both locations if you have them. If you do not have them, you can make the folders yourself).
Create a new DWORD key and name it the name of your application e.g. "myapp.exe" and then edit the value of the key. There are many different values you can add depending on the IE version you want to emulate. I entered 11001 (as a decimal value - 0x2AF9 in HEX) which emulates IE 11 (many more values located at: http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx#browser_emulation).
If you're using Visual Studio like I am, you'll notice that this method might not even work. However, it does work. You need to manually open the .exe file using Explorer or terminal rather than run the project on Visual Studio.
If you wish to run the program on Visual Studio then consider adding a key for "myapp.vshost.exe" as this is used for debugging.
More information and source is from; http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version.
I hope this helps anyone with any issue regarding your Web Browser perhaps using the wrong IE version as a wrapper or functions are not working as intended.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
... other headers
</head>
<body>
... content
</body>
</html>
This will work out , This is the summery of Ryan Singh's answer

WebSupergoo.ABCpdf Test application does not work

I recently cleaned up my Windows 7 64-bit PC, and after it ABCpdf8 started giving me an error, when I try to export HTML to PDF.
The error is "Failed to initiate IE compatibility mode: Failed to load all required assemblies."
at WebSupergoo.ABCpdf8.Internal.IECompatibility.Activate()
at line
theID = theDoc.AddImageUrl(input.Text);
of the test application, and I have no idea why, because I did not remove any assemblies from my machine.
If I run the compiled application on another workstation with the same config (Windows 7 64-bit), it works fine. Dependency Walker images showed no difference in DLLs sets from my machine and from another.
How else can I identify the source of the problem?
It is definitely neither a missing DLL, nor the user access to the system folders, because, I checked user rights as well, they're identical on both machines.
I assume that it might be a corrupted registry entry. Is there any way to quickly check the assumption?
It has to be said that, ABCpdf comes as third-party tool within another software, so I cannot contact support directly, but through the main vendor.
I had a similar problem with different behavior on w7 and ws2008, which was solved by using the Gecko engine
doc.HtmlOptions.Engine = EngineType.Gecko;
Note that websupergoo recommends using Gecko rather than IE9 as parts of the IE API it uses have been deprecated. (item 6.29)
When you 'cleaned' your system you may have erased the license key from the registry. Try re-installing your 'other software'.

Categories