Uncaught Reference error: Connection is not defined - PhoneGap



Download Brave Browser


Uncaught Reference error: Connection is not defined


If you receive this error in phonegap when using the below code:

    var networkState = navigator.connection.type;
    var states = {};
    states[Connection.UNKNOWN] = 'Unknown';
    states[Connection.ETHERNET] = 'Ethernet';
    states[Connection.WIFI] = 'wifi';
    states[Connection.CELL_2G] = '2G';
    states[Connection.CELL_3G] = '3G';
    states[Connection.CELL_4G] = '4G';
    states[Connection.CELL] = 'No GPRS';
    states[Connection.NONE] = 'Not internet connection detected';
    alert('Connection type: ' + states[networkState]);

The solution is simple!

1)In windows, start your Node.js command promt(type node.js in the search bar), right click and use as administatrator.

2)Navigate to your app path ie:
C:\xampp\wwww\myproject\

3)Type this in your command prompt:
npm install -g cordova-plugin-update


4)Type this in your command prompt(after the above command):
cordova-plugin-update

This little application will check all your plugin updates one by one and will ask you if you want to update them, you can either update everything one by one or go to:
cordova-plugin-network-information

And make sure it is at least above the version 2.0.0

Now you code should work without any error.


If this tip helps you please leave us a message below!