Phantomjs page.onConsoleMessage doesn't log wa

2019-06-02 11:19发布

问题:

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

回答1:

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