Disable Closure code sanitization and minification for debugging

549 views
Skip to first unread message

eran wass

unread,
Apr 20, 2022, 5:20:04 AM4/20/22
to Google Apps Script Community
I am developing a google editor add-on in google sheets.
New menu item, open side bar with server side code (.gs) html and js (.html)... that sorta thing.

My code is large and each time there is an exception, i get the annoying:

Uncaught SyntaxError: Unexpected identifier (at userCodeAppPanel:formatted:25:NaN)

kind of messages in my chrome dev panel console in run time.

When i click the userCodeAppPanel link to find the location of the problem, it opens up an empty panel of code :

2022-04-20 12_10_31-.png
(even clicking the '{}' leaves it empty)

Now, from the many stackoverflow posts on the subject, i understand my client side html+js is sanitized and minified by "Closure" (used to be Caja?) and merged into some google js envelope code and because of this nothing remains of the original code function names and rows.

All the posts say: use 'debugger' or use 'console.log()' and print the s**t out of every method to help understand where the problems are.

We are at year 2022, can't google just provide a closure.disableAll() kind of method for dev phase so that we can develop normally and see the actual js exception locations in our code?

I include knockout and other libs and my code is large and sometimes just including new scripts causes exception at unknown locations in hundreds of lines of code...i can't put console logs every 10 lines,

Any solution is welcome. Thanks !

Clark Lind

unread,
Apr 20, 2022, 11:07:40 AM4/20/22
to Google Apps Script Community
With larger projects, you are better off using CLASP to clone a copy of your Apss script project and develop in VSCode or editor of choice. Much easier than trying to find anything in the "userCodePanel". 
When it is running good, then use CLASP Push to upload the new version.     Here is a good video on the topic if you need an overview.
Install via:   npm install @google/clasp              [note: add -g   to install globally]

You can also get the Apps script auto-complete with:
             npm i -S @types/google-apps-script

Reply all
Reply to author
Forward
0 new messages