928 words
5 minutes

Douyin Video Embedded in a Webpage Not Showing? Fixing Referer Hotlink Protection and Black Thumbnail

Douyin Video Embedded in a Webpage Not Showing? Fixing Referer Hotlink Protection and Black Thumbnail

Scope: Directly using <video> / <img> in your own webpage to load video and cover URLs parsed from Douyin (not official iframe embeds). Nature of this article: A real-world record of fixing display issues with Douyin parsing results in the "Online Tools" section of codqor.com. The code is the version running in production.

1. Symptom: Plays in Admin, Missing on Frontend

The blog's Online Tools includes a Douyin parser: paste a share link, the backend parses out the watermark-free video URL and cover image, and the result plays in a modal via <video>.

There are two issues:

  1. The same result plays normally in the admin dashboard, but on the frontend article page the video doesn't show up.
  2. Even when it does play, the video box is completely black with no cover — you have to click into it to see the picture.

2. Cause: Douyin CDN Checks Referer

When the browser loads <video src> and <img src>, it includes Referer in the request headers, telling the server "which page I'm coming from."

Douyin's video and image CDNs have hotlink protection: if the request carries a Referer from an external site, it's rejected outright.

So why does the admin work fine? Because the Caddy in front of the admin already sets Referrer-Policy: no-referrer for the entire admin — requests sent from the admin don't carry a Referer at all, so the CDN doesn't block them. The frontend article page doesn't have this policy, so requests go out with the codqor.com article page URL as the Referer and get rejected.

Page Referrer Policy Request Carries Referer? Result
Admin Dashboard Caddy unified no-referrer No Plays normally
Frontend Article Page Browser default Carries codqor.com Rejected by CDN

3. Fix 1: Only Omit Referer When Needed

Images are easy — <img> supports the referrerpolicy attribute, just add it individually:

tool-widget.js(图片)
`<img loading="lazy" referrerpolicy="no-referrer" src="${esc(v.url)}" alt="${esc(v.label || "图片")}">`

The tricky part is video: <video> doesn't have a referrerpolicy attribute, so you can only rely on a page-level Referrer policy. The most straightforward way is to add it in <head>:

Terminal window
<meta name="referrer" content="no-referrer">

But I don't want to do this site-wide — that would strip the source from all outbound links in articles. So instead: only dynamically insert this meta tag when a video or image appears in the tool results; the admin itself is already no-referrer, so skip it.

tool-widget.js
// Douyin and other CDNs reject video/cover requests with an external site Referer;
// When video results appear on the frontend, this page switches to not sending Referer (the backend already uses no-referrer)
function noReferrerForMedia(state) {
if (location.pathname.startsWith("/blog-admin/")
|| !state?.data?.result
|| document.querySelector('meta[name="referrer"][data-tool]')) return;
if (!state.manifest.outputs.some(o => o.type === "video-list" || o.type === "image-gallery")) return;
const meta = document.createElement("meta");
meta.name = "referrer";
meta.content = "no-referrer";
meta.dataset.tool = "1";
document.head.append(meta);
}

Call it before rendering the results, ensuring the policy is already in effect when <video> sends the request:

tool-widget.js
function refreshDialog(dialog, state) {
noReferrerForMedia(state);
dialog.querySelector(".tool-result-body").innerHTML = resultContent(state);
}

4. Fix 2: Use Poster for the Black Cover

<video preload="metadata"> only fetches metadata and doesn't necessarily paint the first frame — especially noticeable on iOS Safari — so you get a black box.

The solution has three tiers:

  1. The item in the parsed result has its own poster / cover — use it directly;
  2. If not, use the first image in the result (the Douyin parser usually provides a cover image alongside);
  3. If neither exists, append #t=0.1 to the video URL, making the browser jump to 0.1 seconds and show that frame as a preview.

Also add playsinline to prevent forced fullscreen on iPhone on tap.

tool-widget.js(视频)
if (field.type === "video-list") {
// Cover: use the entry's own poster/cover if available; otherwise use the first image in the results; if neither exists, seek to 0.1s so iOS displays the first frame
const firstImage = Object.values(all || {}).find(x =>
Array.isArray(x) && x[0]?.url && x !== value &&
/\.(jpe?g|png|webp|heic|avif)|image|cover|tos-/i.test(x[0].url)
)?.[0]?.url;
html = value.map(v => {
const poster = v.poster || v.cover || firstImage || "";
return `<video class="media-video" controls playsinline preload="metadata"`
+ (poster ? ` poster="${esc(poster)}"` : "")
+ ` src="${esc(poster ? v.url : v.url + "#t=0.1")}"></video>`;
}).join("");
}

Before and after comparison:

Before After
Frontend Video Request rejected, can't play No Referer, plays fine
Cover Black box Parsed cover image
iPhone Tap May be taken over by fullscreen Plays inline

5. Summary

  • Douyin (and many other domestic platforms) CDNs reject external-site Referer; <img> uses referrerpolicy="no-referrer", while <video> can only rely on page-level <meta name="referrer">.
  • Insert meta on demand; don't apply a blanket rule site-wide. The insertion timing must be before media elements render.
  • Use poster for black thumbnails; when there is no thumbnail, use #t=0.1 as a fallback, and add playsinline.
  • Parsed direct links expire and may also return 403 due to issues with the link itself. This is separate from Referer, so distinguish between the two when troubleshooting.

Share Article

If this article helped you, please share it with others!

Douyin Video Embedded in a Webpage Not Showing? Fixing Referer Hotlink Protection and Black Thumbnail
https://codqor.com/posts/douyin-embed-referer-fix/
Author
Liam
Published at
Related PostsSmart
1
My 256MB Router Can’t Run OpenClash, So I Built TinyLane and Open-Sourced It
TechThe Xiaomi AX3000T has only 256 MB of RAM, making OpenClash too much of a strain, so I packaged the sing-box core, a Go daemon, and a mobile panel into a single binary called TinyLane, with my daily readings at about 35 MB for the core and 20–28 MB for the panel. This article explains why I wrote it, what it can do, the memory pitfalls I hit, and how to install it; the project is open-sourced under GPL-3.0.
2
One API for Multiple TTS Providers: OpenAI Standard Parameter Mapping (MOSS Example)
TechWhen creating voiceovers for short videos, I used Edge TTS, Gemini, and MOSS together, each with different parameters. I later added /v1/audio/speech to my AI relay: clients call it using the OpenAI standard format while the gateway maps parameters per provider (for MOSS, just one line: voice→voice_id), and this article covers the parameter comparison table, mapping implementation, usage examples, and pitfalls.
3
Self-Hosting an Astro Blog: Pitfalls with R2 Image Hosting, D1, Caddy, and SEO
Techcodqor.com is itself an Astro static blog: posts are stored in Cloudflare D1, images in R2, pages are served from its own server via Caddy, comments use Turnstile, and there is an English mirror. This article records the build process and pitfalls in real chronological order, including overly long Bing titles, missed noindex directives, a build machine being cooled down, and the remediation approach after AdSense rejected the site for "low-value content."
4
Resend Email Sending from 0 to Launch: Domain Verification, Sending Relay, and Bounce Monitoring
TechA complete record of moving server notification emails from QQ Mail SMTP to Resend: choosing a new account and domain, DKIM/SPF/DMARC on Cloudflare, a sending API where only one relay holds the key, the gotchas that quota resets at UTC and receiving also consumes quota, Bark alerts for bounces, and protection against duplicate sends. Together with the previous post on Cloudflare receiving, it covers both sending and receiving.
5
Xiaomi AX3000T Follow-up: OpenClash Primary/Backup Routing, WireGuard Coexistence, and Lag Troubleshooting
TechTwo weeks after flashing OpenWrt on the AX3000T: switching routing from HomeProxy to OpenClash (Meta core) with primary/backup lines, running WireGuard remote management alongside OpenClash, and tracing cross-ocean link lag from 41 KB/s to 7–8 MB/s.
Random PostsRandom

Comments

Leave a comment

Share your thoughts

Shown after review
Leave the name empty to post as “Anonymous”0 / 3000

Comments

Newest first · 5 at a time

Loading comments…

Profile Image of the Author
Liam
Notes on tech, life, and thoughts.
Categories
Tags
Latest Moments
Site Statistics
Posts
21
Categories
4
Tags
72
Total Words
87,292
Running Days
0 days
Last Activity
0 days ago
Table of Contents