Is there any debugger for Google Ads-scripts?

502 views Asked by At

I write my first *.gs file of Google Ads-script.

Is there any IDE or environment where I can add breakpoints or see the variables state?

I saw only logger printing, but that's not efficient to work with.

I have tried @Andrew's reply, but didn't manage:

enter image description here

2

There are 2 answers

3
Tom On BEST ANSWER

You can place dots in next to the line numbers and then click on the little bug icon, like displayed on this image.

enter image description here

This will open this debug screen:

enter image description here

2
Neilord On

you can use this function.

For example: MyLogger("test");

function MyLogger(s,d=true,w=800,h=400,t=5) {
  const cs=CacheService.getScriptCache();
  const cached=cs.get("Logger");
  const ts=Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "MM|dd|HH:mm:ss")
  if(cached) {
    var v=Utilities.formatString('%s<br />[%s] - %s',cached,ts,s);   
  }else{
    var v=Utilities.formatString('[%s] - %s',ts,s);
  }
  cs.put("Logger",v,t);
  //allows logging without displaying.
  if(d) {
    const a='<br /><input type="button" value="Exit" onClick="google.script.host.close();" />';
    const b='<br /><input type="button" value="Exit" onClick="google.script.host.close();" /><br />';
    SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(b+v+a).setWidth(w).setHeight(h), 'My Logger');
  }
}

(To view logs open spreadsheet with your script)