Skip to content

Instantly share code, notes, and snippets.

@detro
Created June 14, 2012 09:06
Show Gist options
  • Save detro/2929203 to your computer and use it in GitHub Desktop.
Save detro/2929203 to your computer and use it in GitHub Desktop.
Issues with Error reporting and Evaluation in PhantomJS upcoming 1.6
var p = require("webpage").create(),
pErrorCount = 1,
pConsoleMsgCount = 1;
p.onError = function(error, stack) {
console.log((pErrorCount) + " - ON PAGE ERROR: "+JSON.stringify(error)+"\n");
console.log((pErrorCount++) +" - ON PAGE ERROR STACK: "+JSON.stringify(stack)+"\n");
};
p.onConsoleMessage = function(msg) {
console.log((pConsoleMsgCount++) +" - ON PAGE CONSOLE MESSAGE: "+msg+"\n");
}
p.open("http://www.google.com", function(status) {
p.evaluate("console.log('first message'); "); //< ERROR + NO STACK
p.evaluate(function() { console.log('second message'); }); //< NO ERROR
p.evaluate("fakeFunction(); "); //< ERROR + NO STACK
p.evaluate(function() { fakeFunction(); }); // ERROR + STACK (YEAH!)
p.evaluate("setTimeout(function(){ fakeFunction(); }, 200); "); //< ERROR + NO STACK
p.evaluate(function() { setTimeout(function(){fakeFunction(); }, 200); }); //< ERROR + STACK (YEAH!)
});
setTimeout(function() {
phantom.exit();
}, 3000); //< to give the test time to finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment