12

I have issues with my client-side code (who doesn't, with any code they write in any language, at one point or another in the development process?) Problem is that I'm writing this code in Google Apps Script, and can't find the js code I am trying to debug/examine for errors. I remember being able to enter a function name, and then click on the returned code to go straight to the code file, and the function in it, but that, for some reason, isn't working here. I try it and this is what I get taken to:

what even is this?!

(I think Caja might have something to do with this...)

I think it's in some VM**** file, but I don't know much about that. How to access that JavaScript code to set some breakpoints?!

Rubén
  • 34,714
  • 9
  • 70
  • 166
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • 1
    This could be helpful: https://mogsdad.wordpress.com/2015/07/22/did-you-know-you-can-log-to-a-spreadsheet-from-client-javascript/ – Rubén Oct 20 '17 at 21:08
  • This is probably to simplistic but did you put console.log('MyCode') between the script tags. I do this so that I can get a link to my client side code on every refresh. – Cooper Oct 23 '17 at 18:02
  • 1
    Do Me a favor @Mike Warren, click on the `{}` in the above screenshot in bottom Left corner, then it will expand the javascript code. After code is expanded you can find in that file highlight in yellow the exact line in code that is the issue, then take screenshot again!!! – Nick Timmer Oct 24 '17 at 16:39
  • @NickTimmer I do that and it gives me [this](https://imgur.com/a/1MB5S) – Mike Warren Oct 24 '17 at 16:56
  • okay, hmm. so is there an error in the console tab or in the network tab? any more details about what the issue is? I don't see any issue with that line of code. – Nick Timmer Oct 24 '17 at 18:41
  • That's because that's Google Apps Script's code. The issue is that Google Apps Script is hiding my actual code behind that HTML. (That HTML comes with every Google Apps Script web app.) – Mike Warren Oct 24 '17 at 19:53
  • 2
    Hey @MikeWarren you can try the command "debugger" in your JS. Before execute the code leave the Developer tools oppened and it will stop in that place. – Jacobi Oct 26 '17 at 19:03

2 Answers2

7

From answer to how can I debug client side javascript (in html pages) in google appscripts

Unfortunately, there is no other good way to debug client side web UI other than with console logs. As you noted the JavaScript/DOM is re-written so you can't use standard Chrome debug tools.

Because of the above, consider using the approach suggested by Mogsdad on Did you know? (You can log to a spreadsheet from client JavaScript!): Write debugging logs to a spreadsheet.

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

what about 'debugger'?Write it in the code

Myxuan
  • 24
  • 1
  • Can I have an example use case, please? – Mike Warren Oct 27 '17 at 12:00
  • Something like this "worked for me"... `console.log(JSON.stringify(driveResultsArr)); debugger; console.log(driveResultsArr[0].get("fileName")); ` While it doesn't show me the code I wrote (my understanding is that it is "rewritten" by the server before being sent to the browser, via https://en.wikipedia.org/wiki/Caja_project ). But, I could type in commands in the debugger window to inspect variables, etc. – ELee Dec 12 '20 at 23:11