Add auto-pause support for YouTube Music in Chromium browsers - #864
Open
juansegnana wants to merge 2 commits into
Open
Add auto-pause support for YouTube Music in Chromium browsers#864juansegnana wants to merge 2 commits into
juansegnana wants to merge 2 commits into
Conversation
Add BGMYouTubeMusic, a music player that auto-pauses YouTube Music (https://music.youtube.com) running in a Chromium-based browser. It returns one instance per installed browser among Brave, Chrome and Edge. These browsers share Chrome's AppleScript dictionary (see the generated Chromium.h), so we use Scripting Bridge to find the tab that has YouTube Music open and read/control its <video> element via the browser's "execute javascript" command. Controlling the video element directly is robust because YouTube Music's UI stays in sync with it. Two caveats: - "execute javascript" only works if the user has enabled View > Developer > Allow JavaScript from Apple Events in their browser (a one-time, persistent setting). When it's disabled the browser refuses the command, so we show a one-time dialog explaining how to enable it and behave as if nothing is playing. - BGMDriver matches audio to the browser by bundle ID, which all of a browser's tabs share. Audio from YouTube Music is therefore indistinguishable at the driver level from audio played by another tab of the same browser, so auto-pause won't trigger for audio played in a different tab of the same browser.
Chromium-based browsers (Brave, Chrome, Edge) play their audio from helper processes whose bundle IDs are children of the browser's bundle ID, e.g. com.brave.Browser.helper.renderer. The driver matched the music player's audio by exact bundle ID equality, so a browser-based music player never matched its own audio: that audio was classified as non-music, which made auto-pause pause the music player, which produced silence, which unpaused it, looping every few seconds. Match child bundle IDs by prefix as well, so a music player set to a browser's bundle ID also matches the browser's helper processes.
juansegnana
force-pushed
the
feature/youtube-music-auto-pause
branch
from
July 10, 2026 03:00
c9eebf3 to
ef50aa6
Compare
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.
Adds a
BGMMusicPlayerfor YouTube Music running in Chromium-based browsers (Brave, Chrome, Edge) — one instance per installed browser. It controls themusic.youtube.comtab's<video>element via ScriptingBridge's "execute javascript".Requires enabling View → Developer → Allow JavaScript from Apple Events in the browser (a dialog explains this once).
The second commit fixes a related driver bug: BGM matched the music player by exact bundle ID, but browser audio is produced by helper/renderer child processes (e.g.
com.brave.Browser.helper.renderer), not the maincom.brave.Browserprocess. As a result the player never matched and auto-pause oscillated on/off. The driver now matches by exact or parent-prefix bundle ID (<bundleID>.). This is generic and also helps other browser-based players.Testing
Known limitation
Audio from other tabs in the same browser can't be distinguished from YouTube Music at the driver level.
Related issues
Closes #768, closes #188, closes #511.
Related, but not fully covered here (desktop/GPMDP apps or generic browser support): #547, #551, #581, #737.