h2p icon indicating copy to clipboard operation
h2p copied to clipboard

Handling with javascript errors

Open ilpaijin opened this issue 10 years ago • 2 comments

In case of a js error (on the page that phantomjs is trying to render) the converter returns the Exception but with success true and thus the page created.

I discovered the error within a page that uses "requestAnimationFrame" js object, and as far as I know Phantomsjs doesn't deal with it.

I'm working on handling the errors with phantomjs native handler like:

page.onError = function(msg, trace) {

    var msgStack = ['[ERROR]' + msg + " in " + page.url + "[/ERROR]"];

    if (trace && trace.length) 
    {
        msgStack.push('[TRACE]');
        trace.forEach(function(t) 
        {
            msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
        });
        msgStack.push('[/TRACE]');
    }

    returnConsoleMsg(msgStack.join('\n'), false);
};


function returnConsoleMsg(msg, result) 
{
    console.log(JSON.stringify({
        success: result,
        response: msg
    }));

    // Stop the script
    phantom.exit(0);
}

ilpaijin avatar Oct 12 '14 08:10 ilpaijin

Great!

I'll update the converter.js to handle these errors.

kriansa avatar Oct 31 '14 06:10 kriansa

I'm currently reworking in a new version of converter file to address this issue. Would you mind writing a test-case where our current build fails to parse a JS file, @ilpaijin ?

Thanks.

kriansa avatar Mar 24 '16 14:03 kriansa