I ran into a sneaky bug in a recent Cordova app I was building. It would run fine on Android and iPhone but when I tried to run it on an iPad, it would crash. And it was a sneaky crash as well. Nothing out of the ordinary in the Apple Console app and the errors thrown in the Safari console were all about plugins not being defined.
The actually HTML and CSS ran fine, just all the plugins came back undefined.
Doing so gave me the super descriptive error alert of “Error: Script error Script: Line: 0”
ons.ready(onDeviceReady); (I am using the Onsen UI template for this particular app)
This got me thinking, maybe there is an issue with Onsen…
So I changed
document.addEventListener('deviceready', onDeviceReady, false);
This time when I ran the app there were no errors, but
deviceready never gets called and that plugins are undefined must mean that Cordova is not being added to the project when being run on an iPad…
So I added
<script src="cordova.js"></script> into the
<head> of my index.html and it worked!!
The only issue is for all the other devices where things had been working I now have an error about Cordova already being imported, but it doesn’t actually cause any issues at this point so I am considering this a win.