Skip to content

Add auto-pause support for YouTube Music in Chromium browsers - #864

Open
juansegnana wants to merge 2 commits into
kyleneideck:masterfrom
juansegnana:feature/youtube-music-auto-pause
Open

Add auto-pause support for YouTube Music in Chromium browsers#864
juansegnana wants to merge 2 commits into
kyleneideck:masterfrom
juansegnana:feature/youtube-music-auto-pause

Conversation

@juansegnana

@juansegnana juansegnana commented Jul 10, 2026

Copy link
Copy Markdown

Adds a BGMMusicPlayer for YouTube Music running in Chromium-based browsers (Brave, Chrome, Edge) — one instance per installed browser. It controls the music.youtube.com tab'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 main com.brave.Browser process. 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

  1. Enable "Allow JavaScript from Apple Events" in the browser.
  2. Preferences → Music Player → the browser's YouTube Music entry.
  3. Play a video, then start audio in another app → YouTube Music pauses.
  4. Stop the other audio → it resumes.

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.

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
juansegnana force-pushed the feature/youtube-music-auto-pause branch from c9eebf3 to ef50aa6 Compare July 10, 2026 03:00
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.

Request: Support Youtube Music Please add YouTube music to the preference. Auto-pause support for Youtube Music?

1 participant