From Prompt to Manifest V3: Lessons Learned Building a Browser Stream Inspector with AI Coding Agents

building a stream sniffer to download videos

Modern web video has moved far beyond static  .mp4  files. Today, streaming media is delivered through adaptive playlists, demuxed audio/video tracks, encrypted segments, and raw transport containers. When I set out to build StreamSniffer, a zero-dependency Chrome Extension capable of passively detecting streams, decrypting AES-128 HLS segments, and remuxing raw MPEG-TS into Fragmented MP4 ( fMP4 ) directly inside the browser, I treated the project as both a systems-engineering exercise and a testbed for AI-assisted software development.
Building a real-time binary media pipeline inside Chrome's Manifest V3 sandbox quickly reveals where AI coding agents shine, where they hallucinate subtle binary-format bugs, and where cloud architectures still hold the crown over client-side compute.



1. The Problem & Manifest V3 Browser Architecture

In HTTP Live Streaming (HLS) and DASH architectures, video players fetch a master playlist ( .m3u8 ) that points to separate bitrate renditions and often completely separate audio and video sub-playlists. Each sub-playlist references hundreds of short media chunks—typically packaged as raw MPEG-TS ( .ts ) transport streams—and frequently encrypted with AES-128-CBC keys fetched over separate HTTP requests.
Observing and assembling these streams in Chrome requires navigating strict Manifest V3 (MV3) architectural constraints:
  • Passive Network Observation ( chrome.webRequest ): While MV3 replaced blocking  webRequest  interception with  declarativeNetRequest  for modifying traffic, read-only  chrome.webRequest  listeners remain ideal for passively inspecting response headers and URLs per  tabId  to detect  .m3u8  playlists and progressive media in real time.
  • Bypassing Service Worker Timeouts with  chrome.offscreen : MV3 replaced persistent background pages with ephemeral Service Workers that terminate after ~30 seconds of inactivity and lack DOM APIs like  URL.createObjectURL() . Meanwhile, running downloads inside  popup.js  aborts the pipeline the moment the user clicks outside the extension window.
  • Persistent Offscreen Workers + OPFS: To keep multi-gigabyte downloads alive independently of the popup, StreamSniffer delegates the heavy lifting to a dedicated  offscreen  document ( offscreen.js ). Inside that offscreen context, a 24-worker sliding-window pool fetches and decrypts segments via the native Web Crypto API ( crypto.subtle ), remuxes them in JavaScript, and flushes every fragment directly to disk via the Origin Private File System (OPFS) ( navigator.storage.getDirectory() ), keeping V8 heap usage under ~25 MB even on 1.3 GB+ streams.



2. Working Effectively with AI Coding Agents

AI coding agents dramatically accelerate boilerplate generation—setting up  manifest.json , message-passing bridges between  background.js  and  offscreen.js , and dark-mode popup telemetry. However, once you cross into low-level binary protocols (ISO BMFF boxes, Annex-B NAL units, and MPEG-TS packets), blind "vibe coding" breaks down fast. Three workflow habits made the difference between spinning in circles and shipping a clean implementation:

Clear Architectural Prompts Over Monolithic Asks

Asking an agent to "build an HLS downloader extension" produces fragile prototypes that buffer entire videos into an  ArrayBuffer[]  array (triggering  RangeError: Array buffer allocation failed  on HD videos) and dump raw  .ts  chunks into a  Blob . Breaking the prompts into isolated, single-responsibility modules, first playlist resolution ( resolvePlaylistTracks() ), then sliding-window Web Crypto decryption, then a standalone  FMP4Muxer  class, and finally OPFS disk streaming—kept the agent's context focused and testable.

Atomic Git Commits as Guardrails

When iterating across AI models to debug binary stream parsers, an agent will frequently "fix" a timestamp calculation while silently breaking a 4-bit continuity counter or header offset elsewhere in the file. Committing every working milestone atomically gave me instant  git diff  visibility into regressions and a clean rollback point whenever a model over-engineered a parser.

Manual Debugging Beats Blind Re-Prompting

Two of the hardest bugs in StreamSniffer required inspecting raw container behavior manually rather than pasting stack traces back into a prompt:
  1. The  .ts  vs.  .mp4  Container & MIME-Sniffing Quirk: Early builds concatenated raw  .ts  segments. Because raw MPEG-TS lacks a global container header, players like Windows Media Player and QuickTime struggled to open the output, and passing an untyped OPFS file handle to Chrome's download manager caused Chrome to sniff the binary header as  text/plain , saving video files with a  .txt  extension. Catching this required manually inspecting the output headers, wrapping the final stream in an explicit  new Blob([finalFile], { type: "video/mp4" }) , and building a custom  FMP4Muxer  to emit standard  ftyp ,  moov ,  moof , and  mdat  boxes.
  1. H.264 B-Frame Reordering ( PTS  vs.  DTS ): In H.264 High Profile streams with bidirectional B-frames, Presentation Timestamps ( PTS ) differ from Decoding Timestamps ( DTS ). An early AI-generated muxer sorted packets by  PTS , placing B-frames ahead of the P-frames they depended on, causing hardware decoders to drop the video track completely and play audio only. Tracing the frame order manually revealed the root cause: sorting video access units strictly by  DTS  and encoding the signed Composition Time Offset ( CTS = PTS - DTS ) inside version-1 ISO BMFF  trun  boxes.



3. Client-Side vs. Cloud Media Processing Trade-Offs

Building an in-browser remuxer highlights a classic cloud architecture trade-off: when should compute stay on the client, and when should it move to AWS?
Dimension
Client-Side Browser Pipeline (StreamSniffer)
Serverless Cloud Pipeline (AWS S3 + Lambda / MediaConvert)
Infrastructure Cost
$0 — runs 100% on the user's CPU, network, and OPFS disk.
Pay-per-use compute, storage, and egress ( S3 ,  Lambda ,  MediaConvert ).
Latency & Privacy
Instant start; media segments and AES-128 keys never leave the user's machine.
Requires uploading or fetching segments into S3 before processing begins.
Processing Scope
Best for remuxing (repackaging H.264 + AAC from TS to  fMP4  without re-encoding).
Ideal for transcoding (changing codecs like HEVC → H.264, scaling bitrates, burning subtitles).
Concurrency & Scale
Bound by browser tab/offscreen worker limits and client bandwidth.
Virtually unlimited horizontal fan-out via AWS Step Functions, Lambda, and AWS Elemental MediaConvert.



The Architectural Rule of Thumb:
  • Keep it client-side when you are only demuxing, decrypting, and repackaging existing elementary streams ( stream_type = 0x1B  H.264 and  0x0F  AAC). Modern JavaScript engines, Web Crypto, and OPFS handle packet-level byte manipulation at hundreds of megabytes per second with zero server footprint.
  • Offload to AWS the moment you need heavy transcoding, multi-bitrate ABR packaging, or legacy seek-table indexing. Running full FFmpeg or WebAssembly transcoders inside a browser offscreen document drains battery and throttles the UI thread. On AWS, an event-driven pipeline, ingesting raw segments into Amazon S3, triggering AWS Lambda via EventBridge/S3 notifications, and orchestrating AWS Elemental MediaConvert or containerized FFmpeg workers on AWS Fargate, decouples heavy compute from the client and scales effortlessly across thousands of concurrent jobs.


Explore the Code

You can inspect the full Manifest V3 implementation—including the 24-worker sliding-window downloader, Web Crypto AES-128 decryptor, OPFS disk writer, and custom  FMP4Muxer  ISO BMFF engine on GitHub:
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article