Is there a way to retrieve the line number from an Internet Explorer 7/8 error object?
I'm only aware of the .message, .description and .number properties.
I've searched around a bit and found an MSDN article on .stack ( http://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx ), but even using their own example code doesn't return a line number:
http://jsfiddle.net/LWevS/
I dug around some more and found that it is possible to retrieve the line number in IE using window.onerror. It's not from the Error object itself, but it's a decent workaround:
function BadFunction(){
This.badcode.willnot.work = 1000
}
function ForceError(msg, url, lno) {
alert("Error Occurred! Handled by Generic Error Handler" + "\n" +
"Error: " + msg + "\n" + "URL: " + url + "\n" +
"Line Number: " + lno);
return true;
}
window.onerror = ForceError;
This method requires that the error bubble up to the window. If you have a try/catch in your code, you will need to re-throw the error so it can bubble up.
I also came across StackTraceJS on GitHub while researching a solution to this problem. Their stack tracing script works great on all browsers except for Internet Explorer. A great run-time debugger if you want to log errors produced on the client browser.
http://stacktracejs.com/
Related
I am trying to write an automated test program for one of my website using Selenium WEbDriver. I am having some problems when doing the test on Internet Explorer. The website that I am trying to test is built in AngularJS. I will explain my problems in detail.
Here, is the code that waits until Angular has finished processing.
private static ExpectedCondition angularHasFinishedProcessing() {
return (ExpectedCondition<Boolean>) driver -> {
String hasAngularFinishedScript = "var callback = arguments[arguments.length - 1];\n" +
"var el = document.querySelector('html');\n" +
"if (!window.angular) {\n" +
" callback('false')\n" +
"}\n" +
"if (angular.getTestability) {\n" +
" angular.getTestability(el).whenStable(function(){callback('true')});\n" +
"} else {\n" +
" if (!angular.element(el).injector()) {\n" +
" callback('false')\n" +
" }\n" +
" var browser = angular.element(el).injector().get('$browser');\n" +
" browser.notifyWhenNoOutstandingRequests(function(){callback('true')});\n" +
"}";
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
assert javascriptExecutor != null;
String isProcessingFinished = javascriptExecutor.executeAsyncScript(hasAngularFinishedScript).toString();
return Boolean.valueOf(isProcessingFinished);
};
}
private void waitForAngular() {
WebDriverWait wait = new WebDriverWait(driver, 15, 100);
wait.until(angularHasFinishedProcessing());
}
And here is the code that instantiates WebDriver for Internet Explorer.
System.setProperty("webdriver.ie.driver",
new File("H:/libraries/webdrivers/IEDriverServer.exe").getAbsolutePath());
DesiredCapabilities d = DesiredCapabilities.internetExplorer();
// To bypasse the Protected Mode settings of IE
d.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(d);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://arandomangularjsapp.com"); // Let's suppose this
I had to bypass the Protected Mode settings (shown in above code) because I was constantly getting this Exception
Caused by: org.openqa.selenium.WebDriverException: Unexpected error launching Internet
Explorer. Protected Mode must be set to the same value (enabled or disabled) for all
zones. (WARNING: The server did not provide any stacktrace information)
though I made sure that protected mode was enabled and same values were set for all zones.
Now comes the real issue I am having. Look at this block of code,
waitForAngular();
WebElement el = driver.findElement(By.xpath("//div[#class='events-list__event-info' and #id='48040']" +
"//following-sibling::div[#class='events-list__event-buy']/a"));
if(driver.toString().toUpperCase().contains("INTERNETEXPLORER"))
el.sendKeys(Keys.ENTER);
else
el.click();
waitForAngular();
webElement = driver.findElement(By.xpath("(//div[#class='ticket u-cf ng-scope'])[1]//select"));
select = new Select(webElement);
select.selectByIndex(1);
My first question, the way I am trying to wait for Angular app to get ready by calling waitForAngular(), is it a good way? In my program I even had to use Thread.sleep() so many times in order to let elements to properly render before I could invoke actions on them. It would be great if you guys can suggest me a proper way to use Selenium WebDriver along with Angular App.
Now let's talk about my second issue. I had to completely disable Protected Mode from Internet Explorer's options in order to run the program. Otherwise, I would get this exception,
Caused by: org.openqa.selenium.JavascriptException: JavaScript error in async script. (WARNING: The server did not provide any stacktrace information)
I get this exception when trying to execute waitForAngular(). What could be causing this? Is there any way by which I could keep the Protected Mode enabled and still be able to execute that script inside angularHasFinishedProcessing() method?
Finally, my third problem is related to click action not being triggered. Forget about the previous issues for a second. I disabled IE's Protected Mode, so my program starts IE without throwing any exception. The program successfully finds the first element as shown in the code above. But, the click action is not triggered, browser thus doesn't navigate to next page, and the program fails to find the second element. As a workaround I even tried el.sendKeys(Keys.ENTER); but it didn't work.** So, am I having this problem because I bypassed/disabled Protected Mode? Or, is there something else that I am not being able to see?**
I run tests on IE, Opera, Chrome and Firefox and the problem seems to occur only in IE. Any sort of help, suggestions or guidelines are highly appreciated.
Thank You.
At the moment I have the below code on a website
*global escape: true */
var twitterHandle = "Handle";
function tweetCurrentPage() {
return window.open("https://twitter.com/share?url="+escape(window.location.href) + "&text=" + document.title + " via #" + twitterHandle, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600"), !1;
}
Internet Explorer F12 Debugger at the moment throws up the following error.
The value of the property 'tweetCurrentPage' is null or undefined, not a Function object.
Works fine on Chrome, Safari and Edge but not on IE11 nor Firefox - any help would be appreciated. I have put the code through various online bug checkers and so on. Only error they have come up with is Function is not called... but I call the function in other ways.
So I am trying to handle an error when I attempt to open a file location in windows explorer from SharePoint. If the website is not in your trusted sites while in IE the browser will throw an Access is Denied error. I have this written and working but my problem is that my catch is running every time. I am assuming it's something very simple but through a good amount of research I haven't been able to figure anything out.
View_Click: function ($event) {
var clickedFolder = $scope.Folders[$event.$index];
var absoluteLibraryUrl = "file://" + location.host + "/DavWWWRoot" + _spPageContextInfo.webServerRelativeUrl + "/" + clickedFolder.Title;
try {
window.open(absoluteLibraryUrl);
}
catch (e) {
alert("Please Add clientportals.sdcpa.com to your trusted sites, in order to use open with explorer funtionality.");
}
}
I hope this is something simple..
I am using the F12 Development tool debugger in IE 9. Is there a way I can display the line numbers and file source for each console statement, the same way that Firebug displays this info? I may have overlooked something basic, but I haven't yet found a way to do this..Thanks!
The only way to get line numbers is to define a window.onerror method:
window.onerror = function (message, url, lineNo)
{
console.log('Error: ' + message + '\n' + 'Line Number: ' + lineNo);
return true;
}
console.log(window);
console.log(1=2);
But even then, IE breaks on the error, so it's rather useless.
I create an error message its working with IE and Mozila.
Not woking with Safari, Chrome and Opera.
But I need to use it. Please give me right way for doing it.
<script language="javascript" type="text/javascript">
window.onerror = function(msg, url, line)
{
document.write("Message\t = "+msg + "<br/>Location\t = " + url + "<br/>Line No.\t = " + line + "<br/>Error No.\t = " + this.err.number);
}
this.err = Error(12,"My Own Error");
throw this.err;
</script>
==========================================
Internet Explorer:
My Error
Message = My Own Error
Location = http://localhost/practice/JavaScript/window.errors.php
Line No. = 8
Error No. = 12
================================================
Mozilla FireFox:
My Error
Message = Script error.
Location = My Own Error
Line No. = 0
Error No. = undefined
=====================================================
Safari, Chrome, Opera:
My Error
look the code Mozilla give wrong information. what I do?
Opera doesn't support window.onerror at all. Chrome supports it, but not on errors that you throw yourself. This is also true of Internet Explorer when using Error objects other than Error(), e.g. TypeError(). Chrome also doesn't provide the line and file arguments.
You should correctly catch any exceptions you're going to throw with a try...catch statement, instead of relying on window.onerror.