.NET 4.0 Web browser control and msIsSiteMode javascript error - c#

I have an application that connects to www.Jango.com and using a web browser control. However when using the .NET browser control I constantly receive a script error of “Unable to get value of the property 'msIsSideMode': object is null or undefined”, and therefore the rest of the site does not load.
This can be reproduced by creating a simple windows forms application, adding a webbrowser control and navigating to jango.com
As far as I can tell, the web browser control renders a website based on the version of IE installed on your machine. On my machine I have IE9 installed. The method msIsSiteMode appears to be an IE method that tells weather the current page was launched as a pinned site. Since jango.com is very JavaScript based, this null value causes the website to stop functioning correctly. However navigating to jango.com in Internet Explorer works just fine and no errors are produced.
Is anyone aware of a way to work around this, such as having my application set the value? Have the web browser control render as a different version. Any suggestions at all, I am open to anything, except changing the version of IE on my machine as this is not an option.

Set the ScriptErrorsSuppressed property to True on the WebBrowser control.
EDIT: One more alternative
Try this on the Form that hosts the web user control:
using System.Runtime.InteropServices;
using System.Security.Permissions;
[ComVisibleAttribute(true)]
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.ObjectForScripting = this;
}
...
}
Read here for more detailed information.

I see similar problem in WebBrower Control with IE9 installed on my machine. In my case, I have two windows forms with WebBrowser Controls. One of those is used to load the pop up from the other.I get the script error on pop up one.its only with IE9

Related

User data not persisting in DotNetBrowser component

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());

C# Uwp app webbrowser control cannot get device location

I am developing a web view universal windows application. In fact my mobile ready website will be shown within a web view or webbrowser control in windows universal application..
Using the website directly from Edge in mobile (or chrome in desktop etc) the app notifies the user to allow using location as it should (HTML Geolocation API ).
However in my app using web browser control this is not happening. It is not able to run the script or something.
I have given grant access to user's location in the app but still no action is taken.
What else can I do in order to get user's location within an app that uses webbrowser ?
I found the solution.
You have to fire the PermissionRequested event. And in this event you have to execute the Allow method of the WebViewPermissionRequestedEventArgs object. Something like this:
private void webView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
{
if (args.PermissionRequest.PermissionType == WebViewPermissionType.Geolocation)
args.PermissionRequest.Allow();
}

Embed Internet Explorer browser into Winforms using C#

I'm trying to open a IP specified webpage using IE (Why IE? Because not every Windows have Chrome or Firefox installed) and present it in a simple Winforms window.
The up-mentioned webpage is a BI (Business Intelligence) webpage that will update itself dynamically, and I want the user to sit and look at it while the page is updated with a new statistics.
Flow of events:
User will enter the specific IP address and click "Get the Web-page".
New Winform window will pop-up with the specific webpage inside.
Also, it will be great if there an option to hide IE navigation panel, because I don't want to give the option of browsing in this window.
I tried to do this using CefSharp, but I didn't get to anywhere. Every example that I saw was written in asp.
Here is was I did so far, and this is not working:
namespace BingoDesktopWindow
{
public partial class BingoWin : Form
{
public BingoWin()
{
InitializeComponent();
CefSettings settings = new CefSettings();
CefSharp.Cef.Initialize(settings);
ChromiumWebBrowser browser = new ChromiumWebBrowser("http://12.345.67.89/bingo/Default.html");
this.browserPanel.Container.Add(browser);
}
}
Thank you!
}
Why do not you use Winforms WebBrowser control. WinForms WebBrowserControl. You can manipulate it more than IE. Web browser control is itself derived from IE so, it has all its functionalities.

"Unspecified error" from javascript in my Silverlight application

I have a Silverlight application written in C# that utilizes the Bing Maps SDK. In this application I have a page with some javascript functions to expose functions within the application. The application registers the Bing MapControl in the MainPage's constructor with:
HtmlPage.RegisterScriptableObject("Page", new MapControl(this.BingMap));
In the javascript function, I call the methods of the application like so:
<script type="text/javascript">
function ClearMap() {
var control = document.getElementById('silverlightControl');
control.Content.Page.ClearMap();
}
</script>
However, whenever I refer to the control.Content.Page property in a javascript function, I get an "Unspecified error". Even just setting it to a variable will cause the error, for example:
var page = control.Content.Page;
Here is the strange part. I am using this silverlight application from 2 other applications. One is a windows service, and the other a winform application. The winform embeds a visible WebBrowser into its form and uses that to call the javascript functions. When using the winform, everything works fine with no errors.
The error only occurs when calling these functions from the windows service. The service instantiates a WebBrowser object just like the winform application does, and initializes everything in the same way. The only difference is that it's running as a service, and the WebBrowser is not visible nor embedded in any forms. Could that fact possibly cause this error?
I currently have the winform application, the windows service, and the silverlight application's webservice all running on my own local machine.
UPDATE
After Gnostus' comments, I figured out that the main issue I'm having is that the "Page" object is not being created because the App class never gets initialized after navigating to the webservice from the windows service-based WebBrowser. The winform app and the service both do this the exact same way:
WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
WebBrowser.Navigate("http://localhost:56062/BingMapsWebServiceTestPage.aspx");
while (WebBrowser.ReadyState != WebBrowserReadyState.Complete)
System.Windows.Forms.Application.DoEvents();
I added some code to the MainPage's constructor where it calls HtmlPage.RegisterScriptableObject("Page", new MapControl(this.BingMap)); that will log some text when it gets hit. When I run the above code in the WebBrowser of the winform application, the following occurs:
The DocumentCompleted event gets fired twice (once by the browser and I assume once by the silverlight control)
The App() is intialized and the "Page" element successfully added in the MainPage's constructor
The above while loop completes
When I do the same from the windows service, it does #1 and #3, but not #2. Step 2 only gets hit when I call a javascript function that refers to the Page object, and only after it errors.
UPDATE 2
After messing around in a new winform application, I discovered that the silverlight control will fail to load upon calling Navigate() whenever the WebBrowser or its parent form is invisible. I found that it's possible to still call my javascript functions if the parent form is hidden AFTER the silverlight application has finished loading. Does anyone know a better way to force the silverlight app to load aside from flashing up a visible form? Is it even possible to show a form from a windows service, or am I going to have to rethink this whole thing as a console application?

How to launch a browser and later direct it to a page?

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

Categories

Resources