4

I am having an issue with angular-mobile-nav on the very initial page load of Cordova 2.8 Android project using Ripple Emulator. The error I am getting is:

TypeError: Object #<Object> has no method 'overrideBackbutton'
    at module.exports.exec (chrome-extension://geelfhphabnejjhdalkjhgipohgpdnoc/ripple.js:40:22917)
    at backButtonChannel.onHasSubscribersChange (http://localhost:8076/cordova.js:1145:13)
    at Channel.subscribe (http://localhost:8076/cordova.js:667:49)
    at HTMLDocument.document.addEventListener (http://localhost:8076/cordova.js:132:34)
    at null.<anonymous> (http://localhost:8076/components/mobile-nav/mobile-nav.js:11:14)
    at Channel.fire (http://localhost:8076/cordova.js:709:23)
    at http://localhost:8076/cordova.js:232:47

Basically, it is cause by mobile-nav.js line 11:
document.addEventListener("backbutton", function() {

And error raised by cordova.js' call originating from line 1145:
exec(null, null, "App", "overrideBackbutton", [this.numHandlers == 1]);

Is this a problem that you can replicate? Any help would be greatly appreciated.

2 Answers 2

5

I first encountered this when using Ripple with Phonegap 2.5.0. As you point out, on line 1145 of cordova-2.8.0.js for Android, it assumes to be running on the Android platform so calls the native function App.overrideBackbutton() which Ripple doesn't have a stub for.

Since it only calls this on attaching/detaching the first handler, I worked around this by tricking Ripple into thinking there's already more than one handler:

<html>
    <head>
        <script type="text/javascript" charset="utf-8" src="cordova-2.8.0.js"></script>
        <script type="text/javascript" charset="utf-8" src="jquery-1.7.1.min.js"></script>

        <script type="text/javascript">
        _IS_RIPPLE_EMULATOR = $('#tinyhippos-injected').length > 0;

        function deviceready() {
            // Make ripple think that a back button handler has already been attached
            if(_IS_RIPPLE_EMULATOR) cordova.addDocumentEventHandler('backbutton'); 

            document.addEventListener("backbutton", function(){
                alert("Pressed back");
            });

        }
        document.addEventListener("deviceready", deviceready, true);        
        </script>
    </head>
    <body></body>
</html>
3
  • Yeah, I discovered it out of necessity ;-)
    – DaveAlden
    Jun 22, 2013 at 15:22
  • I found that the cordova.addDocumentEventHandler('backbutton'); command absolutely must be placed in the deviceready() function or it will not work Oct 5, 2013 at 13:46
  • 1
    I use phonegap 3.30 and the new (non-plugin) revision of Rippple, the detection method in this answer did not work for me but something very similar works var _IS_RIPPLE_EMULATOR = (window.tinyHippos != undefined); Feb 19, 2014 at 7:37
1

As of Ripple 0.9.22 this should no longer be an issue since App.exitApp and App.overrideBackbutton methods were added:

https://git-wip-us.apache.org/repos/asf?p=incubator-ripple.git;a=log;h=refs/tags/0.9.22

So, if possible update your version of Ripple, or resort to the workaround mentioned by Dpa99c.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.