ReferenceError: URL is not defined

1,390 views
Skip to first unread message

Paul Armstrong

unread,
Mar 6, 2022, 3:44:23 PM3/6/22
to Google Apps Script Community
Inside of a Google Workspace Add-on, I am trying to use a URL class as follows:
new URL("https://google.com");
But this throws a ReferenceError: URL is not defined

If the code ran in the user's Browser, this would not happen. But server-side in Google's walled garden and this class is not present.

If this was Java, I'd make sure the class was on my path (in a .jar) and import it.
what is the best solution in google-apps-script? 

Thank you!
 

Clark Lind

unread,
Mar 7, 2022, 8:47:32 AM3/7/22
to Google Apps Script Community
If you are developing a Workspace add-on (Gmail, Calendar, Drive), you are limited to using the cards and cardservice. If you are making an Editor add-on (Sheets, Docs, Slides, Forms), then you might be able to do what you want while serving HTML.
Otherwise, you should still be able to use the built-in UrlFetchApp instead of creating your own Class.

Paul Armstrong

unread,
Mar 8, 2022, 3:27:00 AM3/8/22
to Google Apps Script Community
Thank you!
That is a perfect solution. Plus, it also explains the scope of what is possible and what is not.  
Reply all
Reply to author
Forward
0 new messages