Derive <iframe> embed link from src template on frontend

What does this MR do and why?

Stacked on top of Detect embeddable URL in the RTE and offer to c... (!265667 - merged).

The FE parts of https://gitlab.com/gitlab-org/gitlab/-/work_items/637694+ (staff-only):

  • Build the "view" URL for embedded content fresh from an admin-written template, using the placeholders in the original.
  • We don't "re-check the sink with the browser's parser (defense in depth)".
    • The suggestion to check new URL(canonicalSrc).host against the host the provider matched before rendering only makes sense if we are, in fact, rendering canonicalSrc. But per the first part of the fix (stop shipping the raw string), we never render (or "ship") canonicalSrc; it never makes it to a link or embed as of this MR, and is only used to preserve the user's entered URL in the source in the RTE.

Calling this typefeature and not typebug since it's a still disabled-by-default FF.

Note that we used to roundtrip other parts of the URL a user might enter, like ?t=30 on a YouTube embed, so that they'd be preserved when a reader clicked "open in new window" (though they never became a part the embed itself). We no longer do that, by design.

Screenshots or screen recordings

Source:

![](https://youtu.be/dQw4w9WgXcQ?si=tracking&t=42)

![](https://www.figma.com/design/abc123/Title?node-id=1-2&t=xyz)
What Before After
YouTube "Open in new tab" link destination image.png image
Figma "Open in new tab" link destination image.png image
Fallback links after providers disabled image.png image

How to set up and validate locally

  1. Check out master.
  2. Enable the allow_iframes_in_markdown FF.
  3. Go to Admin → Settings → General → Embedded content.
  4. Check "Enable embedded content", "YouTube", and "Figma", then click "Save changes".
  5. Restart your Caproni cluster/GDK.
  6. Insert the above source text into a work item/MR description or comment.
  7. Hover each embed's "Open in new tab" link, in the "You are viewing external content from ..." banner. (You need to load the Figma content to see its, not that the embed actually loads; abc123 is not a valid embed ID, but it works all the same.) The link destinations should look like the first two "Before" rows.
  8. Go back to admin and uncheck "YouTube", and "Figma", then click "Save changes".
  9. Wait a minute or so for the settings cache to expire.
  10. Refresh the content you created before. It should look like the last "Before" row.
  11. Check out this branch.
  12. Re-enable "YouTube" and "Figma".
  13. Go back to the source, and edit it slightly. Add a new line between the two embeds, or some text. We need this to ensure the Markdown cache doesn't get used.
  14. Repeat step 7 — the link destinations should match the first two "After" rows.
  15. Repeat steps 8 through 10; it should look like the last "After" row.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Asherah Connor

Merge request reports

Loading
Loading