21. Nov 2020 |

Let the Spotify play your favourite songs by 30 seconds

Inspired by this article and the economic situation for musicians I wrote this little script. This lets Spotify to play your favourite artists on rotation and automatically presses “next” after every 33 (+ littlebit of random) seconds. 30 seconds is the minimum amount of time a song must be listened to before Spotify registers a single “play”.

Loading the song also takes little bit of time so you can not maximize the play count by making the loop take exactly 30 seconds long.

function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min) + min);

function doSomething() {
    var button = document.querySelector('[aria-label="Next"]');

(function loop() {
    var rand = getRandomInt(33000, 37000);
    setTimeout(function() {
    }, rand);

If you are using Spotify in your browser the press ctrl+shift+k or just F12, open console tab, paste this code there and press enter. This code does nothing but pressing the button with title attribute “Next” after every 33-37 seconds (random between these times).

Example of how it works in browser.

It is one option to support your favourite artists 🙂

8 thoughts on “Let the Spotify play your favourite songs by 30 seconds”

  1. Script doesn’t work!
    I copied the code in Chrome & Firefox and get only an error code after a few seconds.

  2. Hi. I just tested and it works for me. I made this gif (in the post) to show you how to use it. Maybe helps. You need to start playing (some playlist preferably) and it just presses “next”.

  3. Hi Robert,

    Thanks for your reply!
    I tried the script again in Chrome & Firefox and still get the following error:

    Uncaught TypeError: button is null
    doSomething debugger eval code:8
    debugger eval code:14
    r https://open.scdn.co/cdn/build/web-player/vendor~web-player.e07a6039.js:1
    setTimeout handler*82303/ze</e.prototype._wrapTimeFunction/< https://open.scdn.co/cdn/build/web-player/vendor~web-player.e07a6039.js:1
    loop debugger eval code:13
    debugger eval code:17

    I’m doing exactly the same as described above and as the GIF shows, but keep getting the error. Could it be the browser?

  4. Hey I tested it in both mozilla and chrome and it skipped after 4 seconds or 15 seconds but never reached 30 seconds please test it and make it for 30 seconds

      1. You are correct. Gif is different because otherwise the gif should be at least 30 seconds long. But the purpose of this gif is just to demonstrate how it works so I made the click span shorter (only for demo). In the JS code you can see values such as 33000 and 37000. These are min and max time in milliseconds. You can modify these according to your preferences.

  5. First open the web player then open console and add the given code change the milliseconds 33000 to 37000 and 37000 to 40000 and then click enter. Now click the play button and it will work.
    It will play a track between 37 t0 40 seconds.

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.