Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Native Browser duplicating HTML5 canvas (fine in chrome)

This is a weird issue that I am only experiencing on a Native browser on Samsung Galaxy Tab 2 and Galaxy S2 in the native browser.

This has also been tested on other android phones and tablets such as the Nexus 7 & Galaxy S4 but their native browser is chrome, so it appears fine. This issue is also not present on any IOS browsers, Windows Desktop browsers or Mac Desktop browsers.

It's almost asif the webpage is loaded twice ontop of itself!

As there is a duplicate canvas element, that updates as the main canvas does.

enter image description hereenter image description here

Here it appears asthough it only happens when rotated in landscape mode, but I beleive that in portrait mode, the canvas' are perfectly aligned over the top.

What is even weirder, the menu button that you see is a toggle button, tap to open menu, tap to close menu. On this device when you tap it, it opens and closes instantly. the same happens for the mute button toggle.

I'm completely at a loss.

I have done some javascript debugging throwing in a few alerts here and there, and the initialisation functions that create references to the canvas and so on are only called once.

I have read and heard about hardware acceleration causing issues, but solutions i've potentially found are only relative to building native apps! not HTML5 Canvas webpages.

Any insight on this could be would be great! Thanks in advance.

--EDIT

I also put in this test alert(document.getElementsByTagName('canvas').length); to see if there was 2 canvas in the DOM but it returns 1!

like image 897
rorypicko Avatar asked Aug 16 '13 11:08

rorypicko


4 Answers

I ran into this same issue. I was able to fix this by running the following code after making a change to my canvas:

// If Samsung android browser is detected
if (window.navigator && window.navigator.userAgent.indexOf('534.30') > 0) {

    // Tweak the canvas opacity, causing it to redraw
    $('canvas').css('opacity', '0.99');

    // Set the canvas opacity back to normal after 5ms
    setTimeout(function() {
        $('canvas').css('opacity', '1');
    }, 5);

}

By tweaking the opacity, this forced the canvas to redraw and removed the duplicate shapes. It's a dumb fix but it works. Hopefully this helps someone.

like image 112
rickdmer Avatar answered Nov 13 '22 07:11

rickdmer


Also you may look at this collections of such tips: http://slash-system.com/en/how-to-fix-android-html5-canvas-issues/

like image 33
lavrton Avatar answered Nov 13 '22 08:11

lavrton


For double canvas issue there is a bug logged https://code.google.com/p/android/issues/detail?id=35474 you may want to check suggested solutions.

In my case this issue appeared only if I had Force GPU rendering enabled.

Issue usually appears if you have some parent element for canvas that has CSS overflow: hidden

like image 1
darkyndy Avatar answered Nov 13 '22 09:11

darkyndy


remove overflow property from all canvas parents,probably we don’t need this property on touch devices:

$("canvas").parents("*").css("overflow", "visible");

It is well explained at http://slash-system.com/en/how-to-fix-android-html5-canvas-issues/

like image 1
Ankit Chaudhary Avatar answered Nov 13 '22 09:11

Ankit Chaudhary