console: getting started copy script inline, no /static/ asset
Customer pages load nothing from /static/ (TestCustomerPagesKeepTheir Layout). The Copy-button script moves inline into getting_started.html, scoped to #getting-started, buttons still hidden until it runs. static/getting_started.js and its icons_test allowance are removed; icons_test.go matches main again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+35
−51
internal/console/gettingstarted_page_test.go+12 −2internal/console/icons_test.go+1 −28internal/console/static/getting_started.js+0 −20internal/console/templates/getting_started.html+22 −1
diff --git a/internal/console/gettingstarted_page_test.go b/internal/console/gettingstarted_page_test.go| index 6e4b3f2ec..e01d18032 100644 |
| --- a/internal/console/gettingstarted_page_test.go |
| +++ b/internal/console/gettingstarted_page_test.go |
| @@ -96,8 +96,18 @@ func TestGettingStartedCardFresh(t *testing.T) { |
| if !strings.Contains(body, prompt) { |
| t.Errorf("connect prompt missing or wrong; want %s", prompt) |
| } |
| - if !strings.Contains(body, `data-copy-target="gs-prompt-connect"`) || !strings.Contains(body, `<script src="`+assetURL("getting_started.js")+`"></script>`) { |
| - t.Error("the prompt has no copy button, or the copy script is not loaded") |
| + // The copy button starts hidden (with JavaScript off the prompt is plain |
| + // text) and the card's own inline script un-hides it; customer pages |
| + // load nothing from /static/. |
| + card0 := gsCard(t, body) |
| + if !regexp.MustCompile(`data-copy-target="gs-prompt-connect"[^>]* hidden>`).MatchString(card0) { |
| + t.Error("the prompt has no copy button, or it does not start hidden") |
| + } |
| + if !strings.Contains(body, `querySelectorAll("[data-copy-target]")`) || !strings.Contains(body, "copy.hidden = false") { |
| + t.Error("the card carries no inline copy script") |
| + } |
| + if strings.Contains(body, "/static/") { |
| + t.Error("the account home loads a /static/ asset") |
| } |
| for _, bad := range []string{"Carloku", "{console}"} { |
| if strings.Contains(body, bad) { |
diff --git a/internal/console/icons_test.go b/internal/console/icons_test.go| index a252f7c06..12fa98230 100644 |
| --- a/internal/console/icons_test.go |
| +++ b/internal/console/icons_test.go |
| @@ -62,8 +62,7 @@ func TestSwitcherChromeIsInlineSVGNotTextGlyphs(t *testing.T) { |
| // loads Rastrillo's stylesheets and scripts, and it loads them from this |
| // origin only, through the {{asset "..."}} template func (/static/{hash}/...). |
| // sameOriginAssetTags is the exact shape it may use. The demo claim page |
| -// may load only its embedded demo_claim.js through the same asset helper, |
| -// and the Getting started card only its getting_started.js. |
| +// may load only its embedded demo_claim.js through the same asset helper. |
| // Its shared console styles are inline and covered by an exact CSP hash. |
| func TestConsoleTemplatesFetchNothingOffOrigin(t *testing.T) { |
| err := fs.WalkDir(tmplFS, ".", func(path string, d fs.DirEntry, err error) error { |
| @@ -134,9 +133,6 @@ func offOriginFetches(path, src string) []string { |
| if path == "templates/demo_claim.html" { |
| src = strings.ReplaceAll(src, `<script src="{{asset "demo_claim.js"}}"></script>`, "") |
| } |
| - if path == "templates/getting_started.html" { |
| - src = strings.ReplaceAll(src, `<script src="{{asset "getting_started.js"}}"></script>`, "") |
| - } |
| var found []string |
| for _, bad := range banned { |
| if strings.Contains(src, bad) { |
| @@ -248,26 +244,3 @@ func TestDemoClaimTemplateRefusesOtherSubresources(t *testing.T) { |
| } |
| } |
| } |
| - |
| -func TestGettingStartedTemplateRefusesOtherSubresources(t *testing.T) { |
| - const path = "templates/getting_started.html" |
| - const allowed = `<script src="{{asset "getting_started.js"}}"></script>` |
| - if got := offOriginFetches(path, allowed); len(got) != 0 { |
| - t.Fatal(got) |
| - } |
| - for _, tag := range []string{ |
| - `<script src="https://example.com/getting_started.js"></script>`, |
| - `<script src="{{asset "https://example.com/getting_started.js"}}"></script>`, |
| - `<script src="{{asset "getting_started.js"}}" data-url="https://example.com"></script>`, |
| - `<script src="{{asset "demo_claim.js"}}"></script>`, |
| - `<link rel="stylesheet" href="{{asset "ops.css"}}">`, |
| - } { |
| - if got := offOriginFetches(path, allowed+tag); len(got) == 0 { |
| - t.Errorf("allowed %s", tag) |
| - } |
| - } |
| - // The allowance is this template's alone. |
| - if got := offOriginFetches("templates/apps.html", allowed); len(got) == 0 { |
| - t.Error("apps.html may load getting_started.js directly") |
| - } |
| -} |
diff --git a/internal/console/static/getting_started.js b/internal/console/static/getting_started.js| deleted file mode 100644 |
| index 264821312..000000000 |
| --- a/internal/console/static/getting_started.js |
| +++ /dev/null |
| @@ -1,20 +0,0 @@ |
| -(() => { |
| - "use strict"; |
| - // The Getting started card's Copy buttons (templates/getting_started.html): |
| - // hidden until this runs, so with JavaScript off the prompt is plain, |
| - // selectable text and no dead button shows. The loop is demo_claim.js's. |
| - for (const copy of document.querySelectorAll("#getting-started [data-copy-target]")) { |
| - const command = document.getElementById(copy.dataset.copyTarget); |
| - if (!command || typeof navigator.clipboard?.writeText !== "function") continue; |
| - copy.hidden = false; |
| - let reset; |
| - copy.addEventListener("click", async () => { |
| - try { |
| - await navigator.clipboard.writeText(command.textContent); |
| - copy.textContent = copy.dataset.copied; |
| - clearTimeout(reset); |
| - reset = setTimeout(() => { copy.textContent = copy.dataset.copy; }, 2000); |
| - } catch (_) { copy.hidden = true; } |
| - }); |
| - } |
| -})(); |
diff --git a/internal/console/templates/getting_started.html b/internal/console/templates/getting_started.html| index 10ce6d3a0..4b3088306 100644 |
| --- a/internal/console/templates/getting_started.html |
| +++ b/internal/console/templates/getting_started.html |
| @@ -41,7 +41,28 @@ |
| .gs-paste button { justify-self: start; } |
| } |
| </style> |
| -<script src="{{asset "getting_started.js"}}"></script> |
| +<script> |
| +// The card's Copy buttons: hidden until this runs, so with JavaScript off |
| +// the prompt is plain, selectable text and no dead button shows. |
| +(function () { |
| + "use strict"; |
| + var card = document.getElementById("getting-started"); |
| + if (!card || !navigator.clipboard || typeof navigator.clipboard.writeText !== "function") return; |
| + card.querySelectorAll("[data-copy-target]").forEach(function (copy) { |
| + var command = document.getElementById(copy.dataset.copyTarget); |
| + if (!command || !card.contains(command)) return; |
| + copy.hidden = false; |
| + var reset; |
| + copy.addEventListener("click", function () { |
| + navigator.clipboard.writeText(command.textContent).then(function () { |
| + copy.textContent = copy.dataset.copied; |
| + clearTimeout(reset); |
| + reset = setTimeout(function () { copy.textContent = copy.dataset.copy; }, 2000); |
| + }, function () { copy.hidden = true; }); |
| + }); |
| + }); |
| +})(); |
| +</script> |
| {{end}}{{end}} |
| {{define "getting_started_show"}}{{if .ShowGettingStarted}}<form class="gs-show small" method="post" action="{{.Base}}/getting-started/show"><input type="hidden" name="csrf" value="{{.CSRF}}"><button class="linkish" type="submit">{{.GettingStartedCopy.Show}}</button></form> |