// FIND A LIVE PAGE'S PLAYLIST THE WAY ITS PLAYER DOES — record-live's path B // (controller/recordLive.ts), when yt-dlp's own requests are refused. // // node liveSniff.mjs [waitMs] // // Opens the page in Chromium, keeps every .m3u8 URL the page requests, closes // the browser and prints one JSON line: {ok, status, playlists, error?}. // // HEADED, UNDER A VIRTUAL DISPLAY. Measured 2026-10-22: Rumble's Cloudflare // answers 403 to headless Chromium (old and new headless, with or without the // operator's Firefox cookies and user agent) and 200 to a headed Chromium. So // the caller runs this under `xvfb-run -a` (no window on the operator's // screen) and it launches headed with `--ozone-platform=x11`. With no DISPLAY // it falls back to headless and says so. // // Plain JS: run by bare `node`, Playwright resolved from the workspace package // that installs it (editor/), as social/playwrightRuntime.ts does. import { createRequire } from "node:module"; import path from "node:path"; const [root, pageUrl, waitRaw] = process.argv.slice(2); const waitMs = Number(waitRaw) > 0 ? Number(waitRaw) : 12000; function out(o) { process.stdout.write(`${JSON.stringify(o)}\n`); } function loadChromium() { for (const dir of [path.join(root, "editor"), path.join(root, "export"), root, process.cwd()]) { try { const req = createRequire(path.join(dir, "__resolve__.cjs")); const m = req("@playwright/test"); if (m?.chromium) return m.chromium; } catch { /* next */ } } return null; } const chromium = loadChromium(); if (!chromium || !pageUrl) { out({ ok: false, status: null, playlists: [], error: chromium ? "no page URL" : "Playwright is not installed in this checkout" }); process.exit(0); } const headed = Boolean(process.env.DISPLAY); let browser = null; const playlists = []; try { browser = await chromium.launch({ headless: !headed, args: ["--disable-blink-features=AutomationControlled", ...(headed ? ["--ozone-platform=x11"] : [])], }); const ctx = await browser.newContext({}); const page = await ctx.newPage(); page.on("request", (r) => { const u = r.url(); if (/\.m3u8(\?|$)/i.test(u) && !playlists.includes(u)) playlists.push(u); }); const res = await page.goto(pageUrl, { waitUntil: "domcontentloaded", timeout: 45000 }); const status = res ? res.status() : null; // The player asks for its playlist a few seconds after the page loads. const until = Date.now() + waitMs; while (Date.now() < until && !playlists.some((u) => /chunklist|\/media\/hls\//i.test(u))) { await page.waitForTimeout(500); } out({ ok: playlists.length > 0, status, playlists, headed, ...(playlists.length ? {} : { error: status && status >= 400 ? `the page answered HTTP ${status}` : "the page asked for no playlist" }), }); } catch (err) { out({ ok: false, status: null, playlists, headed, error: String(err?.message ?? err).slice(0, 300) }); } finally { await browser?.close().catch(() => {}); }