Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
This appears to be related:… – user246 Mar 16 '12 at 1:23
You're quite right. I was searching for the wrong things. Thanks for pointing this out. – Greg Gauthier Mar 16 '12 at 12:22
up vote 3 down vote accepted

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".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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