laurentj / slimerjs

A scriptable browser like PhantomJS, based on Firefox
http://slimerjs.org
Other
3k stars 258 forks source link

phantom.onError does not catch errors in timers #406

Open jlfwong opened 9 years ago

jlfwong commented 9 years ago

Repro Script:

// test.js
phantom.onError = function(err) {
    console.log('onError: ' + err);
    phantom.exit(1);
};

console.log('pre');
setTimeout(function() {
    x();
}, 0);

Expected behaviour:

$ slimerjs test.js
pre
onError: x is not defined
$ echo $?
1

Here's the actual behaviour with phantomjs:

$ phantomjs test.js
pre
onError: ReferenceError: Can't find variable: x
$ echo $?
1

Actual behaviour:

slimerjs test.js outputs pre, then hangs.

laurentj commented 8 years ago

Note to fix the issue: we should probably "listen" messages sent to the gecko console API, so we can intercept asynchronous javascript error messages.

wskorodecki commented 8 years ago

I don't know how to do it. I have tried to hide errors by enabling the debugger: https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XULRunner/Debugging_XULRunner_applications#Browser_Debugger

but with no success. Errors are still not being catched by debugger, although the debugger is working and intercepting some other messages (normally invisible without the debugger) like:

Full message: TypeError: self._socket is null
Full stack: SocketListener.prototype.open/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/security/socket.js:414:7

I need to catch all JS errors, because my application is using timers very often.

DavidKk commented 7 years ago

i use websocket but i can not catch any error after open callback, only system.stderr can, but it includes some warn and a lot xmlhttprequest information. and phantom.onError can not catch any error which in some async function

and --debug=no or false was always trun on debug mode, document say that value is \<bool>?

version: Innophi SlimerJS 0.10.3, Copyright 2012-2017 Laurent Jouanneau & Innophi system: osx