1

First of all I checked already this, this, this, this, this, this and this. And they don't seem to be a duplicate of my problem exactly.

I have a web app, generated by Google Script. In my Code.gs, inside my doGet(e) function, I have a routing mechanism for handling different webpages, which I simplified below in a if else statement block. The doGet(e) returns different pages based on the URL, meaning, if the URL ends in ?v=page1 it returns page1.html, if it ends in ?v=about it returns about.html, and so on. It all works fine if I type the whole thing in the Address URL space in the browser.

Now, my home.html has a menu with hyperlinks for those pages. The pages open fine if I click on the links, as long as the default target is _top.

Now, my problem is: I put an iframe below the menu so all the pages would open in the same home. They failed with error below:

Load denied by X-Frame-Options: “SAMEORIGIN” from “https://script.google.com/macros/s/AKfycbz80HBBQPcs-sYm9CsVNT7iyeBQjySR1FXN0TmgjKc/dev?v=page1”, site does not permit cross-origin framing from “https://n-72ap4753yyujkagtmqc7xoskf2cznnrfk23rzbq-0lu-script.googleusercontent.com/blank”.

I figured the reason would be the app was not published yet, so I publish the app and started returning page1.html with .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL). Now the error is:

Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://n-72ap4753yyujkagtmqc7xoskf2cznnrfk23rzbq-0lu-script.googleusercontent.com’) does not match the recipient window’s origin (‘https://script.google.com’).

The error seems to be related to the page hitting another address in googleusercontent.com and that could be causing the issue?

The home page: As you can see below in my home.html, there are 3 links: iframes opens the wikipedia article about HTML/Iframes in the iframe of my home.html, just fine. Page1 should open my page1.html in my home.html iframe section, but that is where the error takes place. about open the about.html as another page, on _top of everything, so it works fine. But as soon as the iframe issue is solved I will change the target for that one to open in the iframe as well.

My files are as below:

Code.gs:

function doGet(e) {
  Logger.log(e.parameters.v);
  if (e.parameters.v == "page1") {
    return HtmlService.createTemplateFromFile("page1").evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  } else if (e.parameters.v == "about") {
    return HtmlService.createTemplateFromFile("about").evaluate();
  } else
    return HtmlService.createTemplateFromFile("home").evaluate();
}

home.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <style>
      #nav-wrapper {
        background-color: bisque;
        padding: 8px;
      }

      #img-logo {
        height: 2%;
        width: 2%
      }

      #nav {
        display: inline-block;
        list-style-type: none;
      }

      #nav > li {
        display: inline-block;
        padding: 0 24px 0 0;
      }

      #nav > li > a {
        padding: 8px;
        text-decoration: none;
        outline: 0;
      }

      #nav > li > a:link, a:visited {
        color: DarkSlateGray;
      }

      #nav > li > a:hover {
        background-color: GoldenRod;
        border-radius: 8px;
        box-shadow: 4px 4px grey;
      }

      #iframePages {
        width: 100%;
        height: 800px;
        overflow: scroll;
        border: none;
      }
    </style>
  </head>
  <body>
    <?
      var url = ScriptApp.getService().getUrl();
      var imgLogo = "https://png2.cleanpng.com/sh/e2fa53a06dccb65dbd183cfa6b13c455/L0KzQYm3VsIzN5dmj5H0aYP2gLBuTgRpbV5rfd9qbHWwcsPoif4ucKZyedC2YoLkebA0kP9tgZh0hp9xdX3kfn7vhfFlNaF0hOtwb37kfH75ifZtcZ9sRadrMnTkRoPsWPJkQJI2RqU8OEa3Q4q4UcUzQWg2UKU6OEW6Qoe1kP5o/kisspng-the-female-brain-human-brain-polygon-human-head-polygonal-rifling-5b2da62e8bc8a1.3386439115297183185726.png";
    ?>

    <script>
      var url=<?= url ?>;
      console.log(url);
    </script>

    <nav>
      <div id="nav-wrapper">
        <a href="<?= url ?>" class="brand-logo"><img id="img-logo" src="<?= imgLogo ?>"></a>
        <ul id="nav">
          <li><a href="https://en.wikipedia.org/wiki/HTML_element#Frames" target="iframePages">IFrames</a></li>
          <li><a href="<?= url ?>?v=page1" target="iframePages">Page1</a></li>
          <li><a href="<?= url ?>?v=about">About</a></li>
        </ul>
      </div>
    </nav>

    <iframe id="iframePages" name="iframePages"></iframe>

  </body>
</html>

page1.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h1>Page 1</h1>
  </body>
</html>

about.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h1>About</h1>
  </body>
</html>

the URL:

https://script.google.com/macros/s/AKfycbxBBaGG_rZl1jAuNqDzL8O9un7bfn9Qm_cfA_nAjMxE1w-dl2U/exec

Error image: enter image description here

Error in the console. Frame on the left hand side is empty.

Please keep in mind this is a simplified version of my full app which is providing the same behavior so I could share.

Can anyone please shed some light on this?

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
Adriano_Pinaffo
  • 1,429
  • 4
  • 23
  • 46
  • 1.Are you using `postMessage`? 2.Could you describe what happens when you click page1 link? 3. Have you republished a new version after `xframe` modifications? – TheMaster Dec 29 '19 at 16:46
  • 1
    @TheMaster, 1. I'm not entirely sure what `postMessage` really means. 2. Nothing happens on the home page, the iframe is still empty, but the console shows the message `Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://n-72ap4753yyujkagtmqc7xoskf2cznnrfk23rzbq-0lu-script.googleusercontent.com’) does not match the recipient window’s origin (‘https://script.google.com’).`. 3. I republished new versions after all the modifications, but I'm not sure either what the `xframe` you wrote is. – Adriano_Pinaffo Dec 29 '19 at 17:23
  • If I misunderstood your situation, I apologize. About `Page1 should open my page1.html in my home.html iframe section, but that is where the error takes place.`, unfortunately, I cannot replicate this issue using your script. Also even when I tested it with your Web Apps, the issue cannot be replicated. So can I ask you about the method for replicating your issue? By the way, although this is not directly related to your issue, `e.parameters.v` returns an array. So how about modifying to `e.parameter.v`? – Tanaike Dec 30 '19 at 02:20
  • @Tanaike I have the same issue: I can not replicate this with `page1.html`, however I recreated the web app on my test domain and added `target="iframePages"` to `
  • About
  • ` in `home.html`. Now, while I can not replicate this issue with `page1.html`, I can with `about.html`, though this goes away, when I add `.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)` to the `about` page evaluation in `code.gs`. OP, have you made sure that all templates being returned by your`doGet(e)` use `.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)`? – Rafa Guillermo Dec 30 '19 at 12:01
  • @Tanaike, e.parameters.v indeed was an array. I will take care of that, although it is working. About replicating, I thought it would happen to anyone. So, did you set it up and work for you? I'm attaching a picture of the issue. – Adriano_Pinaffo Dec 30 '19 at 17:12
  • @RafaGuillermo, I was using .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) for my Page 1 only, but I now add to About as well, but it didn't work either. The error is the same, as I just added a image in my original post. – Adriano_Pinaffo Dec 30 '19 at 17:18
  • @Rafa Guillermo Thank you for your comment. Also I think so. But I'm not sure that when the OP's issue cannot be replicated, the solution can resolve OP's issue. So at first, I asked the method for replicating OP's issue. – Tanaike Dec 30 '19 at 23:37
  • @Adriano_epifas Thank you for replying. Unfortunately, I cannot replicate your situation. When I tested your deployed Web Apps, the Web Apps has no errors. "IFrames", "Page1" and "About" can be seen. Even when I tested your script in my environment, I could confirm that it works fine. So for example, when you changed the browser to Chrome, will the error be changed? – Tanaike Dec 30 '19 at 23:37
  • oh, this is so weird. I just tested in Chromium and it works fine there. It is only Firefox that is failing. Why is that? – Adriano_Pinaffo Jan 04 '20 at 14:18