WebBrowser control throwing lots of JavaScript errors - c#

The WebBrowser control shipped with .NET 4.7 is throwing lots of JavaScript errors. For example, we tried with www.yahoo.com and we get multiple JavaScript errors. One such example is shown below:
If we browse the same link in internet explorer 11, we are not getting any error and browsing session goes smooth. Note that we already set Browser Emulation registry setting for IE 11. Used the Link to Set IE 11 Emulation. The Registry Key for the Emulation is:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
(For 64 bit machine)
Re-production steps
Create a Visual C# Windows Forms Application
Place Web-Browser Control and a Command Button in the Form
Add the Following code in the command button Handler:
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.yahoo.com");
}
That is all. Once we click the command button, we have to respond to multiple JavaScript errors. How do we resolve this issue?
Note that we already have Browser Emulation for IE is set to 11 (in Registry). We do not want to suppress the Error, as we lose the service provided by the JavaScript. For example, click the “Cricket” button in the very top of the Yahoo page:

Related

Visual Studio C# hyperlink loads in browser AND in .net app

I have a VS 2010 .net app with a hyperlink within a textblock within a stackpanel on a .XAML. When I run the app it opens the link in a new tab in IE which is great, it's exactly what I want. But it also opens it in the executing app panel. I can navigate away and back and get back to the page in my app that I was working on but I need to keep it from loading on that page to begin with. Otherwise the behavior is exactly what I want. Note: I tried using the AbsoluteUri line that is commented out but that had the same behavior PLUS would shut the app down. Thanks in advance.
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="http://www.msn.com">Click here to go to msn</Hyperlink></TextBlock>
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
// System.Diagnostics.Process.Start(e.Uri.AbsoluteUri);
System.Diagnostics.Process.Start("http://www.msn.com");
} ```

C# WebBrowser Control Enhanced Protected Mode

I am trying to access a webpage (that is not under my control) namely allscripts sandbox via a WebBrowser control. My computer's internet explorer is correctly set up for said webpage (Added in Trusted Sites, Allowed and installed all active-x addons, running in compatibility mode, etc).
The webbrowser control displays the following error:
This webpage wants to run 'Some ActiveX control' which isn't compatible with Internet Explorer's enhanced security features. If you trust this site you can disable Enchanced Protected Mode for this site and allow the control to run.
I have not enabled (to the best of my knowledge) the enhanced protected mode.
Also trying to ignore the errors and continue with log-in displays a Message
The Centricity's container for .NET-based pages failed to initialize. Make sure your .NET environment is configured to grant Full Trust to this Website.
The above was also an error on the default IE until i run the command %WINDIR%\Microsoft.NET\Framework\v2.0.50727\caspol -q -m -cg Trusted_Zone FullTrust.
I have tried various registry keys but none seemed to work.
I have also tried implementing a custom IInternetSecurityManager that Maps all urls to zone Trusted and returns URLPOLICY_ALLOW on all ProcessUrlAction calls.
Any suggestion would be appreciated.
The problem could be that webbrowser uses by default an old version of the IE. Take a look at Use latest version of Internet Explorer in the webbrowser control
The webbrowser control is ie11 wrapped with a com wrapper that throttles back ie11 to ie7 mode. There's not a lot else going on there that I can imagine would cause your issue.
Since this page works for you when you run ie11 externally then the most likely explanation seems to be your attempt to force the control into ie11 mode is the problem.
I suggest you try Mentor's code here:
Set WPF webbrowser control to use IE10 mode
Which will automate adding the name of the running program to the registry.
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if(pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
string myProgramName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var currentValue = registrybrowser.GetValue(myProgramName);
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue(myProgramName, 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";

Unable to click login button on angular site in IE (Selenium)

For some reason I seem unable to click a login button when using the selenium IEDriver. It works fine in both Chrome and Firefox.
Website is http://www.notacv.com/
Simple code...
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.notacv.com");
IWebElement element2 = driver.FindElement(By.CssSelector("div.container-fluid.hero ul li:nth-child(1)"));
element2.Click();
I've tried the following to remedy the problem with no success
Have tried referencing both the li and the a tags
Both XPath and CSS selector - both confirm to find only one element via Chrome developer toolbar
Thread.sleep (prevents the error but does nothing when it gets to the click)
Repeating the click and the wait
Javascript, JQuery and angular waits
SendKeys(Keys.Enter)
actions -> moveto.Click()
Explicit wait to check displayed, visibility, enabled
Protractor for C#
Does anyone know how to fix this for IE?
please check the current link https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#Required_Configuration
Make sure you applied required changes
The IEDriverServer exectuable must be downloaded and placed in your PATH.
On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value
can be on or off, as long as it is the same for every zone. To set
the Protected Mode settings, choose "Internet Options..." from the
Tools menu, and click on the Security tab. For each zone, there will
be a check box at the bottom of the tab labeled "Enable Protected
Mode".
Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet
Options dialog.
The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance
of Internet Explorer it creates. For 32-bit Windows installations,
the key you must examine in the registry editor is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows
installations, the key is
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the
FEATURE_BFCACHE subkey may or may not be present, and should be
created if it is not present. Important: Inside this key, create a
DWORD value named iexplore.exe with the value of 0.

__IE_PrintType script error when calling WebBrowser.ShowPrintDialog from windows forms app

I've been tasked with fixing a bug in a windows forms application written in C# that basically allows the user to perform an operation then print a summary of the results by calling WebBrowser.ShowPrintDialog() on button_click. However, upon clicking the Print button, a javascript error is returned, but only in IE10 and IE11; older versions work fine. Unfortunately I'm unable to debug the script error because it causes the app to crash as it attempts to launch IE's debugger.
Line: 291
Error: Unable to get property '__IE_PrintType' of undefined or null reference
Basically, the results of the user's action are passed through to a browser via WebBrowser.Navigate where they are rendered on the client then can be printed.
browser.Navigate(new Uri(targetFile.ToString(), UriKind.Absolute));
Unfortunately, I have no clue where this script error is coming from or why. My first inclination was to print out the html output via MessageBox.Show, save it off, then open it directly in IE11 to see if the error reproduced, only to find out that it didn't; IE11 handles it just fine.
Further research led me to believe that compatibility mode is used when using the WebBrowser object, but opening the html in IE11 reveals that it's already using EDGE mode.
What am I missing here?

Open Internet Explorer from Google Chrome

I currently developing a ASP.NET web application.
The application is designed for Google Chrome. I would like to pop out IE when printing is involved because Chrome lack preview etc. at a button click the IE should open. Here's the code:
protected void btn_print_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://localhost/storeapp/printpage.aspx?orderno=" + Request.QueryString["orderno"].ToString() + "");
}
Here I have passed a particular orderno to the URL. But when I click nothing happens. I have set IE as default web browser. Why is this?
There is no error shown? Any ideas?
What you are trying to do will only open an IE window on the SERVER not on the client machine. You cannot (for obvious security reasons) start a process on the clients machine.
You cannot force a client browser to open a link in a different browser.
You cannot force server to open process on Client side, what you have now is opening it on the Server side which is not desired behavior I believe.

Categories

Resources