Run Apps Script code in a standalone web page

223 views
Skip to first unread message

Kovas Palunas

unread,
May 12, 2022, 11:20:14 PM5/12/22
to Google Apps Script Community
Hi all,

I'm interested in running the same javascript code both in Apps Script and on a standalone web page.  I feel like this should work given that Apps Script is just javascript, but I'm not sure how I would get access to the seemingly Apps Script specific product APIs on my standalone web page.  For instance, if my code wants to interact with Google Drive, I would use something like the code snippet at https://developers.google.com/apps-script/reference/drive in Apps Script.  Could I run that same code snippet in javascript on a standalone webpage?

Thanks in advance!

 - Kovas

Clark Lind

unread,
May 13, 2022, 8:56:42 AM5/13/22
to Google Apps Script Community
If you are trying to access Google services/APIs from an external source, this may be your best resource to start from:
https://developers.google.com/apps-script/api/quickstart/nodejs

Adam Gigstad

unread,
May 13, 2022, 11:43:27 AM5/13/22
to Google Apps Script Community
I think you're looking for https://developers.google.com/apps-script/guides/html/communication which shows how you can invoke functions from your Apps Script project from the client-side JS. Note that the functions are async though and don't look like they support promises out of the box, so you might have to add some promise wrappers if you don't want to do that nasty success handler stuff.

Kovas Palunas

unread,
May 15, 2022, 1:38:21 PM5/15/22
to Google Apps Script Community
I ended up using a function to branch my code to either call the apps script functions or call some other functions based on the runtime environment: https://github.com/kovasap/autojournal-on-gas/blob/fe8e80c358f0dce2e9852f8d2f6f7813b23008be/src/autojournal/env_switching.cljs#L3.

Andrew Roberts

unread,
May 16, 2022, 5:14:51 AM5/16/22
to google-apps-sc...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/23414435-2f6b-4c98-97ea-3cf80735dc31n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages