3

I saw this article Secure, Offline, Cross-Platform Apps with Salesforce Mobile SDK and Web Components and found it very interesting, when I try the sample application Heroku Hosted Version of the Canonical Sample App on Chrome on the desktop it works fine, but when I go to the same page with Chrome on an Android phone (I tried 2 different phones) I get a blank page.

Using Chrome remote debugging tool I can see that the error occurs in cordova.force.js, full error below:

Exception caught during observer callback: ReferenceError: Connection is not defined
at Object.deviceIsOnline (https://sfdc-sobject-editor.herokuapp.com/dependencies/mobilesdk-shared/libs/cordova.force.js:164:45)
at Object.SFDC.isOnline (https://sfdc-sobject-editor.herokuapp.com/elements/force-app/force-app.js:31:85)
at force-ui-search.Polymer.computeQuery (https://sfdc-sobject-editor.herokuapp.com/elements/force-ui-search/force-ui-search.html:53:22)
at force-ui-search.g.invokeMethod (https://sfdc-sobject-editor.herokuapp.com/dependencies/polymer/polymer.js:13:25932)
at force-ui-search.g.notifyPropertyChanges (https://sfdc-sobject-editor.herokuapp.com/dependencies/polymer/polymer.js:13:24037)
at Object.x.report_ (https://sfdc-sobject-editor.herokuapp.com/dependencies/polymer/polymer.js:12:18266)
at Object.S.check_ (https://sfdc-sobject-editor.herokuapp.com/dependencies/polymer/polymer.js:12:22604)
at c (https://sfdc-sobject-editor.herokuapp.com/dependencies/polymer/polymer.js:12:12173)

the line giving an error in cordova.force.js is the first return line below:

    if (typeof connType !== 'undefined') {
        // Cordova's connection object.  May be more accurate?
        return (connType && connType != Connection.NONE && connType != Connection.UNKNOWN);
    } else {
        // Default to browser facility.
        return navigator.onLine;
    }

1 Answer 1

0

This only works on the Android WebView, not Android Chrome. Android Chrome has navigator.onLine but not window.Connection, which is a Cordova object.

The new code fixes the existence check:

    if (typeof connType !== 'undefined' && window.Connection) {
        // Cordova's connection object.  May be more accurate?
        return (connType && connType != Connection.NONE && connType != Connection.UNKNOWN);
    } else {
        // Default to browser facility.
        return navigator.onLine;
    }
};

Android 2.2 introduces the navigation.connection interface but it does not work properly in WebView. So in order to get the proper connection information we had to implement our own connection interface which is accessible at navigator.network.connection.

References

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .