Effective way to debug a Google Apps Script Web App

Viewed 7169

I have had some experience writing container-bound scripts, but am totally new to web apps.

How do I debug (e.g. look at variable values, step through code etc) a web app? In a container bound script it was easy, because I could set breakpoints, use the apps script debugger - how do I go about this in a web page e.g. when I execute a doPost?

3 Answers

So, for me, I debug the front-end using inspector, I haven't found a way to step through code yet, but you can use 'debugger' in your javascript (along with console.log) to stop the code and check variables.

to debug the backend, what I've been doing is to write my functions like

function test_doSomething(){
  payload = "{item1: 100, item2: 200}"  //<- copy paste from log file
  backend_doSomething(payload)
}
function backend_doSomething(payload){
  Logger.log(payload)
  params = JSON.parse(payload)
  ...
}

Then after refreshing your project on the backend, you can look at executions, grab the payload from the log file, and paste it into your test_doSomething() function.

From there, you are re-creating the call that you want to debug and you can run that, stepping through the backend code as usual.

Related