[Crash Reporting] Getting JS Stacktrace in Native

[Crash Reporting] Getting JS Stacktrace in Native


How do i get trace for javascript error which occur in native builds ( ios, android). JS error are shown in logs as
JS Error: error message

but crashlytics does not understand this as error. To log this type of error we tried to manually log error in
Scriptingcore.cpp’s js_log function as

  cocos2d::JniMethodInfo t;
  if(cocos2d::JniHelper::getStaticMethodInfo(t, "org/cocos2dx/javascript/Analytics", "flushCrashLogs", "()V"))
     t.env->CallStaticVoidMethod(t.classID, t.methodID);

and in flushCrashlogs we throw a non-fatal exception so the log is pushed to crashlytics.
but using this method we are not able to get stacktrace.
So can someone help us finding a better approach for tracking js error in native such that we can get stacktrace and local variable?

Thank you :smile:

1 Like

Have you tried the javascript onerror function?

can you post some reference for the onerror function?

@schngrg if you are talking about window.onerror method it is not working in Native mode.

Thank you.

This is an important feature to me as well, since most of the errors would come from JavaScript, instead of native code. Since they are not fatal and only logged to the console, currently there is no way to catch them and report them.

The SDKBOX plugins for Flurry and Apteligent are good for native error handling, but since the JS errors don’t throw such errors they are useless.

If cocos2d-js would send non-fatal exceptions with the stack trace and variables so that the application continues to run, but error reporting frameworks can catch them and report them back to us, this would help immensely with debugging and development.


Any news on this? It would be really helpful!

You may try this to get stack trace of JS errors.