ToolingProjects

MP4/M3U8 Sniffer — catch video links → yt-dlp

A personal Chrome extension (Manifest V3) that turns a tedious chore — opening DevTools to hunt for the m3u8 and copying headers into yt-dlp — into a single click. Built with plain vanilla JS: no backend, no build step, and no data leaves the machine.

11 min read

A Chrome extension (Manifest V3) that catches every media stream a page is playing, tells HLS master and variant playlists apart, keeps the real headers the browser sent (Referer / Cookie), and assembles a yt-dlp command you can paste and run right away.

Manifest V3Service WorkerwebRequest APIHLS (m3u8)DASH (mpd)yt-dlpSession StorageVanilla JS
Empathize · Define

The problem

Why does saving a video you already have access to for offline viewing get harder every year?

A raw m3u8 master playlist full of EXT-X-STREAM-INF tags, BANDWIDTH and RESOLUTION values, and variant links
Open a .m3u8 file directly and this is what you get — you have to read the tags yourself to see that 1080p and 720p are available (Mux public test stream)

Sites no longer embed a plain .mp4 file. They play HLS, which cuts the video into thousands of small segments (.ts / .m4s) controlled by a .m3u8 playlist. To save one for offline viewing you open DevTools → Network, hunt for the m3u8, then copy the Referer and Cookie into yt-dlp by hand. Doing that every time is slow and easy to get wrong.

— The starting brief for MP4/M3U8 Sniffer

Finding media URLs in DevTools is tedious

The Network tab has hundreds of requests. You filter for .m3u8/.mp4 yourself, and you still can't tell which one is the master playlist (the quality options) and which is the variant you actually need to download.

Downloading directly returns 403 because headers are missing

Pasting the URL into yt-dlp on its own often gets a 403, because the server checks the Referer / Origin / Cookie the browser sent during playback. DevTools usually hides those headers.

No way to tell how many qualities a stream has, or whether it's encrypted

Reading an m3u8 yourself means knowing tags like #EXT-X-STREAM-INF and #EXT-X-KEY. Most people can't tell whether 1080p/720p is available or whether the segments are AES-128 encrypted.

Sniffing YouTube directly is unreliable

YouTube serves streams from googlevideo.com with tokens that expire quickly, and splits video and audio into separate tracks. A captured link usually won't download, so it needs a different approach.

Media from old pages mixed with the new one

With several sites open in different tabs, media gets mixed together. You can't tell which link came from the page you're looking at, so you end up guessing.


Ideate

The solution

Let the extension do all the boring parts — catch, parse, build the command — so all that's left is "copy → paste → Enter"

A page playing an HLS video with the Sniffer popup open at the top right, listing the captured master and variants; the icon shows a badge with the number 3
Open a page that plays video (the hls.js demo) and click the icon — the actual popup lists every stream it caught, with URL / cmd / download buttons

Catches media automatically at the network layer

The service worker listens to webRequest. Any request matching .m3u8/.mpd/.mp4/.ts/.m4s, or with type = media, is stored immediately. No DevTools, no manual filtering.

Parses the real m3u8 and tells you which one to download

It fetches the playlist and parses it: which one is the master, which qualities it offers (1080p/720p), how many segments each variant has, how long it runs, and whether it's AES-128 encrypted — summarized in an easy-to-read table.

Builds the yt-dlp command with the real headers

It keeps the Referer/Origin/Cookie/User-Agent the browser actually sent and assembles a safely shell-quoted yt-dlp --referer ... --add-header ... command. One click copies it.

YouTube = download from the page URL

It detects YouTube watch/shorts/live pages and offers a yt-dlp command built from the page URL itself (far more reliable than sniffing googlevideo), stripping &list= so it doesn't pull the whole playlist.

Media kept strictly per tab

Every item is tied to a tabId. The popup only shows media from the page you're on; navigating away or closing the tab clears the old items automatically, and the badge counts per tab.


Prototype

How it works — 4 steps

From opening a page to a command ready to download

The popup groups streams by type: a master with its quality list, variants with segment count and duration, an AES-128 encrypted variant, and MP4 files with thumbnails
Step 3 for real: it parses the m3u8 and tells you which is the master and which are variants, how many segments, how long, and whether it's AES-128 encrypted (the links shown are public test streams)
1

Open the page

The video starts playing and the browser sends requests for the m3u8 and segments

2

The service worker catches them

Captures the URL and the real headers, ties them to the tabId and updates the badge count

3

Open the popup → parse

Fetches the m3u8 and parses it into master/variant, qualities and encryption

4

Copy the command

Press the yt-dlp button → copy the command with headers and paste it into a terminal


Prototype

Tech Stack & Architecture

Pure Manifest V3 — no backend, no build step, nothing leaves the machine

background.js code for webRequest.onSendHeaders, capturing requests per tabId and requesting extraHeaders
The heart of the service worker — listen to onSendHeaders with "extraHeaders", tie every item to a tabId, then update the badge (actual code from background.js)
The page playing the video (any origin)
HLS .m3u8 DASH .mpd .mp4 / .ts / .m4s YouTube watch/shorts
↕
Service Worker (background.js) — webRequest
onSendHeaders onBeforeRequest extraHeaders setBadgeText
↕
Popup (popup.js) — classifier + command builder
parseM3u8() analyze() buildCmd() ytCard()
↕
chrome.storage.session (per-tab, in-memory) + clipboard
items[] tabId binding onChanged → render
Why this stack?

Manifest V3 + Service Worker is the new standard Chrome requires — event-driven, no background page sitting in RAM · chrome.storage.session lives in memory and is cleared when the browser closes — right for temporary data that shouldn't stay on disk · host_permissions <all_urls> lets the popup fetch the m3u8 for parsing without hitting CORS · Plain vanilla JS — no build step, loads unpacked as is, the whole extension is about 4 files


Prototype

What I built — 8 core capabilities

The full loop, from catching network traffic to a command ready to download

The YouTube card in the popup, showing the clip title, a Download button, a 1080p button and a copy-command button
YouTube Smart Card — on a watch page you can download straight from the page URL, no googlevideo sniffing needed (&list= is stripped automatically)

Media Sniffer

Catches .m3u8/.mpd/.mp4/.ts/.m4s plus requests with type = media from webRequest — covering HLS, DASH and direct files

Real Header Capture

Uses extraHeaders to read the Referer/Origin/Cookie/User-Agent that are normally hidden — the key to getting past 403

HLS Classifier

Fetches and actually parses the m3u8 — master (with variants + audio/subs) vs variant (segment count + duration + AES)

Quality Resolver

Reads RESOLUTION/BANDWIDTH from the master and maps each variant to its label, such as 1080p/720p

yt-dlp Command Builder

Builds the command with headers and safe shell quoting (handles single quotes, spaces and semicolons in cookies)

YouTube Smart Card

Detects watch/shorts/live pages → offers two download commands from the page URL (best / 1080p) with the playlist parameter removed

Per-Tab Badge & Cleanup

Counts media per tab on the icon and clears it on navigation (main_frame) or when the tab closes — nothing stale left behind

Copy All / Rescan / Clear

Copy every URL at once, reload the tab to catch a fresh round, clear only the current tab — all controlled from one header


Prototype

The popup

Open a page with video → click the icon → see everything on one screen

The popup with a destination project and scene picker, a YouTube card, and a download queue of four jobs with progress bars, speed, and pause, resume and open-folder buttons
Download queue: % bar · speed · ETA · pause / resume — pick the destination scene from the top bar (project and file names are examples)
The popup listing captured streams: Master, Variant, AES-128 and MP4 files
The stream list — every row has URL / cmd / download buttons

Test & Iterate

Hacks and problems

6 problems I had to work out myself — Chrome extension API quirks and streaming internals

The yt-dlp command the popup builds, with --referer and several --add-header flags; a Cookie value containing a single quote is escaped as quote-backslash-quote
The command the cmd button copies — a Cookie containing ;, spaces and ' is wrapped in single quotes and escaped the POSIX way, so it pastes into a terminal without breaking (header values shown are examples)

Cookie / Referer are hidden from webRequest

By default onSendHeaders doesn't return headers the browser manages itself (Cookie, Referer, Origin). You only get a bare URL, and downloading it fails with 403.

Fix: add "extraHeaders" to the listener's extraInfoSpec so Chrome exposes the hidden headers, then whitelist only the 4 that yt-dlp needs (referer/origin/cookie/user-agent) and store nothing more.

Parsing the m3u8 needs a cross-origin fetch

To know which qualities a master offers, you have to fetch the playlist and read it — but a normal cross-origin fetch gets blocked by CORS.

Fix: declare host_permissions: <all_urls> in the manifest so the popup context can fetch across origins without CORS, then cache results per URL so it doesn't refetch on every re-render.

The master must be parsed before the variants to know their quality

The quality (1080p) lives in the master file, but at the network layer we only see bare variant URLs with no label.

Fix: parse the master → store a variantUrl → "1080p" map in variantRes first, then draw the table. Promise.all(analyze) finishes parsing everything before a single render, so each variant can pick up its label from the already-parsed master.

Media from the old page carries over into the new one

SPAs change pages without a reload, so old media stays in storage alongside the new page and the popup shows unrelated links.

Fix: listen to onBeforeRequest for main_frame only — the signal that the page really changed → clear that tabId's items and reset the badge, plus clean up on tabs.onRemoved. Storage stays clean.

Spaces and semicolons in cookies break the shell command

Real cookie values are full of ; and spaces. Appended straight into a shell command, they split the command or get misinterpreted.

Fix: a q() function wraps every value in single quotes and escapes inner single quotes as '\'' — the standard POSIX shell pattern, which makes a Cookie/Referer with special characters fully safe.

Sniffed YouTube links won't download

Catching googlevideo gives you a real URL, but its token expires quickly and audio is split from video — actual downloads almost never succeed.

Fix: change strategy — don't sniff googlevideo at all. Detect that you're on YouTube and let yt-dlp handle it from the page URL (it resolves the tracks and merges them), with cleanYt() stripping &list= so you don't download a whole playlist by accident. Lesson: some problems are better solved by not doing something than by forcing it to work.

Define

Deliberate design decisions

The scope I chose not to build matters as much as what I built

Python code for the native messaging host that validates the URL and runs yt-dlp through subprocess.Popen in a separate session
The actual downloader is yt-dlp — the native host only validates the URL and hands the job on, in a process separate from Chrome, so the job keeps running after the popup closes

This tool does one job: it builds the command faster. It doesn't download on its own, doesn't decrypt DRM, and doesn't send data off the machine. The classifier only reports that segments are AES-128 encrypted (so you know a key is needed) and never touches any key. Setting the scope clearly from the start made the implementation simple and straightforward.


Builds commands, doesn't download

yt-dlp does the downloading — the extension only prepares its input


Detect, don't decrypt

Reports that AES-128 encryption is present but leaves the key alone


Session storage only

Data lives in memory and disappears on close; nothing is written to disk


Whitelist 4 header

Stores only what yt-dlp needs, nothing more


Level Up · Reflect

Knowledge I gained

5 areas where my skills genuinely moved up through this project

A variant playlist with an EXT-X-KEY METHOD=AES-128 tag and an EXTINF entry for each segment
Reading every line of an m3u8: #EXT-X-KEY says the segments are AES-128 encrypted · #EXTINF is the length of each piece — the source of the "AES-128" label and the total duration in the popup
1. Chrome Extension MV3 — from "heard of it" to "built one":

I learned the service worker lifecycle (event-driven, no persistent background), when to use chrome.storage.session vs local, tying state to a tabId, and the badge API — going from zero to a complete extension I actually use. Lesson: MV3 forces event-driven thinking from the start.

2. HLS / streaming internals — reading every line of an m3u8:

I learned the structure of master vs variant playlists and the tags #EXT-X-STREAM-INF (RESOLUTION/BANDWIDTH), #EXT-X-MEDIA (audio/subtitle tracks), #EXTINF (duration per segment) and #EXT-X-KEY (AES-128/SAMPLE-AES), and wrote my own parser that classifies streams accurately. Lesson: video streaming is no longer a black box.

3. HTTP header semantics — understanding where a 403 comes from:

I learned how CDNs use Referer/Origin/Cookie to check access, why the browser hides some headers, and how extraHeaders exposes them — knowledge that carries straight over to debugging API auth and CORS. Lesson: headers are half the key to web security.

4. Shell-safe string building — a security path you can't get wrong:

I practiced writing quoting that is actually safe (the '\'' escape) instead of gluing strings together, and learned that untrusted input (cookies from a website) must always be sanitized before it goes into a command. Lesson: correct quoting patterns prevent command injection.

5. Scoping — knowing that what you leave out is good design:

I chose not to sniff YouTube, not to decrypt and not to auto-download, which keeps the tool small, easy to understand and within sensible bounds. Lesson: a sharp scope makes implementation direct and maintenance easier than a tool that tries to do everything.

4
Files — the whole extension (no build)
5
Media formats it catches
1
Click — from network to a ready-to-run command
0
Data sent off the machine

Tan · Natpakan Sirirat

Product Designer & AI Builder — designing user experiences and building AI tools that actually work.

0%