6

I have a phonegap application that is throwing a javascript error. I have had the HTML page open in a browser on the desktop and it works fine there without any error. When I load it in the android emulator the window.onerror event is getting fired, but I can't see any useful information in the error object to see where it's coming from. I have this to try to get more out of the error object:

window.onerror = function(e){
    for(var i in e){
        console.log("window.onerror ::" + i + ' = ' + e[i]);
    }
};

But I don't even see a 'message' property. Here's the output:

window.onerror ::undefined
window.onerror ::eventPhase = 3
window.onerror ::currentTarget = [object DOMWindow]
window.onerror ::cancelable = false
window.onerror ::target = [object HTMLScriptElement]
window.onerror ::bubbles = true
window.onerror ::type = error
window.onerror ::cancelBubble = false
window.onerror ::clipboardData = undefined
window.onerror ::srcElement = [object HTMLScriptElement]
window.onerror ::defaultPrevented = false
window.onerror ::timeStamp = 1330975112077
window.onerror ::returnValue = true
window.onerror ::stopPropagation = function stopPropagation() { [native code] }
window.onerror ::preventDefault = function preventDefault() { [native code] }
window.onerror ::initEvent = function initEvent() { [native code] }
window.onerror ::stopImmediatePropagation = function stopImmediatePropagation() { [native code] }
window.onerror ::CAPTURING_PHASE = 1
window.onerror ::AT_TARGET = 2
window.onerror ::BUBBLING_PHASE = 3
window.onerror ::MOUSEDOWN = 1
window.onerror ::MOUSEUP = 2
window.onerror ::MOUSEOVER = 4
window.onerror ::MOUSEOUT = 8
window.onerror ::MOUSEMOVE = 16
window.onerror ::MOUSEDRAG = 32
window.onerror ::CLICK = 64
window.onerror ::DBLCLICK = 128
window.onerror ::KEYDOWN = 256
window.onerror ::KEYUP = 512
window.onerror ::KEYPRESS = 1024
window.onerror ::DRAGDROP = 2048
window.onerror ::FOCUS = 4096
window.onerror ::BLUR = 8192
window.onerror ::SELECT = 16384
window.onerror ::CHANGE = 32768

What else can I do to find the problem?

4
  • Well you can debug the code...? Commented Mar 5, 2012 at 19:54
  • I don't know, can I? I just installed eclipse - I've never used it or any other java tool before. Can you set a breakpoint in a javascript class with it or set it to auto break on any javascript exception? Commented Mar 5, 2012 at 20:02
  • It has been a while since I used eclipse, don't know... but in VS you can. =) Commented Mar 5, 2012 at 20:04
  • That'd be nice if I could use VS, but my laptop is just old enough that I can't get a video driver that supports the Windows Phone 7 emulator. There's not a way to attach VS to the android emulator, is there? Commented Mar 5, 2012 at 20:08

2 Answers 2

3

Now you can install Chrome for android and remote debug/analyze your application in the same way you would do with regular chrome:
http://code.google.com/chrome/mobile/docs/debugging.html

To install Chrome in the emulator:

it may take a while to install. Then follow the instructions to remote debug your web application

Sign up to request clarification or add additional context in comments.

4 Comments

I don't have the application deployed to a mobile device, just to the android emulator launched from eclipse. Does this apply to me?
Looks promising. I'll have to try it out.
btw I've seen people having problems with Chrome to work in the emulator, make sure you have the latest API updates installed, it would be probably best to try it on a real device if you have one available
This does not apply to Phonegap as far as I'm aware. According to that link your WebView has to be setup in a certain way to enable debugging and you must be using KitKat.
0

You're missing out as the error handler is actually passed multiple arguments, so you need to log those too.

For example,

window.onerror = function(e,f,g){
   console.log("window.onerror ", e, f, g);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.