DEV Community

alapha888
alapha888

Posted on

YouTube changed its transcript DOM: the old selector silently returns zero rows

While building a small transcript exporter for YouTube, I hit a silent failure: the panel-based transcript path returned zero rows, with no error anywhere.

The old selector ytd-transcript-segment-renderer matches nothing on current YouTube. The transcript panel now renders <transcript-segment-view-model> elements, with the timestamp in .ytwTranscriptSegmentViewModelTimestamp and the text in span[role="text"].

What I verified in a real browser (headless Chrome, extension loaded, panel opened on a real video): the new selectors returned 24 cues / 2,066 characters, and the TXT / MD / SRT / VTT exports built from those cues came out at 2,335 / 2,668 / 3,142 / 3,162 bytes, spot-checked correct. The old selector returned 0 hits on the same page.

The fix is boring, and that is the point: try the new DOM first, fall back to the legacy renderer rows, and treat "zero rows" as a signal to re-check the DOM rather than as an empty transcript.

function panelRows() {
  const rows = [...document.querySelectorAll('transcript-segment-view-model')];
  if (!rows.length) return null; // fall back to the legacy renderer rows
  return rows.map(row => ({
    time: row.querySelector('.ytwTranscriptSegmentViewModelTimestamp')?.textContent?.trim() ?? '',
    text: row.querySelector('span[role="text"]')?.textContent?.trim() ?? '',
  }));
}
Enter fullscreen mode Exit fullscreen mode

Two caveats from the same testing session. First, the panel only gives the rows currently rendered (24 on the first screen here), not the full transcript; the timedtext endpoint is the only full-length path. Second, from a datacenter IP, timedtext returned empty bodies even inside a real browser — real users on residential IPs should be fine, but I could not verify that from my environment.

The exporter itself is in review on Edge. Its privacy page is at https://alapha888.github.io/yt-transcript-export-privacy/

Top comments (0)