If I have this onOpen() setup for a Google Docs Add On:
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Edit Template', 'showSidebar')
.addToUi();
}
function showSidebar() {
const html = HtmlService
.createHtmlOutputFromFile("dist/addOn");
html.setTitle("DocsNData Template Editor");
DocumentApp.getUi().showSidebar(html);
}
and if dist/addOn.html contains this:
<html>
<head>
<script>
let x = `https://api.airtable.com`;
</script>
</head>
</html>
I get this error in the browser console when I try to launch the Add On:
userCodeAppPanel:3 Uncaught SyntaxError: Unexpected end of input
If I change the contents of the string so it's not a url, it works. This works in other words:
<html>
<head>
<script>
let x = `abc`;
</script>
</head>
</html>
So it's not the use of a template literal that is the problem.
In addition, referencing a URL as a normal string works, i.e. this is fine:
<html>
<head>
<script>
let x = "https://api.airtable.com";
</script>
</head>
</html>
So URLs in strings are not a problem, template literals are not a problem, its urls in template literals that are the problem. I have two questions:
- Why is this the case and whats the right corrective action?
- How do the line numbers reported in the error messages relate to my source?