Created
June 14, 2012 09:06
-
-
Save detro/2929203 to your computer and use it in GitHub Desktop.
Issues with Error reporting and Evaluation in PhantomJS upcoming 1.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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