Permalink
Browse files

add a default error handler on all pages. people can override if they…

… need.
  • Loading branch information...
1 parent 989aa9f commit e9121c1f5ac962543cc732d0655abe9aa20d3d17 @jonleighton committed Mar 15, 2012
Showing with 6 additions and 4 deletions.
  1. +4 −4 src/bootstrap.js
  2. +2 −0 src/modules/webpage.js
View
8 src/bootstrap.js
@@ -60,17 +60,15 @@ function require(name) {
phantom.__defineSetter__('onError', function(f) {
if (handler) {
- try {
- signal.disconnect(handler);
- } catch (e) { console.log("got error") }
+ try { signal.disconnect(handler) } catch (e) {}
}
handler = f;
signal.connect(f);
})
})();
// TODO: Make this output to STDERR
-phantom.onError = function(error, backtrace) {
+phantom.defaultErrorHandler = function(error, backtrace) {
console.log(error + "\n");
backtrace.forEach(function(item) {
@@ -80,5 +78,7 @@ phantom.onError = function(error, backtrace) {
})
}
+phantom.onError = phantom.defaultErrorHandler;
+
// Legacy way to use WebPage
window.WebPage = require('webpage').create;
View
2 src/modules/webpage.js
@@ -123,6 +123,8 @@ exports.create = function (opts) {
defineSetter("onError", "javaScriptErrorSent");
+ page.onError = phantom.defaultErrorHandler;
+
page.open = function (url, arg1, arg2, arg3, arg4) {
if (arguments.length === 1) {
this.openUrl(url, 'get', this.settings);

0 comments on commit e9121c1

Please sign in to comment.