Add YouTube Background Play userscript - #21
Open
VeigaPunk wants to merge 2 commits into
Open
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.
What
Adds a new userscript,
youtubeBackgroundPlay/youtube-background-play.user.js, that keeps YouTube and YouTube Music playing when the tab is hidden or the screen is locked.It is a port of the well-known "YouTube Background Playback" Firefox fix, adapted for userscript managers (tested with AdGuard's userscript engine / Dguard).
How it works
document.hidden,visibilityState(incl. vendor-prefixed variants) andhasFocus()always report visible/focused.visibilitychange,blur,focusout,pagehide,freezeare stopped at capture phase, and listener registration for them onwindow/documentis swallowed so site pause logic never hooks them.pauseVideo()andHTMLMediaElement.pause()so programmatic pauses without a recent real user gesture (~1.5s window) are ignored, while genuine user pauses keep working.Runs at
document-start,@grant none, no external dependencies. Matches*.youtube.com,*.youtube-nocookie.comandmusic.youtube.com.Metadata
@downloadURL/@updateURLfollow the repo convention (raw GitHub URLs onmaster), so once merged, users get automatic updates from this repo.Also published on Greasyfork for testing: https://greasyfork.org/en/scripts/589117-youtube-background-play-firefox-fix-port
License: MIT (compatible with the repo's GPLv3 as a contribution).