Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova - Deprecated attempt to access property 'userAgent' on a non-Navigator object

I'm trying to get my Cordova iPhone app working in iOS 8.1

Working fine in 7, since 8 I'm getting the following error:

Deprecated attempt to access property 'userAgent' on a non-Navigator object.

This is breaking the rendering of the app in page so I need a fix. I've taken a look at the various proposed solutions around the web but none seem to work.

Interestingly the error is coming from the JS retrieved from "https://maps.gstatic.com/maps-api-v3/api/js/17/17/main.js". --- perhaps part of the Google Maps API I'm trying to use?

Any help on the matter would be amazing!

Many thanks

Chris

like image 286
Chris Avatar asked Oct 30 '14 13:10

Chris


1 Answers

Which cordova version are you using?

That should be fixed now in the latest version, but if you don't want to update the project, you can change replaceNavigator function to be like this on the cordova.js file (the whole else is new)

function replaceNavigator(origNavigator) {
        var CordovaNavigator = function() {};
        CordovaNavigator.prototype = origNavigator;
        var newNavigator = new CordovaNavigator();
        // This work-around really only applies to new APIs that are newer than Function.bind.
        // Without it, APIs such as getGamepads() break.
        if (CordovaNavigator.bind) {
            for (var key in origNavigator) {
                if (typeof origNavigator[key] == 'function') {
                    newNavigator[key] = origNavigator[key].bind(origNavigator);
                } else {
                    (function(k) {
                        Object.defineProperty(newNavigator, k, {
                            get: function() {
                                return origNavigator[k];
                            },
                            configurable: true,
                            enumerable: true
                        });
                    })(key);
                }
            }
        }
        return newNavigator;
    }
like image 170
jcesarmobile Avatar answered Nov 12 '22 14:11

jcesarmobile