fix: prevent autoplay playback before play() is called#3758
Merged
ImprovedTube merged 2 commits intocode-charity:masterfrom Apr 6, 2026
Merged
fix: prevent autoplay playback before play() is called#3758ImprovedTube merged 2 commits intocode-charity:masterfrom
ImprovedTube merged 2 commits intocode-charity:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, theautoplayDisable()function was called inside theHTMLMediaElement.prototype.playoverride, but thepauseVideo()call was scheduled viasetTimeout(0). By the time the callback ran, the video had already started playing (sinceplay()returns a Promise that resolves asynchronously).Fix
The fix restructures the autoplay prevention to check conditions BEFORE calling
original.play():play()method, we check if autoplay should be blocked based on storage settings (player_autoplay_disable,playlist_autoplay,channel_trailer_autoplay).video.pause()synchronously BEFOREplay(), preventing any video playback.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: