marcelduran/yslow — pull request #64 by naltatis (2013-01-26 21:57:16+00:00)
Title: phantomjs: onError handling for uncaught js error of the page

There was no way to prevent javascript error that are thrown on the page from being passed through:

```
$ phantomjs build/phantomjs/yslow.js --info basic http://jsbin.com/ubibep/1
TypeError: 'undefined' is not a function (evaluating '"foo".unknownMethod()')

http://jsbin.com/ubibep/1:18
{"w":53561,"o":89,"u":"http%3A%2F%2Fjsbin.com%2Fubibep%2F1","r":8,"i":"ydefault","lt":1210}
```

I've implemented the onError callback and made it work similar to the onConsoleMessage implementation. So by default (`--console 0`) all errors are ignored:

```
$ phantomjs build/phantomjs/yslow.js --info basic http://jsbin.com/ubibep/1
{"w":53561,"o":89, ...}
```

But the user has the option to output the errors with `--console 1` or `--console 2`:

```
$ phantomjs build/phantomjs/yslow.js --info basic --console 1 http://jsbin.com/ubibep/1
TypeError: 'undefined' is not a function (evaluating '"foo".unknownMethod()')
{"w":53561,"o":89, ...}
```

```
$ phantomjs build/phantomjs/yslow.js --info basic --console 2 http://jsbin.com/ubibep/1
{"message":"TypeError: 'undefined' is not a function (evaluating '\"foo\".unknownMethod()')","stacktrace":[{"file":"http://jsbin.com/ubibep/1","line":18,"function":""}]}
{"w":53561,"o":89, ... }
```

I've thought about adding a separate `error` option, but I think using the `console` option is sufficient. What do you think?

\ naltatis