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.

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.
The problem
Why does saving a video you already have access to for offline viewing get harder every year?

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.
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.
The solution
Let the extension do all the boring parts — catch, parse, build the command — so all that's left is "copy → paste → Enter"

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.
How it works — 4 steps
From opening a page to a command ready to download

Open the page
The video starts playing and the browser sends requests for the m3u8 and segments
The service worker catches them
Captures the URL and the real headers, ties them to the tabId and updates the badge count
Open the popup → parse
Fetches the m3u8 and parses it into master/variant, qualities and encryption
Copy the command
Press the yt-dlp button → copy the command with headers and paste it into a terminal
Tech Stack & Architecture
Pure Manifest V3 — no backend, no build step, nothing leaves the machine

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
What I built — 8 core capabilities
The full loop, from catching network traffic to a command ready to download

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
The popup
Open a page with video → click the icon → see everything on one screen


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

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.
"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.
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.
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.
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.
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.
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.Deliberate design decisions
The scope I chose not to build matters as much as what I built

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
Knowledge I gained
5 areas where my skills genuinely moved up through this project

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.
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.
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.
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.
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.
