Reputation: 488
When I try to run the following extremely simple PhantomJS script, I get a parse error:
var page = require('webpage').create();
page.open('http://compare.nissanusa.com/nissan_compare/NNAComparator/TrimSelect.jsp', function (status) {});
Anyone know why this could be happening? The error message is not helpful at all... It just says "Parse Error".
Could this be a bug in PhantomJS?
I am using PhantomJS version 1.9. I'm able to run the above script with other URLs, but for some reason certain URLs return a parse error...
Any help would be greatly appreciated!
Upvotes: 4
Views: 1375
Reputation: 24558
It's simply because there is a javascript error on the web site http://compare.nissanusa.com/nissan_compare/NNAComparator/TrimSelect.jsp
. Parse Error
is not because of your code.
Phantomjs does not really loves js error when loading a page, that's why it's important to add an error handler.
To easily catch an error occured in a web page, whether it is a syntax error or other thrown exception, use page.onError.
Here is a basic example :
page.onError = function(msg, trace) {
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
});
}
console.error(msgStack.join('\n'));
};
Upvotes: 3