Phonegap - Javascript debugging in Xcode - javascript

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

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.

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.

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.

Related

JavaScript execution throws "Error: OLE Automation error in eval: Unknown name or named argument." in wx.html2.WebView on MSW

I’m developing a cross-platform GUI app for Mac and Windows using wx.html2.WebView, using the latest wxPython 4.1.1. (Hint: The problem started appearing in 4.1. Earlier wxPython versions, as well as the wxPython 4.1.1 for Mac, don’t have that problem, but I’m trying to migrate to the latest wxPython for various benefits it has)
The Windows app throws an error message Error: OLE Automation error in eval: Unknown name or named argument. when executing some JavaScript on WebView.RunScript().
I honestly don’t know where to start debugging. I can’t find out what JavaScript code caused the problem since the code isn’t displayed anywhere. I tried throwing in a confirmation dialog before each RunScript() call, but the execution doesn’t wait, and instead, the dialogs pile up over each other.
As the JavaScript code gets generated by the app on runtime, I did route all JavaScript code into a file and syntax-checked it externally, without errors.
The only result that shows up in Google search for that error message is this page: https://trac.wxwidgets.org/ticket/17893?cversion=2&cnum_hist=10 and the discussion hints at a custom protocol being used, which I’m not using, so it seems irrelevant.
Any ideas?
Don't know the reason behind, but I have solved the same error by adding an <script></script> element into the page contents. That is, for instance, replacing:
self.browser = wx.html2.WebView.New(self)
self.browser.SetPage('<p>Hello World!</p>')
with this:
self.browser = wx.html2.WebView.New(self)
self.browser.SetPage('<p>Hello World!</p><script></script>')

What does it mean in Chrome's dev tools when a js file's link starts with debugger?

I'm trying to diagnose a JavaScript issue in an ASP.Net website that I didn't write. I've loaded Google Chrome's development tools and run the function that isn't working and am getting an error that says:
Uncaught TypeError: jQuery.clean is not a function
When I click on the error in the debugger it is showing me a file which is obviously knockout.js. I believe the issue is that we have upgraded jQuery to a new version that no longer contains the .clean function. This much isn't that interesting just background to my question.
I'm trying to figure out where Chrome has got knockout.js from so that I can upgrade it. However when I look at the location of the knockout.js file it is telling me it has come from debugger:///VM830. That is clearly not part of the site. I have tried right clicking on 'Empty Cache and Hard Reload' but it is still showing as coming from the same place. My question is what is the debugger:///VM830 location and where might it actually come from?
Looks like our "quality" code is downloading knockout.js as an XHR request and then executing the response using eval().

applescript: do javascript fails on OSX10.8.4?

After OSX 10.8.4 update, this small script stopped working
tell application "Adobe Photoshop CS6"
do javascript "alert('hello world')"
end tell
Can anyone confirm it's a change in AppleScript syntax introduced in last updated,
or I'm missing something?
Can your reproduce this script on OSX 10.8.4?
The exact error I get is:
Syntax error
Expected end of line but found identifier.
And JavaScript is highlighted.
I just struggled with a similar problem in Illustrator CC on 10.8.5 for a few hours.
I was running the script through a shell command in a .sublime-build file (Sublime Text 2).
Running the same basic script once from the official AppleScript Editor subsequently fixed it.
I still need to investigate why. If you have an idea, please comment.
I think the problem your experiencing is due to the fact that you have to specify a tab for applescript to run the JS code in. For example:
do JavaScript "alert('Hey');" in tab 1 of front window
If you don't specify which tab to run the javascript code in, it always throws the same 'identifier' error.
Hope this helps. (I've been frustrated by this one myself. It's easy to forget)
--Sorry, just realized you were talking about Illustrator. My mind immediately went to Safari's 'do javascript'.

How do you debug IE & jQuery errors like this

I'm developing in Javascript for quite a long time now. Usually when I hit an error in IE I know roughly where it originated even if the message received from IE is useless bunch of text. When I don't know where the error originated, I usually try to "delete" parts of my code, until the error doesn't repeat itself, and that start manually checking line by line until I find the error.
I'm sure that it's far from the best approach, so I'd like to ask you how you debug error like these:
If you are using IE8+, you can press F12 on a page to open the Developers Tools.
This contains a JavaScript debugger, much like Firebug & Chrome Dev Tools
EDIT:
In response to the comment under the question, if IE is throwing a cryptic error that you are unsure of, there is a couple of steps I would do.
Is it an IE only error? Does the same error occur in Firefox? Chrome?
Is the error occurring in a 3rd party library. If you believe it is, use an un-minified version of the library.
Can you replicate the error outside of your website? Can you make the error occur in a http://jsfiddle.net/ for instance?
If you still can't narrow down the issue, post a question on SO with your code, any error messages, and expectations of the result.
HTH
Try using non-minified version of jQuery - it will give you a better idea where exactly the error is. Also, if you use VS 2010 to debug your js code in IE, it will break at the error line. This always works fine for me.
IE is the only browser that I've managed to successfully use the fantastic Visual Studio script debugger with - in my experience Visual Studio is hands down the best script debugger out there, so quite often I find myself in the reverse situation to you (running broken scripts in IE just so I can use the script debugger)
See How to debug JavaScript in Internet Explorer for instructions on how to use Visual Studio Express to debug scripts in IE - if you own a full edition of Visual Studio then its much simpler (just attach to IE as normal).

Microsoft Script Debugger does not display any information after error

I'm trying to debug a Javascript error which only occurs in Internet Explorer. I have Microsoft Script Debugger installed, and have used it successfully in the past. On this error, though, I select "Yes" to do-you-want-to-debug?, and it opens up Script Debugger, which displays nothing. Running documents window is empty, call stack is empty, as though nothing is being debugged.
Can anyone tell me what causes this?
I've had these sorts of issues before with the Microsoft Script Debugger but never managed to find a solution - if you have a license the script debugger inside Visual Studio 2008 is far far better.
There is an article here about how you can use VS 2008 Express (free) as a script debugger.
I've seen this issue with code inside a try/catch/finally block--for some reason the debugger gets confused by the finally block. Try commenting them out.
I know this is old but I thought I would point out that this is still an issue. Microsoft plain sux. Developers are being forced to support products that are broken....this is a crime

Categories

Resources