Function rewriteEmbeds
-
rewriteEmbeds(
html: string,
options?: EmbedOptions | ResolvedEmbedOptions,
page?: { csp: boolean },
): { html: string; rewritten: number; skipped: Record<string, number> }Parameters
- html: string
- options: EmbedOptions | ResolvedEmbedOptions = {}
- page: { csp: boolean } = ...
Returns { html: string; rewritten: number; skipped: Record<string, number> }
Replaces each server-rendered YouTube or Vimeo
<iframe src>inhtmlwith a facade, asoptionsallow, and says how many it replaced and how many it left alone. Only anhttps,httpor protocol-relativesrcon a known embed host and path, with an id of 6 to 64 letters, digits,-and_, is touched. An iframe inside an HTML comment or<noscript>, one that hassrcdoc, and one whose URL setsenablejsapi=1(the page's script expects the real player) stay as they are; the last is counted asjsapi. An embed that plays on its own by design (seeambient) stays too and is counted asambient. Withpage.cspset, and noignoreCsp, every matching iframe is left alone and counted ascsp. The facade keepswidth,height,title,class,style,allow,allowfullscreen,loading,id,sandboxandreferrerpolicy. Everything outside the replaced start tags stays byte for byte.