33

I am trying to debug what the cordova_plugins.json file is used for?

I am using multiple plugins so far and I have never interacted with this file. I want to figure out why cordova makes an xhr request for this file at initialization.

When looking at my console I keep seeing this 404 error every time I test my app in Chrome and like to understand why this file is necessary.

MSTdev
  • 4,149
  • 2
  • 18
  • 39
Eric H
  • 1,666
  • 3
  • 15
  • 17

8 Answers8

14

It seems like a feature introduced in Cordova 2.6.0, at least I just noticed in this version. At this point I could not find any documentation and I don't have many details on it, but right now I solved the 404 issue adding a dummy cordova_plugins.json file to the root of my project.

As it expects a valid json file I added the following content to the file: "just a dummy file required by Cordova 2.6.0"

Felipe Plets
  • 5,192
  • 3
  • 28
  • 47
11

It seems this is a know issue as discussed: here

Creating a dummy json file did not solved the problem for me... Indeed, remove this entire chunk of code at the end of cordova-2.7.0.js

// 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();
}

and replace it with a call to finishPluginLoading() will solve the problem.

Etienne Desgagné
  • 2,814
  • 1
  • 24
  • 35
  • Can you make your answer a bit clearer is not wel understood, replace `finishPluginLoading` where, and how. Can you be more specific ? – Lali Pali Jun 10 '13 at 16:17
  • 1
    @LaliPali, It's pretty clear. Delete that whole section of code and replace it with finishPluginLoading(); – Danation Jun 28 '13 at 15:32
  • One reason creating a dummy cordova_plugins.json doesn't work, at least on IIS 7 +, is that you have to explicitly add the MIME type mapping to IIS, or it will block the request. – Alan McBee Oct 01 '13 at 15:54
9

Filip Maj of Adobe has said elsewhere that this is due to (so far) partially implemented plugin tooling. In future versions of Cordova, the plugin tooling will generate cordova_plugins.json itself.

For now, he has said it's save to completely ignore the 404 error. If you feel it is affecting your application, you should file a bug with Cordova.

[Note that if you add a dummy file yourself, it may affect the integration of Plugins]

Black
  • 4,320
  • 5
  • 53
  • 75
6

i confirm francis answer and would note that on 2.7 if a dummy file is inserted, sometimes it starts an infinite loop on error "processMessage failed: invalid message:" (line cordova-2.7.0.js:971). keeping the 404 error seems indeed safer. (ref: https://groups.google.com/forum/?fromgroups#!topic/phonegap/slbvvtEw0aw)

netalex
  • 381
  • 3
  • 13
  • 2
    To get rid of the infinite loop, I had to remove the – tyler.frankenstein Jun 08 '13 at 23:27
2

That file did represent a bug/loose end in previous versions of Cordova/PhoneGap - and nurieta's suggested fix did resolve the (harmless) error thrown in its absence. The successor to this file is now created and handled by the Cordova/PhoneGap CLI entirely and resides in /myapp/platforms/#platform#/www/cordova_plugins.js

Bottom line - though the file sorta exists still this is no longer an issue as of Cordova 3.0.

1

I actually mock this file as an empty json file whose content is : "{}" and -using cordova 2.6- that seems to fix issues. There was not an ugly 404 and cordova seemed to work fine.

Edit: You can delete the code that does the ajax request all together from cordova and things would work just fine.

nurieta
  • 1,467
  • 12
  • 6
0

You can find out more about it here.

The location in the SDK / XDK is like: xdk-new\xdk\components\server\emulator\resources\cordova_plugins.json

Sascha Wedler
  • 375
  • 1
  • 7
-2

Are you using Sencha Touch?

You can ignore the error but if you want to package the app for iOS you wont be able to. I solved the issue by going back to cordova-2.5.0.js.

vLamp
  • 59
  • 1
  • 5