Google Scripts are awesome as a multitude of different business applications can be built on top of them. Therefore it's great that you can also use them inside Universe Pages.

This article assumes you are familiar with Google Script.

Google Script needs 3 things to work with Pages. 1st you need to have a built UI for the script. 2nd you need to set the doGet(e) function output with setXFrameOptionsMode(). 3rd you need to publish the script. Lets go through the details below.

1. Build a Google Script UI

For this section, please refer to the Google Script documentation about UIs here: https://developers.google.com/apps-script/guides/html/

2. setXFrameOptionsMode to ALLOWALL

By default the HTML output is not allowed to be embedded. To fix this, you need to set the HtmlService output to allow embedding. Below is short snippet to allow this.

function doGet(e) {  
  var output = HtmlService.createTemplateFromFile('form');
  return output
       .evaluate()
       .setSandboxMode(HtmlService.SandboxMode.IFRAME)
       .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

3. Publish the script

Publish the script from the top navigation bar under "Publish". From here select the "Deploy as web app". Set the necessary settings and grab the Current web app url from the form, its the one starting with https://script.google.com/macros/s/...

Now you can add a new iframe widget to your Universe Pages, copy the web app url as the source and you are all set!

Did this answer your question?