1

Is there a way to catch javascript errors in Casperjs?

I've written a script for Casperjs to crawl a website and look for javascript errors of each page. Actually, I would like to catch all the javascript errors thrown by the JavaScript engine. As an example, for the following script:

<script src="http://example.com/a/image.jpeg"> </script>

Since JavaScript engine cannot interpret a jpeg file as a js file, it throws a syntax error in my browser console.

In order to catch such errors in Casperjs, I've tried remote.message, page.error, and resource.error handlers, but none of them works. remote.message only catches console.log, page.error should be fired in case of existing any uncaught js error but is not fired for the above example.

Would you please give me some hints on any other handlers or options that I can use to catch such errors?

2
  • This seems like a case of PhantomJS where nothing can be done about it. Do any of the event handlers change when you try an actual image url? Have tried to add the type attribute to the script tag so that PhantomJS knows it is supposed to parse it as JavaScript?
    – Artjom B.
    Jan 10, 2015 at 19:35
  • These are the list of event handlers I used:
    – Alex
    Feb 17, 2015 at 20:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.