embed
oEmbed-style iframe HTML for rich cards. It resolves to an object with
html, the markup to render, and scripts, the script tags the markup depends on:const { html, scripts } = await microlink.embed('https://www.youtube.com/watch?v=9P6rdqiybaw')Any URL implementing the oEmbed specification is supported — hundreds of providers, from YouTube and X to Spotify and TikTok. See the iframe parameter for the list. It resolves to
null when the provider doesn't expose an embed.Options
maxWidth<number>— the maximum width of the embedded resource, in pixels.maxHeight<number>— the maximum height of the embedded resource, in pixels.
Both are forwarded per the oEmbed spec, so support depends on each provider. Any shared option applies too.
Examples
Constrain the player to the column it renders in:
const { html } = await microlink.embed('https://www.youtube.com/watch?v=9P6rdqiybaw', {
maxWidth: 350
})Render a post whose widget needs a script, injecting both:
const { html, scripts } = await microlink.embed('https://x.com/microlinkhq/status/1032664633960800257')
document.querySelector('#post').innerHTML = html
for (const { src, async } of scripts) {
const script = document.createElement('script')
script.src = src
script.async = async
document.body.append(script)
}For a static card instead of the provider's player, use metadata and render the fields yourself. For a drop-in component that does either, see link preview.
See the embed guide for iframe versus card decisions, caching, and private pages.