Muting Spotify Ads

Published: 2020-10-19 | Tags: ads

Update: 12/3/2020 - Spotify changed the skip button, the script has been updated to work with the new version of the Spotify web player.

I really hate Spotify's audio ads. While, it might be unethical to totally skip the ads(without paying for Spotify premium), I think that it is ok to mute them.

There are several other solutions to do this including an Android app,a Chrome extension and a desktop app. However, they all have to be installed. So I created the one below which can just be pasted into the Firefox or Chrome developer console.

function adPlaying(){
    // Determine if add is playing
    var skipButton = document.querySelector('[aria-label="Next"]')

    if(skipButton.disabled == true){
        console.log("An ad is playing");
        return true;
    }else{
        return false;
    }
}
function muteAudio(action){
    var clickButton = null;
    if(action){
        // Mute the audio
        console.log("Clicking the mute button")
        clickButton = document.querySelector('[aria-label="Mute"]');
    }else{
        // Unmute the audio
        console.log("Clicking the unmute button")
        clickButton = document.querySelector('[aria-label="Unmute"]');      
    }
    // click the button
    if (clickButton != null){
        clickButton.click()
    }

}

// See if the title has changed
const target = document.querySelector('title');

// set config for observer
const config = { attributes: true, childList: true, subtree: true, characterData: true };

// Callback function
const callback = function(mutations, observer) {
    // check if ad is playing
    if(adPlaying()){
        muteAudio(true);
    }else{
        muteAudio(false);
    }

};

var observer = new MutationObserver(callback);
observer.observe(target, config);