Skip to content

fix: prevent autoplay playback before play() is called#3758

Merged
ImprovedTube merged 2 commits intocode-charity:masterfrom
TeapoyY:fix/autoplay-disable-timing
Apr 6, 2026
Merged

fix: prevent autoplay playback before play() is called#3758
ImprovedTube merged 2 commits intocode-charity:masterfrom
TeapoyY:fix/autoplay-disable-timing

Conversation

@TeapoyY
Copy link
Copy Markdown

@TeapoyY TeapoyY commented Apr 5, 2026

Summary

This PR fixes a bug where disabling autoplay would cause videos to play for approximately 1 second before being paused, instead of preventing playback entirely.

Root Cause

In js&css/web-accessible/functions.js, the autoplayDisable() function was called inside the HTMLMediaElement.prototype.play override, but the pauseVideo() call was scheduled via setTimeout(0). By the time the callback ran, the video had already started playing (since play() returns a Promise that resolves asynchronously).

Fix

The fix restructures the autoplay prevention to check conditions BEFORE calling original.play():

  1. Check conditions first: Before invoking the original play() method, we check if autoplay should be blocked based on storage settings (player_autoplay_disable, playlist_autoplay, channel_trailer_autoplay).
  2. Pause synchronously: If autoplay should be blocked, we call video.pause() synchronously BEFORE play(), preventing any video playback.
  3. Return resolved Promise: We return Promise.resolve() to satisfy callers without triggering the browser autoplay mechanism.

This ensures the video never starts playing in the first place, rather than pausing after the fact.

Issues Fixed

Testing

The fix has been tested for:

  • Direct URL navigation to watch pages
  • Opening videos in new tabs
  • Playlist pages with playlist_autoplay === false
  • Channel homepage with channel_trailer_autoplay === false

@ImprovedTube ImprovedTube merged commit 6a0968a into code-charity:master Apr 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants