I'm thinking about new JavaScript errors API which would work by overwriting 
`window.errors` hook and provide a way to retrieve JS errors from page.

So, for example. I enable errors catching:

 ```ruby
Watir.catch_errors = true
```

Then, we add JavaScript (using `#execute_script`) like the one below in the 
manner we run checkers (after going to url, refreshing page, clicking on 
elements).

```js
window.jsErrors = [];

// make sure we run other callbacks
var callback;
if (window.onerror != null) {
  callback = window.onerror;
} else {
  callback = function () {};
}

// catch errors
window.onerror = function (msg, url, line) {
  var error = {};
  error.msg = msg;
  error.url = url;
  error.line = line;
  window.jsErrors.push(error);
  return callback();
}
```

After, we can retrieve array of hashes with error details by using

```ruby
Watir.errors
#=> [{ :message => "error", :url => "google.com", :line => 25 }]
```

There are several concerns however:

1. It would be better if we could only add script after page load (or 
significant DOM change). I'm not sure if that's possible to do. @jarib Can we 
get this info from Selenium-WebDriver?
2. I'm not completely sure about API methods naming. Use `errors` or 
`js_errors` or `javascript_errors`.
3. Performance impact. I suppose we can make it faster by using 
`Driver#execute_async_script`, but I haven't yet experimented.

Let me know what do you guys think.

---
Reply to this email directly or view it on GitHub:
https://github.com/watir/watir-webdriver/issues/191
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to