Clicks on the annoying buttons for you
In order for the script to work, YouTube Music needs to be the active tab! You can drag its tab out of the tabs bar, and leave it as a separate window. This is a browser restriction, background scripts don't work unless their tab is selected.