How to prevent script error in C# webbrowser? - javascript

I am getting script error in loading some web sites.
Please help me how to prevent script error in C# WebBrowser.
This is my code:
try
{
webBrowser1.Navigate(textBox1.Text);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
MessageBox.Show("Loaded");
}
catch(Exception)
{
MessageBox.Show("failed");
}

Write this in Your Code
webBrowser1.ScriptErrorsSuppressed = true;

To disable the script error pop up, you need to go to (in Internet Explorer) Tools->Internet Options, there go to the Advanced tab, and in Browsing select Disable Script Debugging (Other), but, the problem may be related to the fact that every site loaded in the WebBrowser control is rendered in IE7 compatibility mode, to solve this the only thing you can do is a registry hack like this: WebBrowser control to use IE9

change your registry to 2af8 which is IE 11 for devenv.exe
software/Microsoft/internet explorer/main/featurecontrol/feature_Browser_emulation

If your working with a GUI (like in Visual Studio) just go to the Webbrowser Properties and set "ScriptErrorsSuppressed" = true

It is easy to see how this error has been eliminated. But Visual Studio uses Internet Explorer and another Web Browser coding is hard. If you look at the versions, the last Visual Studio one uses IE 11 for WebBrowser tool.
The C++ GUI is recommended for one of each encoding:
https://msdn.microsoft.com/en-us/library/60k1461a.aspx

Related

How to run exe or bat file with JavaScript [duplicate]

I have following javascript code to run notepade.exe:
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
function executeCommands()
{
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun ="C:\WINDOWS\notepad.exe";
oShell.ShellExecute(commandtoRun,"","", "open", "1");
}
</SCRIPT>
The problem is that, when i run the script then it give error..."Permission denied."
Can anybody help me on this matter?
It's necessary to have two settings turned on.
Enable unsigned ActiveX controls for the current zone
Tools > Internet Options > Security > Custom level...
Enable "ActiveX Controls and plug-ins" > "Initialize and script ActiveX controls not marked as safe for scripting"
Allow Active Content to run files
Tools > Internet Options > Advanced > Security
Enable "Allow Active Content to run in files on My Computer"
** Make sure to close all your IE browser windows.
You may experience a "Permission denied" error, which means that the browser will not let script execute outside the "sandbox". Try solving the issue by changing a security setting in the browser:
Internet Options, Advanced, Security:
"Allow Active Content to run in files on My Computer"
The above is for IE, but most browsers have similar options.
Okay, weirdly, I had this issue when running a .html file I'd created on my desktop into IE... but when I moved the file onto a WAMPServer it worked okay; Not quite sure why that should solve the problem, but maybe that'll help someone!?

Edge Browser - iframe.document.open not working

We have some functionality for exporting data to an excel file.
When the 'export' button is clicked, some client-side javascript is called, firstly checking the client browser version, and based on this, deciding which way to render the excel document.
It is working in Chrome & Firefox & IE11 when tested locally.
However, when I remotely test using a windows 10 machine running Edge browser, the excel is not rendered.
I might add that my local machine is a Win7 machine and Im running VS2012 and IE11. The remote machine is Win10 with Edge, hence the need to test remotely.
I've tried the emulation in IE11 F12 dev tools but cant replicate the Edge error there.
An error of 'undefined or null reference' is thrown for 'open' when using the following code:
excelIFrame.document.open("txt/html", "replace");
excelIFrame.document.write(sHTML);
excelIFrame.document.close();
excelIFrame.focus();
excelIFrame.document.execCommand("SaveAs", true, "Spreadsheet.xls");
The iframe exists in the html and is not added dynamically.
<iframe id="excelIFrame" style="display:none"></iframe>
I have tried the following possible solutions to get this working, to no avail -
Possible Solution 1: Same 'undefined or null reference error when assigning the document to a temp var
var doc = excelIFrame.document;
doc.open("txt/html", "replace");
doc.write(sHTML);
doc.close();
doc.focus();
doc.execCommand("SaveAs", true, "Spreadsheet.xls");
Possible Solution 2: Using the contentWindow property of the iFrame. No error thrown, it just opens 'about:blank' containing no content.
excelIFrame.contentWindow.contents = sHTML;
excelIFrame.src = 'javascript:window["contents"]';
Totally at a loss with this at this stage.
The page is an angularJS web page.
From reading up on it, I'm aware the document.open is problematic in edge when using iframes. But the following link document.open fails in an iframe I felt would solve the problem.
Any thoughts or suggestions greatly appreciated.
This may be helpful to others who are searching for it.
//For Edge browser ….. U have to write separate logic for each browser
if (ua.match(/Edge/)){
var blob = new Blob([sHTML], {type: 'data:application/vnd.ms-excel'});
window.navigator.msSaveBlob(blob, "P2P_Report_"+new Date().getTime()+".xls");
}

Windows Phone 8 IE10 Javascript debugging

IE10 has some wonderful enhancements in the HTML5 compliance area but remains a bear to develop JavaScript HTML5 when running on the WP8 as there is no way to debug the app except console messages.
Is there a remote debugging experience available for IE10 running on WP8 like the WebKit phone browsers have(see my video at http://www.youtube.com/watch?v=GNAjzFpNEj4 for example). When this is in place with a USB cable to desktop Safari debugging Javascript apps on IOS is easy as breakpoints can be set and variables examined in the remote debugger . I am hoping the same capabilities are in IE10 and would appreciate any information on where to enable these very much needed capabilities.
The bad news, that there is no new debug capabilities in comparison to WP7/IE9. Please take a look on How do I debug Internet Explorer on Windows Phone 7? since we are in exactly the same situation on WP8.
What I personally use on daily basis
Debug your app in IE10 Desktop as much as possible
Weinre remote debugger. Demo video. You can use the following app based on Weinre to simplify its usage (no local setup needed) - IeMobileDebugger src or link to Store
Supports
Html traversing
Html node styles, properties, metrics
Reading console output
Executing js on device side from console (including intellisense)
Dynamic script injection - ability to debug live sites
Not supported
js breakpoints
For javascript line by line debugging use aardwolf. Demo with VS integration.
To redirect console trace to Visual Studio output and be able to use console.log("some message") for tracing
index.html:
<script type="text/javascript">
window.console = {
log: function (str) { window.external.Notify(str); }
};
// output errors to console log
window.onerror = function (e) {
console.log("window.onerror ::" + JSON.stringify(e));
};
console.log("Installed console !");
</script>
MainPage.xaml.cs
private void Browser_Loaded(object sender, RoutedEventArgs e)
{
Browser.IsScriptEnabled = true;
// Add your URL here
Browser.Navigate(new Uri(MainUri, UriKind.Relative));
Browser.ScriptNotify += (s, arg) =>
{
Debug.WriteLine(arg.Value);
};
}
FWIW: Windows Phone 8.1 finally supports remote debugging. See http://blogs.msdn.com/b/visualstudioalm/archive/2014/04/04/diagnosing-mobile-website-issues-on-windows-phone-8-1-with-visual-studio.aspx
While not a full solution, Lauri Piispanen's consolelog.js, a nodejs-based remote JS console logger could help you.

javascript error while recording a web test with Visual Studio 2010 recorder

I'm currently recording Web Performance Tests using Visual Studio 2010.
The recorder is working fine except for a javascript that is triggered in a popup (fckEditor file manager).
When editing HTML content in fckEditor, we can add an hyperlink. Clicking on the link tool open a popup with a file browser on the server. All files are displayed as hyperlink with a onsubmit event:
OpenFile(fileUrl); return false;
The OpenFile function fails at the following line:
window.top.opener.SetUrl( fileUrl ) ;
The following error is thrown:
SCRIPT5007: Unable to get value of the property 'SetUrl': object is
null or undefined frmresourceslist.html, line 92 character 2
This error only appears when recording with MS Recorder. Following the exact same steps on IE without the Recorder on is working fine.
Does anyone had the same type of issue?
As per MSDN:
A downside to this recording method is that it can fail to record
requests made by JavaScript (for example, on AJAX sites), ActiveX
controls, and some types of pop-up windows, since Internet Explorer
does not always raise the necessary events. In most cases, these
problems can be solved by manually adding the missed requests back
into the Web test, as described later in this document.
http://msdn.microsoft.com/en-us/library/ms364082(v=vs.80).aspx
Even if this documentation is intended to Visual Studio 2005, I believe that it is still valid for VS 2010.
you can solve this by making parse dependent Requests property = false for every single request and
you can make some custom web plugin test so you can generalize this property for all the requests

How do you avoid the drop-down ActiveX warning in IE7 and IE8?

I am currently using javascript to enable changes to css on hover for certain items in my html page. In Firefox I never get an ActiveX message but in IE8 I get a message stating "To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer. Click here for options..." I'm assuming its because of the javascript I have:
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
The hover effects still work in IE8 without me clicking on the warning and allowing ActiveX.
My questions are:
1) Is there a way for me to change the javascript I have in place for the hover effects so the ActiveX warning doesn't pop up?
2) Is there code to disable the ActiveX warning since the website works fine in IE even with the warning?
Thank you
That's the default security restriction when you open it by local disk file system instead of by webserver. In other words, it won't occur when you change the security restrictions in the browser configuration or serve it by a (local) webserver like http://localhost/test.html
In Firefox I never get an ActiveX message
ActiveX is MSIE proprietary, you indeed won't ever see this on browsers other than MSIE.
You can try this if it work :
Add this to your ASPX code.
<!doctype html>
<!-- saved from url=(0023)http://www.contoso.com/ -->
It happens only when you work with local files, if it still bothers you, check this out: http://msdn.microsoft.com/en-us/library/ms537628(VS.85).aspx

Categories