1

I'm using Phantomjs to detect errors/warnings on my pages by hooking console messages :

page.onConsoleMessage = function(msg, line, source) {
   console.log(msg);
}

page.open(page.address, function (status) {
    if (status !== 'success') {
        console.log('Fail to load the address');
    } else {
        for(var i=0;i<page.errors.length;i++)
        {
            console.log(page.errors[i]);
        }
    }
    phantom.exit();
});

It works fine with the errors, but it does not record the warnings. By errors and warnings, I mean what Chrome console displays in red/yellow.

Is there a way to do it in PhantomJS or is it browser-dependant ?

Edit : updated code

3
  • This: page.errors[] = 'page logs ' + source + ':' + line + ' - ' + msg; is not valid JavaScript AFAIK. Commented Feb 11, 2013 at 22:55
  • Sorry, in fact I'm using console.log(msg), not page.errors[] .. Commented Feb 11, 2013 at 22:57
  • Just a guess, but you're iterating over page.errors. Have you tried page.warnings? Full disclosure: I know nothing of phantomjs Commented Feb 11, 2013 at 22:58

1 Answer 1

1

So after many research, it appears that the errors/warnings are browser-dependant (JS engine dependant to be exact).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.