You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Andrew Grieve (JIRA)" <ji...@apache.org> on 2013/05/02 16:56:16 UTC

[jira] [Comment Edited] (CB-3029) remote page loading 2.6.0 cordova js file not work

    [ https://issues.apache.org/jira/browse/CB-3029?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13647590#comment-13647590 ] 

Andrew Grieve edited comment on CB-3029 at 5/2/13 2:55 PM:
-----------------------------------------------------------

Yep, this was certainly a regression from 2.6. 
We added in the following code:
{code} 
    // Try to XHR the cordova_plugins.json file asynchronously.
    try { // we commented we were going to try, so let us actually try and catch
        var xhr = new context.XMLHttpRequest();
        xhr.onload = function() {
            // If the response is a JSON string which composes an array, call handlePluginsObject.
            // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
            var obj = this.responseText && JSON.parse(this.responseText);
            if (obj && obj instanceof Array && obj.length > 0) {
                handlePluginsObject(obj);
            } else {
                finishPluginLoading();
            }
        };
        xhr.onerror = function() {
            finishPluginLoading();
        };
        xhr.open('GET', 'cordova_plugins.json', true); // Async
        xhr.send();
    }
    catch(err){
        finishPluginLoading();
    }
{code} 

When loading over HTTP, onload is called with status==400 and responseText with an error page. JSON.parse then throws and the surrounding try/catch doesn't apply since it's in a callback.

As a work-around for 2.7, you can delete this entire chunk of code, and replace it with a call to finishPluginLoading(). The code is used only when using cordova-cli. Another work-around is to just create an empty file in your www/ called "cordova_plugins.json".
                
      was (Author: agrieve):
    Yep, this was certainly a regression from 2.6. 
We added in the following code:

    // Try to XHR the cordova_plugins.json file asynchronously.
    try { // we commented we were going to try, so let us actually try and catch
        var xhr = new context.XMLHttpRequest();
        xhr.onload = function() {
            // If the response is a JSON string which composes an array, call handlePluginsObject.
            // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
            var obj = this.responseText && JSON.parse(this.responseText);
            if (obj && obj instanceof Array && obj.length > 0) {
                handlePluginsObject(obj);
            } else {
                finishPluginLoading();
            }
        };
        xhr.onerror = function() {
            finishPluginLoading();
        };
        xhr.open('GET', 'cordova_plugins.json', true); // Async
        xhr.send();
    }
    catch(err){
        finishPluginLoading();
    }


When loading over HTTP, onload is called with status==400 and responseText with an error page. JSON.parse then throws and the surrounding try/catch doesn't apply since it's in a callback.

As a work-around for 2.7, you can delete this entire chunk of code, and replace it with a call to finishPluginLoading(). The code is used only when using cordova-cli. Another work-around is to just create an empty file in your www/ called "cordova_plugins.json".
                  
> remote page loading 2.6.0 cordova js file not work
> --------------------------------------------------
>
>                 Key: CB-3029
>                 URL: https://issues.apache.org/jira/browse/CB-3029
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: BlackBerry, iOS
>    Affects Versions: 2.6.0
>         Environment: tested on ios including iphone and ipad; on blackberry, reported this error: TypeError:'undefined'is not an object
>            Reporter: Andy Downton
>            Assignee: Andrew Grieve
>             Fix For: 2.7.0
>
>
> My app loads remote page containing cordova js file; it works fine with 2.5.0 and previous version, however, after upgrading cordova js file to 2.6.0, all app functions broken, no deviceready fired at all and other app functions stop working. this bug affects only remote page loading cordova js file on ios and blackberry, local page works fine. I only tested on iphone, ipad and blackberry, not sure if this issue affects other OSs.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira