6

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 to do this, I need to call function console.log.

The problem is, however, when running the application in simulator no debug info is displayed in XCode console... I am using phonegap version 0.9.3, what am I doing wrong?

Thanks for an answer

Lukas1
  • 582
  • 1
  • 5
  • 28
  • could you explain where is the information about console.log in the documentation? I can't find it – xus Oct 07 '11 at 16:58
  • Hello, I solved the problem by upgrading to higher version of phonegap. I've seen it in phonegap google group, but might be, the post is already removed by today. I recommend you to upgrade your code to new version of phonegap, there is even stable release out there finally – Lukas1 Oct 17 '11 at 13:31

3 Answers3

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.

elMarquis
  • 7,450
  • 4
  • 38
  • 42
3

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.

fil maj
  • 2,260
  • 16
  • 16
3

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.

Francesco Frapporti
  • 5,195
  • 4
  • 32
  • 39