I am developing a Browser Helper Object (BHO) for Internet Explorer written in C#. I use the BeforeNavigate event to get a called URL and save it into a local variable. For every tab a new BHO instance is spawned. This means that every tab has it's own BHO which in turn have own local variables. I have checked this by displaying a MessageBox with the previous called URL (the value of the local variable) before it is overwritten with the new URL.
string myUrl = "";
void BeforeNavigate( string URL, ... )
{
System.Windows.Forms.MessageBox.Show( myUrl );
myUrl = URL.ToString();
}
But in some cases the local variable is empty although a URL was called before. I investigated the IE settings and found out that this behavior is caused by the zone elevation protection of IE. For the zones local intranet and trusted sites the protected mode is disabled while it is enabled for zones internet and restricted sites.
E.g., when intranet.com is called and then internet.com in the same tab, I would expect that the MessageBox displays intranet.com when internet.com is called. But an empty string is displayed instead. I guess that calling internet.com activates the protected mode for this tab which spawns a new instance of the BHO. The MessageBox will now display the value of the variable of the new BHO instance. The value of the variable of the old BHO gets lost.
If protected mode is enabled for zones local intranet and trusted sites the BHO behaves correctly. I guess that the protected mode is disabled in this zones for compatibility reasons. There may exists websites in the intranet that do not work with protected mode. Thus, I am looking for a solution that works with protected mode disabled for this zones.
Since IE manages the loading of the BHO I doubt that this problem can be solved from within the BHO.
Does anybody have deeper knowledge about this topic to confirm my guess?
Is it possible to keep the variable's value with protected mode disabled for zones local intranet and trusted sites?
Any help will be appreciated, thanks!
I found the following link: http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html
There is said:
When you cross into or out of Protected Mode by, say, navigating from an internal intranet website to one on the internet, IE has to create a new process, because it can't change the Mandatory Integrity Control level of the existing process. Moreover, in IE versions after 7, it's not always obvious that a Protected Mode boundary has been crossed, since IE tries to present a better user experience by seamlessly merging the browser window of the new process with the already opened browser window. This under-the-covers process switching also means that any references pointing to IE's COM objects before the Protected Mode boundary crossing are left pointing to objects that are no longer used by IE after the boundary crossing.
Based on this, my guess seems to be right. The BHO which is a COM object of IE is no longer used and thus it's value gets lost. The only solution that remains is to enable or disable protected mode for all zones.
Related
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 += " ( Первый раз запускать с правами админа )";
I am developing a Browser Helper Object (BHO) for Internet Explorer written in C#. I use the BeforeNavigate event to get a called URL and save it into a local variable. For every tab a new BHO instance is spawned. This means that every tab has it's own BHO which in turn have own local variables. I have checked this by displaying a MessageBox with the previous called URL (the value of the local variable) before it is overwritten with the new URL.
string myUrl = "";
void BeforeNavigate( string URL, ... )
{
System.Windows.Forms.MessageBox.Show( myUrl );
myUrl = URL.ToString();
}
But in some cases the local variable is empty although a URL was called before. I investigated the IE settings and found out that this behavior is caused by the zone elevation protection of IE. For the zones local intranet and trusted sites the protected mode is disabled while it is enabled for zones internet and restricted sites.
E.g., when intranet.com is called and then internet.com in the same tab, I would expect that the MessageBox displays intranet.com when internet.com is called. But an empty string is displayed instead. I guess that calling internet.com activates the protected mode for this tab which spawns a new instance of the BHO. The MessageBox will now display the value of the variable of the new BHO instance. The value of the variable of the old BHO gets lost.
If protected mode is enabled for zones local intranet and trusted sites the BHO behaves correctly.
This issue I already described in IE's zone elevation protection interferences functionality of BHO to this point.
When I enable the EPM (Enhanced Protected Mode) the same problem occurs even if protected mode is enabled in all zones. Strangely also if I explicitly remove the tested URLs from the zones local intranet and trusted sites. (Note that "protected mode" and "enhanced protected mode" are different.)
In the context menu of a website the menu item properties gives information about the mode in which a website is executed. For websites in the internet the mode Internet | Protected Mode: Enhanced is displayed indicating that this website is executed in EPM.
I discovered that websites that belong to the intranet are executed in a "special" EPM. For an intranet website the mode Local Intranet | Protected Mode: Enhanced (122) is displayed. After I removed the tested URLs from the zones, Internet | Protected Mode: Enhanced (122) is displayed. I tried to find out what the 122 means but could not find any helpful information. It seems that calling a Internet | Protected Mode: Enhanced (122) website and then a Internet | Protected Mode: Enhanced website in the same tab triggers a boundary crossing which leads to the same issue.
Can anyone provide information about the meaning of the 122?
Any help will be appreciated, thanks!
In my opinion, it is just an inner serial number.
For more information about Enhanced Protected Mode, see the following Internet Explorer blog articles:
Enhanced Protected Mode
Understanding Enhanced Protected Mode
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.
What I'm trying to do is to, from a Web Service (WCF), give a remote computer (the Web Service Consumer) the instruction to open its default Web Browser (be it Internet Explorer, Firefox, Chrome, etc.), navigate to a certain web page and keep monitoring the events of that browser so that I can capture a certain value from the Document Title at a certain point, and do stuff with it.
I'm already able to send the command to open Internet Explorer and navigate to a URL, from the Web Service to the remote computer (my consumer), but I don't like the approach since I can't monitor the Document.Title property for changes nor access its value at any given time. Here is an example:
using System.Diagnostics;
public void DoIt();
{
Process batchProcess = new Process();
batchProcess.StartInfo.FileName = "iexplore.exe";
batchProcess.StartInfo.Arguments = "http://whatever.com";
batchProcess.Start();
}
This opens up Internet Explorer on the remote machine and navigates to the Url I give it, but I can't keep watch for the Browser's Events or Properties Values....
Can somebody help? ;-)
I don't think you can access information in one application (the web browser) from another (the WCF client) like that, and it's certainly not possible to do it without knowing what the user's default browser is.
You might have more luck using a WebBrowser control (WPF or Windows Forms), which embeds Internet Explorer's engine into the application and allows you access to the document title.
When I access the page with the browser (ie9), the browser is rendering ok.
When I use the WebBrowser control I have JavaScript errors.
I know I can suppress the scripts errors, but I want them to run correctly, because they affect the rendering and the functionality of the page.
How can I solve this problem ? Can I integrate IE9 directly in the Windows Form and use similar methods like with the WebBrowser control (navigate,get id, invoke click) ?
Thanks.
What I would do is assign an object to webbrowser.ObjectForScripting and then inject a javascript function that assigns windown.onerror to a wrapper that calls the external script in the host app. Like:
window.onerror = function(message, url, lineNumber)
{
window.external.errorHandler(message, url, lineNumber);
}
Refere to:
http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/
If you have IE9 installed, the WebBrowser will still use IE7 mode unless you override this behaviour with a registry setting - as described in this StackOverflow answer. This is the most likely cause of the JavaScript errors you're getting in the WebBrowser (because you're not seeing the same errors in IE9).
You can make the registry setting using the following c# code (which sets IE10 mode if Windows 8 is detected) and changing app-name.exe to match your own application. You should add an error handler for the case where there are insufficient privileges (admin privileges are required to write to this registry key).
string installkey = #"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
string entryLabel = "app-name.exe";
System.OperatingSystem osInfo = System.Environment.OSVersion;
string version = osInfo.Version.Major.ToString() + '.' + osInfo.Version.Minor.ToString();
uint editFlag = (uint)((version == "6.2") ? 0x2710 : 0x2328); // 6.2 = Windows 8 and therefore IE10
RegistryKey existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, false); // readonly key
if (existingSubKey.GetValue(entryLabel) == null)
{
existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, true); // writable key
existingSubKey.SetValue(entryLabel, unchecked((int)editFlag), RegistryValueKind.DWord);
}
You can use the following code line to get rid of those types of errors:
webBrowser1.ScriptErrorsSuppressed = true;
It will prevent getting JavaScript errors.
So i know the post is old, but it was a recent problem for me and i had to do some serious digging and thinking outside the box.
basically like most replies here - you cannot alter the webbrowser control to use the most recent IE engine. mine uses IE7 by default, i have seen some replies that basically changes/ adds stuff to registry, am always not comfy when it comes to the registry, a cleaner way to address this issue would be to append code on your website that forces it to use the most current IE engine on any pc and works like a charm.
if you have access to the web.config file of the page you intend to browse, simple append:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
</system.webServer>
and your site would force webbrowser control to run the most current IE engine on your computer. Other options are found here:
https://www.leapinggorilla.com/Blog/Read/1016/ie-ate-my-css---disabling-compatability-mode
I should state that this would only work if you have access to the page / web.config of the website/ application you are trying to access- which was my case.
THe WebBrowser control uses IE7. So if there is a problem then your script does not work for IE7 and you will have to fix that.
You cannot integrate IE9 as it depends on it being installed on the computer and not everyone has IE9 installed.
As a help to whoever else may have this problem, I tried all these things and nothing worked for me. Here's what does work. I am not sure exactly what causes this error, but apparently when you just press "F5" in VS to debug your app, it runs YourProject.vshost.exe as the process name. If you run the same app from the command line, it will show up as YourProject.exe, and the javascript errors vanish. I think IE sees the app running visa via VSHOST and decides this is fishy and disables javascript from loading correctly.
So... go into your project setting for your executable.
Select "Debug" options.
Select "Start External Program".
Browse to and select Debug\YourProgram.exe (NOT YourProgram.vshost.exe).
Save, recompile, and hit F5.
Everything should work as per usual now, and Visual Studio even attaches to the process for you automatically.
Enjoy!
Grego