Why does Cordova 2.7.0 JS seemingly no longer work on remote pages?

10,284

Solution 1

Yes, something broke in 2.7 - related to our cordova-cli work. See: https://issues.apache.org/jira/browse/CB-3029

The fix is to add an empty file called "cordova_plugins.json" in your root folder.

Solution 2

I had a similar problem relating to upgrading to Cordova 2.7. However my problem was all my console.logs stopped firing when running the app. I couldn't figure out why for the life of me this was happening. I thought it was because I upgraded jquery.mobile. That wasn't it. I then thought it was an .htaccess issue, that wasn't it either. It turns out, it was Cordova 2.7 that was causing this problem.

I did try adding the .json file on my server, that did not fix the issue.

The fix was going into the 2.7 source and commenting out the following code:

/*comment out this as it is breaking console.logs
    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();
    */

Replace entire block with a call to the following function:

finishPluginLoading();

My logs are now working again. Only took me 3 days scratching my head.

Hope this helps someone with a similar problem.

Share:
10,284
Charlie Gorichanaz
Author by

Charlie Gorichanaz

I'm a software engineer with a bachelor of biochemistry degree from the University of Wisconsin-Madison.

Updated on July 19, 2022

Comments

  • Charlie Gorichanaz
    Charlie Gorichanaz almost 2 years

    Background

    I'm attempting to upgrade an iOS app built on Cordova 2.0 to version 2.7.

    It's basically a welcome screen that points to a remote search engine (please withhold comments about app validity and likely approval, as we're past that), and we were using the ChildBrowser plugin to enable opening links in a sub browser so as not to trap the user in the Cordova webview.

    Cordova 2.7 has a feature called InAppBrowser I am hoping to use instead of ChildBrowser. InAppBrowser does essentially the same thing, aside from missing a button to open in Safari.

    Problem

    The existing app's remote webpages include the Cordova JS (as well as that for the ChildBrowser plugin) and it works fine for opening links in the sub browser.

    My test Cordova 2.7 app doesn't seem to load the Cordova JS correctly when it's being loaded from a remote web page.

    I tried using this exact same HTML on the embedded start page and a remote start page:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <script type="text/javascript" src="http://mydomain.com/mobile/cordova-2.7.0.js"></script>
      </head>
      <body>
        <script>
          document.addEventListener("deviceready", onDeviceReady, false);
          function onDeviceReady() {
            alert("Ready!!");
          }
        </script>
      </body>
    </html>
    

    To test this as the embedded start page, I put this line in config.xml:

    <content src="index.html" />
    

    When I run the app, I promptly get the "Ready!" alert.

    To test this as the remote start page (I'm aiming to link to the remote page in the final app, I am just using it as the start page for testing. The result is the same if I link from the embedded page.), I put this line in config.xml:

    <content src="http://mydomain.com/mobile/index.php" />
    

    When I run the app, I just get the blank screen and no alert.

    Further, in cordova-2.7.0.js L. 6255, I changed

    console.log('deviceready has not fired after 5 seconds.');
    

    to

    alert('deviceready has not fired after 5 seconds.');
    

    With that change, running the app using the remote start page causes the blank page, and then after five seconds, I get the alert "deviceready has not fired after 5 seconds.". So this tells me Cordova JS is not starting correctly. Needless to say, I can't get InAppBrowser to launch links in the sub browser on the remote site, but I can get it working just fine on the embedded start page.

    Anyone have any ideas of where to go from here? This is a pretty simplistic example, so I'm assuming this is a Cordova settings problem or a change in the functionality. I appreciate any thoughts, thanks!

  • Charlie Gorichanaz
    Charlie Gorichanaz about 11 years
    This doesn't sound right. Why would this be a problem now, when Cordova JS loaded fine on the remote webpages with version 2.0 and the Cordova plugin ChildBrowser worked fine as well?
  • Charlie Gorichanaz
    Charlie Gorichanaz about 11 years
    Further, I just tested with 2.6 instead of 2.7 and it works as I want it to. Something broke in 2.7 apparently.
  • Charlie Gorichanaz
    Charlie Gorichanaz about 11 years
    Thanks, I went the route of replacing code block with call and it worked fine for me! Thanks so much!
  • asgeo1
    asgeo1 about 11 years
    Adding cordova_plugins.json didn't work for me. I also commented out the section in cordova.js (as per your link) and that worked.
  • jjsquared
    jjsquared about 11 years
    Actually, I spoke too soon. This didn't correct my console.log issue. Any idea why 2.7 would break console.log output in Chrome?
  • Jacksonkr
    Jacksonkr about 11 years
    This got rid of the error where the script was looking for cordova_plugins.json but I'm still getting "deviceready has not fired after 5 seconds."
  • ChuckE
    ChuckE about 11 years
    me too, I'm getting that using the Riddle Chrome Extension.
  • Nassif
    Nassif about 11 years
    I tried all the above supports to sort out the same issue,but no hope.i tried the adding the empty cordova_plugins.json,Tried with linking the ref of cordova-2.7.0.js to local host 10.2.0.108:8000/mobile/cordova-2.7.0.js,also tried the comment option.
  • Nassif
    Nassif about 11 years
    I tried all the above supports to sort out the same issue,but no hope.i tried adding the empty cordova_plugins.json,Tried with linking the ref of cordova-2.7.0.js to local host 10.2.0.108:8000/mobile/cordova-2.7.0.js,also tried the comment option.