Google Apps Script HTML scriplets trucates JSON object containing URLS when using

1 week ago 5
ARTICLE AD BOX

I'm running into an interesting issue with Google Apps Script HTML scriplets where a JSON object is being strangely truncated directly before the double forward slashes of a URL (//) on the client side.

Server-side Apps Script code (with some random data):

const template = HtmlService.createTemplateFromFile('pageName'); template.data = JSON.stringify({"time": "2026-02-03T12:40:00.000Z", "name": "T'Challa", "profileUrl": "https://stackoverflow.com/users/23479790/brodblox09"});

Server-side HTML code:

<script> fillPageWithData(<?!= data ?>); </script>

In the client-side code on a web browser after publishing the web app, the client receives the following:

<script> fillPageWithData({"time": "2026-02-03T12:40:00.000Z", "name": "T'Challa", "profileUrl": "https: </script>

What can I do to ensure all of the data I want to send to the client via scriplets is correctly received/not truncated? Why do these scriplets get truncated?


I have discovered that if there is any code on the same line as the line with the scriplet, all of the code after the scriplet is completely removed:

Server-side HTML code:

<script> fillPageWithData(<?!= data ?>); console.log("Hello world!"); </script>

Received by client:

<script> fillPageWithData({"time": "2026-02-03T12:40:00.000Z", "name": "T'Challa", "profileUrl": "https: </script>

If there is no apostrophe before the URL (1), or if the apostrophe appears after the URL (2), there is no issue:

Server-side Apps Script code (1):

const template = HtmlService.createTemplateFromFile('pageName'); template.data = JSON.stringify({"time": "2026-02-03T12:40:00.000Z", "name": "BrodBlox09", "profileUrl": "https://stackoverflow.com/users/23479790/brodblox09"});

Received by client (1):

<script> fillPageWithData({"time": "2026-02-03T12:40:00.000Z", "name": "BrodBlox09", "profileUrl": "https://stackoverflow.com/users/23479790/brodblox09"}); </script>

Server-side Apps Script code (2):

const template = HtmlService.createTemplateFromFile('pageName'); template.data = JSON.stringify({"time": "2026-02-03T12:40:00.000Z", "profileUrl": "https://stackoverflow.com/users/23479790/brodblox09", "name": "T'Challa"});

Received by client (2):

<script> fillPageWithData({"time": "2026-02-03T12:40:00.000Z", "profileUrl": "https://stackoverflow.com/users/23479790/brodblox09", "name": "T'Challa"}); </script>
Read Entire Article