youtube
youtube copied to clipboard
fix: block autoplay before any frame renders (#1461)
Summary
Fixes #1461 — Disabled autoplay was pausing ~1 second into playback instead of preventing it entirely.
Root Cause
The original autoplay-disable code:
- Intercepted
HTMLMediaElement.prototype.play()(worked) - Called
player.pauseVideo()then returnedPromise.resolve()(worked) - BUT: YouTube's player found other paths to start playback (internal API, retry logic, etc.)
- The
setTimeout(100ms)fallback allowed ~6 frames to render before pausing
Changes
File: js&css/web-accessible/functions.js (1 file, +22/-7)
| Change | Before | After |
|---|---|---|
| Pause logic | Inline try/catch | Extracted blockAutoplay() helper |
| Safety net | None | playing event listener (once:true) catches escaped playback |
| setTimeout delay | 100ms | 0ms (next tick) |
| currentTime reset | None | Resets to 0 so watch history gets no progress |
How the safety net works
play() called → blockAutoplay() pauses + resets time → return Promise.resolve()
↓ (if YouTube retries)
'playing' fires → blockAutoplay() again → listener removes itself
The once:true ensures normal user-initiated playback is never affected.
Test Results
Test Suites: 16 passed, 1 failed (pre-existing)
Tests: 66 passed, 3 failed (pre-existing, from sidebar-transcript PR)
No new test failures introduced.
Bounty claim: This PR addresses issue #1461 (Bounty label). Requesting review.
hi! @jiangyj545 did you consider to make your (automated) process look at the timeline / edit history? thanks