Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError "Cannot set property connection of #<Navigator>" in console when upgrading project to latest version of Cordova 4.0.0

Today, I upgraded Cordova-CLI from version 3.5 to version 4.0. After this, I updated a project's platform support to the latest version of Android (since they get updated separately now).

Ever since then, I get this error showing up whenever I run cordova run android, I get the following error:

Uncaught TypeError: Cannot set property connection of # which has only a getter at file:///android_asset/www/cordova.js:512

As a result, a lot of events in the app don't get run, causing that app to not work.

like image 581
Josh Tumath Avatar asked Oct 20 '14 12:10

Josh Tumath


2 Answers

I started getting this after updating Cordova but only on very old Android phones. As a workaround I put a try/catch block around the contents of the function generating the error (clobber) in cordova.js :


    function clobber(obj, key, value) {
      try {
        exports.replaceHookForTesting(obj, key);
        obj[key] = value;
        // Getters can only be overridden by getters.
        if (obj[key] !== value) {
            utils.defineGetter(obj, key, function() {
                return value;
            });
        }
      }
      catch (e){
        console.error('clobber error '+e+', obj='+JSON.stringify(obj)+', key='+JSON.stringify(key)+', value='+JSON.stringify(value));
      }
    }

This obviously isn't the best fix but at least it lets the initialization complete and seems to not be affecting my app.

like image 63
John kendall Avatar answered Nov 09 '22 19:11

John kendall


I met the same problem with Android cordova 3.6.4 got via CLI 4.1.2. I tried to merge two fixing of the issue:CB-7868. The first fixing can be saw with the link CB-7868,https://github.com/apache/cordova-js/pull/88. The second fixing is on the comment on CB-7868.

See *************

function clobber(obj, key, value) {

exports.replaceHookForTesting(obj, key);

obj[key] = value;
var needsProperty = false;
try { obj[key] = value; }
catch (e) { needsProperty = true; }
// Getters can only be overridden by getters.
if (obj[key] !== value) {
   if (needsProperty || obj[key] !== value) {
       utils.defineGetter(obj, key, function() { return value; }
 );

With those two fixing. There is no error reported on Android API14(4.0) and API15(4.0.3). But, I didn't try if the related plugins can work not. It means I don't know if the fixing is right or not.

Also, I got cordova 3.7.0 via CLI 4.1.2 for IOS platform. I can see the fixing, https://github.com/apache/cordova-js/pull/88, has been applied on 3.7.0 JS. But, the function ,clobber, still haven't above fixing. Also, there is no available 3.7.0 for Android cordova. It is still 3.6.4 for Android platform.

like image 36
Joe Avatar answered Nov 09 '22 19:11

Joe