I am working on a phonegap based project. I\'d like to use some debug tools, to be able to debug some variables etc into XCode console, etc. Now, I\'ve found, that in order
Lukas, there is a fantastic tool you can use to debug your phonegap project.
With iWebInspector you basically have Firebug for your Phonegap Application. You can even live-change the code.
This feature was completed very recently (two days ago), and is not included in the 0.9.3 release. You can see this ticket in the issue tracker for more information.
To get this working, you have to pull the latest code from the PhoneGap GitHub repository. From a shell:
$ git clone git://github.com/phonegap/phonegap-iphone.git
... and then go about building up the source from scratch. You should see it then!
Alternatively, you replace your console.log
statements with debug.log
, and that will work in 0.9.3.
Paste the following somewhere near the start of your document so that it gets executed before any of your other JavaScript.
<script type="text/javascript">
window.onerror = function(message, url, lineNumber) {
console.log("Error: "+message+" in "+url+" at line "+lineNumber);
}
</script>
And enjoy viewing details of your Javascript errors in the Xcode console window.
UPDATE: The above technique will log errors such as undefined variables. But syntax errors such as missing commas will still cause the entire script to break without logging anything.
Therefore you should add the following to the start of your onDeviceReady function:
console.log('Javascript OK');
If you don't see "JavaScript OK" appearing in your log window when the app launches, then it means you have a syntax error somewhere.
To save hunting for missing commas, the easiest thing is to paste your code into a Javascript validator such as this one:
http://www.javascriptlint.com/online_lint.php
and let it find the error for you.
Hopefully that takes some of the pain out of debugging.