amp-story is already registered. The script tag for amp-story is likely included twice in the page

346 Views Asked by At

I have a project where I'm trying to build an amp-story generator with a simple editor. You can check the current state at https://ampy.co/test/.

The idea is when you insert information on the left panel, the amp-story to be rebuild within an iframe element.

This works only in firefox, but fails in every other browser. Is there a way to achieve what I'm trying here?

Steps to reproduce:

  • Open https://ampy.co/test/
  • Open console (dev tools)
  • Click add layer, or add page on the left panel Image of the left panel
  • Check the console log for all the errors such as "amp-story is already registered. The script tag for amp-story is likely included twice in the page."
1

There are 1 best solutions below

0
On

Yes, the document is evaluated twice and hence the message. One possibility to resolve this is to replace the iframe entirely. For example, create a wrapper DIV:

<div id=iframe_wrapper></div>

And fill in your iframe when it gets updated:

document.getElementById("iframe_wrapper").innerHTML = "<iframe ..."
// find the iframe and insert content