google-apps-scriptweb-applicationsgoogle-sitesx-frame-options

Apps Script Refused to Connect


I am trying to learn Apps Script and some fron-end web dev. I wrote some some code in Apps Script and I am trying to render it in a Google Site.

Here is the doGet function that I use in my Apps Script:

function doGet() {
  var template = HtmlService.createTemplateFromFile('Index');
  return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

Interestingly, the script renders itself when I use the Google-given URL: https://sites.google.com/corp/view/vrajlinkshortener

However, that is not the case when I enter the custom domain: www.wharton.ml

I checked the documentation and I still could not figure out why a custom domain would prohibit Apps Script form working.

Any tips? Thanks!


Solution

  • You need to set the option XFrameOptionsMode to ALLOWALL.

    XFrameOptionsMode

    https://developers.google.com/apps-script/reference/html/x-frame-options-mode

    Setting XFrameOptionsMode.ALLOWALL will let any site iframe the page, so the developer should implement their own protection against clickjacking.

    return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
    

    As stated in the comments below (Shan Eapen Koshy said) check that your browser is logged into one Google account only.