amphtml: amp-script: Support location.href (don't return the blob URL)

I am using AMP-SCRIPT. I want to get the current URL with parameter, but that what I get:

blob:http://localhost:8080/bcd8ce8b-4c8f-4ab0-8d4e-471d7be9af3f

That’s what I want:

http://localhost:8080/?foo=bar

The HTML code:

<!DOCTYPE html>
<html ⚡>
    <head>
        <meta charset="utf-8" />
        <title>AMP-SCRIPT</title>
        <meta
            name="viewport"
            content="width=device-width,minimum-scale=1,initial-scale=1"
            />      
        <script type="application/ld+json">
            {
            "@context": "http://schema.org",
            "@type": "NewsArticle",
            "headline": "Article headline",
            "image": ["thumbnail1.jpg"],
            "datePublished": "2015-02-05T08:00:00+08:00"
            }
        </script>
        <script 
            async 
            custom-element="amp-script" 
            src="https://cdn.ampproject.org/v0/amp-script-0.1.js"
        ></script>            
        <style amp-boilerplate>
            body {
                -webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
                -moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
                -ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
                animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            }
            @-webkit-keyframes -amp-start {
                from {
                    visibility: hidden;
                }
                to {
                    visibility: visible;
                }
            }
            @-moz-keyframes -amp-start {
                from {
                    visibility: hidden;
                }
                to {
                    visibility: visible;
                }
            }
            @-ms-keyframes -amp-start {
                from {
                    visibility: hidden;
                }
                to {
                    visibility: visible;
                }
            }
            @-o-keyframes -amp-start {
                from {
                    visibility: hidden;
                }
                to {
                    visibility: visible;
                }
            }
            @keyframes -amp-start {
                from {
                    visibility: hidden;
                }
                to {
                    visibility: visible;
                }
            }
        </style>
        <noscript
        ><style amp-boilerplate>
            body {
                -webkit-animation: none;
                -moz-animation: none;
                -ms-animation: none;
                animation: none;
            }
        </style></noscript
        >
        <script async src="https://cdn.ampproject.org/v0.js"></script>
    </head>
    <body>
    <amp-script layout="container" src="/javascript.js" sandbox="allow-forms">
        <button>Hello amp-script!</button>
        <span></span>
    </amp-script>
</body>
</html>

javascript.js

const btn = document.querySelector('button');
btn.addEventListener('click', () => {
  document.body.textContent = location.href;
});

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 15
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Looks like something that should be remedied!

@kristoferbaxter did give it a P2!

It might also be a simple way to start contributing… to submit your own PR.

Could you please help me to know if it is possible?

@CarlosCPC: this is currently not possible.


Less of an easy fix than I initially thought. The worker location object is WAI in terms of how Workers usually behave. We could overwrite the global location as well as provide Document.location and keep them up to date with the main thread.