I have a very simple C#-Form in which there is just a Web browser opening a website. When i execute the code and the browser loads the desired website i always get an warning which looks like this
I do not want to have to touch the website or the browser for it, is there a way to solve this in C#?
I solved it by adding this line:
webBrowser1.ScriptErrorsSuppressed = true;
Related
Using DotNetBrowser in WPF app in Windows 10. When navigating to certain pages that typically save user data and use it in subsequent loads to restore your settings, it doesn't seem to be happening.
See example code here of a very simple implementation. If I use it to browse to Amazon's site and login, after closing and reopening app, I'll need to login again -- in a normal browser like Chrome, it retains my login. Is something missing in the code to enable this similar behavior?
To make it work, I had to set UserDataDirectory when creating engine:
engine = EngineFactory.Create(new EngineOptions.Builder
{
RenderingMode = RenderingMode.HardwareAccelerated,
UserDataDirectory = $"{Environment.ExpandEnvironmentVariables("%AppData%\\MyApp\\Chromium\\User Data")}",
LicenseKey = ConfigurationManager.AppSettings["DotNetBrowserLicenseKey"],
}
.Build());
I'm currently working on a WinForms application that I'm hoping will allow users to enter stored passwords into a web browser without a keylogger being able to see the password. I've got the storing part completed, but I can't figure out how to insert the password into a browser without using either the clipboard or .NET's SendKeys class, both of which can be seen by most keyloggers.
I looked into using Windows messages to do this, but, from what I understand, you need to know the hWnd of a control in order to send it a Windows message. Unfortunately, it appears that web browsers do not use hWnds for individual textbox controls.
I know there has to be a way to do this. In Notepad++, for example, you can drag text into a web browser textbox and the text doesn't show up in keyloggers. Same goes for Neo's SafeKeys. Anyone have any ideas on a general approach to doing this? Thanks so much.
What you want is a WebDriver Library. Unfortunately .net does not have plenty of good ones. You can take a look at WatiN or selenium
From what I understand watin isn't supported anymore and is not multi-browser compatible.
Here is an example of what you can do with selenium
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://testing-ground.scraping.pro/login");
var userNameField = driver.FindElementById("usr");
var userPasswordField = driver.FindElementById("pwd");
var loginButton = driver.FindElementByXPath("//input[#value='Login']");
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
loginButton.Click();
}
I image you can link your driver to an existing opened browser
If you are able to run ruby on the computers I would recommend using Watir
and running the ruby script doing the web manipulation from the c# using processes.
I am having a problem with iframe and WebBrowser. In my app I have a page with WebBrowser which goes to specific url and should show a google map (embedded with iframe). However, it does not. Getting the error "This content cannot be displayed in a frame. To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame."
But if I go to this url with the emulators browser everything works fine, same with ie in my pc. I also tested with other urls which dont have iframes and the WebBrowser works fine. I have also tried webBrowser.NavigateToString with the same code the url has but doesnt work either. I do have the &output=embed at the end of the map url in iframe. Also tried using my api key in the html.
What should I try next?
Im gonna answer to myself.
Adding this line in c#
webBrowser1.IsScriptEnabled = true;
and this in xaml
IsScriptEnabled="True"
did the trick.
So scripting is disabled in WebBrowser control by default.
Well, now I know.
Found the answer from here: http://www.jeffblankenburg.com/2010/10/18/31-days-of-windows-phone-day-18-webbrowser-control/
I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't
I know there is built-in Internet explorer, but what I'm looking for is to open Firefox/Mozilla window (run the application) with specified URL. Anyone can tell me how to do that in C# (.nET) ?
You can do this:
System.Diagnostics.Process.Start("firefox.exe", "http://www.google.com");
This will launch the system defined default browser:
string url = "http://stackoverflow.com/";
System.Diagnostics.Process.Start(url);
Remember that Process.Start(url) might throw exceptions if the browser is not configured correctly.
See ProcessInfo.UseShellExecute
Use the Process class (System.Diagnostics) using the URL as the process name. This will use the system default browser to open the URL. If you specify a browser, you run the risk that the browser doesn't exist.
In Visual Studio click the File -> Browse With... on the menus and then select the browser that you want to use. You can also change the browser there. If the Browse With... menu option doesn't appear then you need to select a project from your solution that that can be launched in a browser.
If you explicitly do not want to use the User's default browser, you can run the browser with the URL as the first argument.
C:\Program Files\Mozilla Firefox>firefox.exe http://google.com
launches Firefox with google for me. But as people have said, you run the risk of it not being installed, or being installed to a different place, etc.