I'm using a technique I found here, to capture javascript errors for testing purposes. It's a technique that is frequently recommended on Stack Overflow for those who need to catch JavaScript errors on the fly, and it at least got me something I could work with.

The implementation is as follows:

My web dev put the following into a script called "error.js":

window.jsErrors = [];
window.onerror = function(errorMessage) {
    window.jsErrors[window.jsErrors.length] = errorMessage;

Which is getting loaded into the of every page, via an include.

I have a method set up to return the collected errors to my tests, as an array, like so:

public static Array JsErrorList(this IWebDriver driver)
        return ((IJavaScriptExecutor)driver)
            .ExecuteScript("return window.jsErrors.toString()")
        return new string[,] {};

When running my tests cross-browser, I've noticed something very odd. On Chrome(18) and Firefox(10) the only thing that ever gets reported back, is the string "Script error." IE(8) is the only browser that reports the actual JavaScript error text.

I wonder if the problem might lie in the way I'm invoking window.jsErorrs, but I'm not sure exactly. Could this be a problem with differences between the browser drivers? What has everyone else's experience been? If anyone has any suggestions, I'd surely be grateful.

My Environment:

  • Windows 7 (64bit)
  • .Net Framework 4.0.30319 (C#)
  • Visual Studio 2010 (10.0.40219.1)
  • Nunit 2.6.12051
  • C# WebDriver 2.20.0
  • InternetExplorerDriver
  • ChromeDriver 19
  • Firefox 10

1 Answer 1


Apologies to all for duplicating this question. Turns out, that indeed, the failing script in question lives on a separate domain than the place where my error.js was being included from. So, it was indeed a cross-domain trigger of "same origin".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.