1

How can i see javascript errors from within a Phonegap App?

Currently I am trying to use this:

window.onerror = function(msg, url, linenumber) {
    console.error('Type: ' + typeof msg + '\nError message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
    return true;
};

But nothing shows up on screen or in weinre I am using.

Nurdin
  • 23,382
  • 43
  • 130
  • 308
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • Very smart :) Down votes without an explanation or view of helping the problem. – Jamie Hutber Mar 30 '14 at 16:04
  • What version of PhoneGap are you using? And are you trying to test this through a device or emulator? – Andrew Lively Mar 31 '14 at 02:05
  • window.onerror only works on iOS. I think the js errors appear on the logcat without doing anything special – jcesarmobile Mar 31 '14 at 07:58
  • @AndrewLively Both emulators and 3 different devices, all v4.x.x @jcesar I had inittially been using `console.info` but switched to `.error` to see if it made a difference. I think I may have missed the logcat completely. I will do some googlging when I get to work, unless you want to suggest something for me :D – Jamie Hutber Mar 31 '14 at 08:33
  • I use window.onerror and it does what it is supposed to on Android. Did you try use console.log instead of console.error? Usually that will allow me to write to logcat. – Andrew Lively Mar 31 '14 at 10:55
  • Andrew is right, window.onerror works on android too, I was wrong. But you won't see anything on the screen (unless you use alert instead console), the console.log, .error or .info are displayed on the logcat. But even if you don't use window.onerror, the js errors are displayed on the logcat too – jcesarmobile Mar 31 '14 at 11:17

0 Answers0