Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

phantomjs: onError handling for uncaught js error of the page #64

Merged
merged 2 commits into from Jan 27, 2013

Conversation

Projects
None yet
2 participants
Contributor

naltatis commented Jan 26, 2013

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

marcelduran added a commit that referenced this pull request Jan 27, 2013

Merge pull request #64 from naltatis/master
phantomjs: onError handling for uncaught js error of the page

@marcelduran marcelduran merged commit ba61582 into marcelduran:master Jan 27, 2013

Owner

marcelduran commented Jan 27, 2013

good one! I've already updated the wiki page with new link for new release.
thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment