October 29, 2010

Android bug: "Miss a drag as we are waiting for WebCore's response for touch down."

I'm using Phonegap to port an HTML5 iPad app over to the Android platform. On my development HTC Incredible phone, every time I swipe my finger far enough, my app would freeze, and the adb debugging console would give me this error: "Miss a drag as we are waiting for WebCore's response for touch down." I researched a bunch and didn't find any solutions. I did find the Java code that logs this error in the core Android WebView.java class, but it didn't give me any clues to fix it.

I searched and hacked, and removed all my touch event listening code, and it would still break. Luckily the company work for has the resources to invest in development, and we went out and got a Samsung Galaxy S phone. I set the device up, published the app, and this phone did not have the cryptic issue! It did, however, show a range of other issues with fonts and the <canvas> object, which made me sad, as it's clear that building an HTML5-based app for Android isn't as easy as I hoped. The fragmentation of the Android platform is definitely an issue if you're attempting complex UI design and interaction with HTML/Javascript. I recommend keeping your HTML5 app very simple if you're targeting multiple Android platforms. Even though all new Android devices use Webkit, there are plenty of small, ugly differences.

[UPDATE]: The following code, when removed from my project, got rid of this weird error:
document.ontouchmove = function(event) {
    event.preventDefault();
};

Another update... Check out this post, and try out the demo code to get a bit more idea about how to handle preventDefault() on touch events in the Android browser: http://code.google.com/p/android/issues/detail?id=4549. It still crashes on my HTC device, but works great on the Samsung device.

4 comments:

  1. I have been having similar issues with HTC Evo & Incredible.

    This is the signal of death:
    Miss a drag as we are waiting for WebCore's response for touch down

    As a consequence of this I see various rendering & scrolling issues.

    I've tried a bunch of hacks top work around this issue. For rendering I force trigger a reflow and it seems to makes it work. But the basic problem is you never know when webkit flakes at the javascript layer and this makes it a tough problem to solve.

    ReplyDelete
  2. Thanks for posting this, Justin. I've been struggling with the same issue.

    @khivi: You mentioned that you force trigger a reflow.. could you explain how you do this? Do you dispatch a touch-end event after a certain X/Y distance has been made?

    ReplyDelete
  3. preventDefault prevents native scrolling use this shim instead : https://github.com/TNT-RoX/android-swipe-shim

    ReplyDelete
  4. Shim for this bug at https://github.com/TNT-RoX/android-swipe-shim

    ReplyDelete