DEV Community

devcaption
devcaption

Posted on Originally published at captionfast.is-a.dev

Built a 100% serverless TikTok transcript extractor with Cloudflare Workers (<500ms, zero ads)

If you've ever tried building a scraper or transcription pipeline for TikTok videos, you've likely hit the standard wall: headless browser latency and compute costs.

Running full Chromium instances with Playwright or Puppeteer to solve TikTok's JavaScript hydration, signed parameters (X-Bogus, msToken), and cookies takes anywhere from 8 to 15 seconds per video, consumes gigabytes of RAM, and burns through proxy budgets.

I wanted something different: instant subtitle extraction in under 500ms with zero heavy infrastructure.

Here is how I built CaptionFast — a 100% serverless edge app and public developer API deployed entirely on Cloudflare Workers.


The Secret: Universal HTML Rehydration Scraping

When you request a TikTok video page with realistic desktop browser headers, TikTok returns an initial HTML document containing a server-side hydration script tag:

<script id="__UNIVERSAL_DATA_FOR_REHYDRATION__" type="application/json">
  { ... "webapp.video-detail": { "itemInfo": { "itemStruct": { "video": { "subtitleInfos": [...] } } } } }
</script>

Enter fullscreen mode Exit fullscreen mode

By extracting and traversing this JSON tree inside a lightweight Cloudflare Worker fetch() request, we can locate the direct .vtt / .srt subtitle URLs and speech transcripts without executing a single line of client-side JavaScript!


The 3-Tier Waterfall Architecture

To ensure 99.9% uptime and prevent rate-limiting, the system implements a resilient 3-Tier Waterfall:

  1. Tier 1 (Instant HTML Rehydration): Direct worker fetch() extracting __UNIVERSAL_DATA_FOR_REHYDRATION__. Resolves in ~300ms–450ms.
  2. Tier 2 (Alternative Mirror API): If TikTok serves a dynamic bot-challenge, the worker automatically fails over to an alternative mirror API in ~400ms.
  3. Tier 3 (Cloudflare Browser Rendering & Queue): Only for rare edge cases where static hydration data is completely absent. Jobs are queued with a concurrency limit to protect session pools.

Extracted subtitles are converted into standard .SRT (for CapCut / Premiere), .VTT (for web players), and clean .TXT (for ChatGPT and LLMs), then cached in Cloudflare KV and stored in R2 buckets.


Free Web Tool & Public Developer API

You can test the tool live in your browser:

👉 https://captionfast.is-a.dev

Or query the free, keyless REST API directly:

# Fetch transcripts & metadata as JSON:
curl "https://captionfast.is-a.dev/api/v1/subtitles?url=https://vm.tiktok.com/ZGeXXXXX/&format=json"

# Download direct .SRT subtitle file:
curl -o captions.srt "https://captionfast.is-a.dev/api/v1/subtitles?url=https://vm.tiktok.com/ZGeXXXXX/&format=srt"

Enter fullscreen mode Exit fullscreen mode

Python developers can install the zero-dependency client:

from tiktok_subtitles import TikTokSubtitles

client = TikTokSubtitles()
transcript = client.get_transcript("https://vm.tiktok.com/ZGeXXXXX/")
print(transcript)

Enter fullscreen mode Exit fullscreen mode

The entire project is open source on GitHub:

⭐ github.com/GermanCorrection/tiktok-caption-extractor

I'd love your feedback! What other formats or video platforms would you like to see supported?

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.