Command Palette

Search for a command to run...

Hectal
Phase 9: Prompt Injection and Safe Frontends
AI Frontend · Exercise 1 of 4Next
Intermediate

Allow Only Safe Links

A reply contains four links. Write safeHref(raw) so it returns the full address for https: and mailto: links and null for everything else. Parse with new URL(raw, "https://chai.example"), and use try/catch for text that is not a URL.

When #render is clicked, the page already lists the links. Links with an address become real <a> elements in #links. The others must appear as plain text with the words (link removed) after the label.

What Check tests

  1. Before the click #links is empty
  2. After the click there are exactly two real links
  3. The two removed links show (link removed)
  4. The code parses with new URL

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.