Capturing page script errors
Errors that are generated within the scripts that are coded within the page.evaluate
method will not trigger phantom.onError
; however, the webpage
object's onError
callback will receive the event instead. The definition of the function is the same, except that we define our handling on the webpage
instance as shown in the following code:
var page = require('webpage').create(); page.onError = function(msg, trace) { console.log(msg); if (trace) { trace.forEach(function(t) { var stackmsg = ' at' + (t.function ? ' function ' + t.function : '') + ' (' + (t.file || t.sourceURL) + ':' + t.line + ')'; console.log(stackmsg); }); } };
Assume that we have the following code in our webpage
evaluate block:
page.open(url, function(status) { page.evaluate(function() { documentx.content = 1; }); });
As we see in the preceding code, we have a reference to an object named...