Intercepting Social Media Video Streams: A 40-Line Console Script

Published: (February 1, 2026 at 03:35 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

How it works

It overrides fetch() and XMLHttpRequest.open() to intercept outgoing network requests. When it spots an .mp4 URL, it strips the byte‑range parameters and logs the clean URL. The getVideoUrls() helper lets you retrieve everything collected, useful if your console gets noisy.

// Instagram Story Video URL Extractor
(() => {
    const videoUrls = new Set();

    // Strip start and end time params
    const cleanUrl = (url) => {
        const u = new URL(url);
        u.searchParams.delete('bytestart');
        u.searchParams.delete('byteend');
        return u.toString();
    };

    // Intercept fetch
    const origFetch = window.fetch;
    window.fetch = async function(url, ...args) {
        const urlStr = url?.toString?.() || url;

        // Domain and extension matcher, you can drop the domain to use this elsewhere
        if (urlStr.includes('fbcdn.net') && urlStr.includes('.mp4')) {
            const clean = cleanUrl(urlStr);
            if (!videoUrls.has(clean)) {
                videoUrls.add(clean);
                console.log('> Video found:', clean);
            }
        }
        return origFetch.apply(this, [url, ...args]);
    };

    // Intercept XHR
    const origOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {

        // Domain and extension matcher, you can drop the domain to use this elsewhere
        if (url?.includes?.('fbcdn.net') && url?.includes?.('.mp4')) {
            const clean = cleanUrl(url);
            if (!videoUrls.has(clean)) {
                videoUrls.add(clean);
                console.log('> Video found:', clean);
            }
        }
        return origOpen.apply(this, arguments);
    };

    // Helper to get all collected URLs
    window.getVideoUrls = () => {
        const urls = [...videoUrls];
        console.log(`\nFound ${urls.length} video(s):\n`);
        urls.forEach((url, i) => console.log(`${i + 1}. ${url}\n`));
        return urls;
    };

    console.log('Extractor active - play stories/reels, then run getVideoUrls()');
})();

Note: This script is for research purposes only. Do not download content you do not own.

How to use (for total beginners)

  1. Open DevTools (press F12).
  2. Paste the script into the console and press Enter.
  3. Play the desired video(s); URLs will appear in the console.
  4. Optionally run getVideoUrls() to list all collected URLs.
  5. Open a URL in a new tab to view the video, or right‑click → Save As to download.
Back to Blog

Related posts

Read more »