vibes.diy Make an app → Discord
creator docs · reference · generated

Third-party embeds — another site's player inside the page

This is the same document the Vibes code generator reads when it builds apps — rendered from prompts/pkg/llms/third-party-embed.md on every deploy, so it can't drift from what the platform actually does. Read it from your terminal any time with npx vibes-diy skills.

A video, a track, a playlist from another site plays inside the app through that site's own player: an <iframe> whose src is the service's embed page. No key, no backend, and no fetch from your code. The service skill that loaded this page says how its links turn into an embed src; this page is how every embed behaves once you have one.

What a person pastes is a share link, and the link is what the app stores. The service skill's parser turns it into an embed src at render time, and anything that does not parse is refused with the input kept on screen ("That isn't a YouTube link — paste the address from the Share button"), never saved.

Build the src from the parsed id only, and never render pasted embed HTML (dangerouslySetInnerHTML with an <iframe …> someone copied): pasted markup is someone else's HTML running in this page, and an id cannot carry a script.

One frame component

Every embed renders through one component that owns the frame's attributes, so a list of ten players carries the same rules ten times without ten copies.

jsx// A video keeps its shape as the column narrows; an audio player has the fixed
// height its service names, so pass `height` for those.
const ALLOW = "autoplay; encrypted-media; fullscreen; clipboard-write";
function EmbedFrame({ src, title, height }) {
  if (height) {
    return (
      <iframe src={src} title={title} height={height} width="100%" loading="lazy" allow={ALLOW}
        referrerPolicy="strict-origin-when-cross-origin" className="block border-0" />
    );
  }
  return (
    <iframe src={src} title={title} loading="lazy" allow={ALLOW}
      referrerPolicy="strict-origin-when-cross-origin" className="block w-full aspect-video border-0" />
  );
}
  • title is required. It is what a screen reader announces for the frame: the video's or track's name, never "embed" or "player".
  • loading="lazy" keeps players below the fold from loading until they scroll near.
  • allow asks only for what the app's own frame was given. A vibe runs inside a frame of its own, and a frame nested in it can be granted only what that outer frame delegates: autoplay, encrypted-media (full-length streams), fullscreen and clipboard-write are delegated. Picture-in-picture is not, so asking for it does nothing.
  • The referrer stays on. Players check where they are embedded, and some refuse to play with no referrer at all, so never set referrerPolicy="no-referrer" on a player.
  • Nothing autoplays with sound. Browsers block it until the person presses something, and a page that starts talking is a page people close. The player's own play button is the gesture.

The player's insides are another origin: your code cannot read whether it loaded, and a refusal (embedding turned off by the uploader, a region lock, an age gate) shows only inside the frame. So every player has a plain link to the same item on its own site beneath it ("Open on YouTube", "Listen on Spotify"), which is also the way to the full experience.

Many players: show a card, load the frame on press

A page of twenty embeds loads twenty players. Show each item as a card with its thumbnail and title, and swap in the EmbedFrame when the person presses play, so only the one they chose loads. The frame then needs the press to start, so the service's embed parameter for "start on load" is fine there, and only there. Pass the service's fixed player height through (Spotify's 152 or 352), so the opened frame keeps the shape its service draws in.

jsxfunction PlayerFacade({ item, src, height }) {
  const [open, setOpen] = useState(false);
  if (open) return <EmbedFrame src={src} title={item.title} height={height} />;
  return (
    <div>
      {item.thumbnail && <img src={item.thumbnail} alt="" className="block w-full" />}
      <Button type="button" onClick={() => setOpen(true)}>Play {item.title}</Button>
    </div>
  );
}

A title and thumbnail without a key: oEmbed

Most players publish an oEmbed endpoint: a keyless GET that answers a share link with its title, author_name and thumbnail_url. The service skill names its endpoint. Read it once, when the person adds the item (in the add handler, never during render), and store the answer on the record with the link, so the list renders from the app's own data. When the call fails in any way (an error status, no network, an answer that is not JSON), save the link anyway with the link itself as its title: the player still plays.

jsxasync function fetchOEmbed(endpoint, link) {
  try {
    const r = await fetch(`${endpoint}?url=${encodeURIComponent(link)}&format=json`);
    if (!r.ok) return { title: link };
    const o = await r.json();
    return { title: o.title ?? link, author: o.author_name ?? null, thumbnail: o.thumbnail_url ?? null };
  } catch {
    return { title: link };
  }
}