Embed Code

Reads back what an embed will show and track, and strips tokens from its URL, so an embed doesn't leak a private link or secret.

StopsEmbed leaked a private token

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/embed-code.json

The files land in your project. They're yours to edit.

Usage

embed-code-usage.tsx
import { EmbedCode } from "@/components/ui/embed-code"

<EmbedCode
  resource={resource}
  defaultValue={{ allowedDomains: ["acme.dev"] }}
  renderPreview={() => (
    <div className="relative grid size-full place-items-center bg-linear-to-br from-zinc-800 to-zinc-950 text-white">
      <span className="grid size-10 place-items-center rounded-full bg-white/15">
        <Play aria-hidden className="size-4 fill-current" />
      </span>
      <span className="absolute bottom-2 left-3 text-xs font-medium text-white/80">{resource.title}</span>
    </div>
  )}
/>

What it catches

  • Secrets in the embed URL (token=, sig= and similar)
  • Draft or private resources about to be embedded
  • Tracking the embed adds, with a privacy-mode option
  • Allowed-site entries that aren't valid domains

Props

EmbedCode props
PropTypeDefault
resource* (required)

What is being embedded, and what it exposes.

EmbedResource—
value

Controlled embed options.

EmbedOptions—
defaultValue

Initial options when uncontrolled.

Partial<EmbedOptions>—
onValueChange

Called with the embed options whenever they change.

(options: EmbedOptions) => void—
onCopy

Called with the snippet after it is copied.

(snippet: string) => void—
renderPreview

Renders the live preview for a src. Defaults to a titled placeholder at the chosen size.

(src: string) => React.ReactNode—
labels

Override any visible label.

Partial<typeof DEFAULT_LABELS>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Labelled options and allowed-domain field with aria-invalid and aria-describedby
  • Readback rows use icons plus text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Scope embed tokens to read-only, short-lived access on the server, and enforce allowed origins with frame-ancestors.

  • Exposure and tracking come from the resource description you pass
  • Stripping a token may break an embed that genuinely needs it

What it stops

Embed leaked a private token

Also known as

embed · iframe · embed code · youtube · privacy-enhanced · widget · share · token in url

Dependencies

Pairs well with