Skip to content

amp-script: Support creating all AMP elements e.g. amp-date-countdown #25344

Open

Description

@mwiley

What's the issue?

When trying to add amp-date-countdown dynamically using amp-script, a "Sanitized node" error is printed to the console, and it isn't added to the DOM.

How do we reproduce the issue?

JSBin: https://jsbin.com/tenozoxoko/edit?html,output

<!DOCTYPE html>
<html ⚡>
  <head>
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
    <script async custom-element="amp-date-countdown" src="https://cdn.ampproject.org/v0/amp-date-countdown-0.1.js"></script>
  </head>
  <body>
    <amp-script layout="container" script="hello-script" development>
      <button>Add timer</button>
      <div id="timer"></div>
    </amp-script>
    
    <script id="hello-script" type="text/plain" target="amp-script">
      const btn = document.querySelector('button');
      btn.addEventListener('click', () => {
        const timer = document.getElementById('timer');
        timer.innerHTML = `
          <amp-date-countdown layout="fixed" height="100" width="300" timestamp-seconds="2147483648">
            <template type="amp-mustache">
              {{d}}:{{h}}:{{m}}:{{s}}
            </template>
          </amp-date-countdown>
        `
      })
    </script>
  </body>
</html>

Create a page that uses amp-script, and within the script, dynamically add an amp-date-countdown to the DOM.

What browsers are affected?

All browsers appear to be affected.

Which AMP version is affected?

Version 1910251950120.

Activity

  1. changed the title [-]amp-date-countdown can't be inserted using amp-script[/-] [+]amp-script: Create <amp-date-countdown>[/+] on Nov 18, 2019
  2. dreamofabear commented on Nov 18, 2019

    @dreamofabear

    Thanks for filing this issue. Currently, only creating amp-img and amp-layout are supported. This will change in the future, but we'll update the documentation to point this out in the meantime.

  3. changed the title [-]amp-script: Create <amp-date-countdown>[/-] [+]amp-script: Support creating all AMP elements e.g. amp-date-countdown[/+] on Nov 18, 2019
  4. mwiley commented on Nov 26, 2019

    @mwiley
    Author

    Great, thank you!

  5. nurulhudaapon commented on Dec 7, 2019

    @nurulhudaapon

    Can we have support for amp-iframe? If not then what would be the best way to dynamically assign src of amp-iframe from script of amp-script?

  6. massawho commented on Dec 27, 2019

    @massawho

    I just needed to created an amp-pixel dynamically and found out that only amp-layout and amp-img is supported. The problem is that for what I need, amp-img would be enough, but I can't generate PAGE_VIEW_ID or RANDOM with it. That would be great if we can support other amp elements

  7. brycesteinhoff commented on Jan 6, 2020

    @brycesteinhoff

    We also would like to be able to dynamically create amp-iframe from amp-script. We need some programmatic control over which iframe src is loaded.

  8. PratkinV commented on Mar 5, 2020

    @PratkinV

    Please add ability to create amp-analytics, it would help a lot.

  9. akira28 commented on May 4, 2020

    @akira28

    I would need to add amp-ad dinamically

  10. c0un7-z3r0 commented on Aug 20, 2020

    @c0un7-z3r0

    Please add amp-consent to allow loading of cmp layers.

  11. rafaelmuttoni commented on Oct 8, 2020

    @rafaelmuttoni

    Can we have support for amp-iframe? If not then what would be the best way to dynamically assign src of amp-iframe from script of amp-script?

    Were you able to do it? I'm also looking for a way to dynamically assign src of amp-iframe.

  12. alexandr-kazakov commented on Feb 19, 2021

    @alexandr-kazakov
    Contributor

    I tried to add images with a lightbox using amp-script, but the lightbox does not work: #27808 I think this is an important feature.
    It turns out that I can't add images to the lightbox gallery right now.

  13. vivekn-procentris commented on Jul 22, 2021

    @vivekn-procentris

    Need the ability to create amp-script at run time for analytics to dynamically add the src value for amp-script tags.

  14. stale commented on Oct 19, 2022

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

  15. added
    StaleInactive for one year or more
    on Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy