Control desktop Spotify application from web browser using JavaScript

I want to trigger music playback in the Spotify desktop app when someone clicks a button on my webpage. I’ve seen this work before where clicking play on a website would automatically start a track in the actual Spotify client running on the computer. The desktop app wouldn’t even need to come to the foreground, it would just begin playing in the background.

I need this functionality for my web application. When users interact with a play button, I want the music to start in their local Spotify application if it’s already running.

I’ve tried several approaches that didn’t give me what I need:

  • Spotify Web API integration
  • Spotify web player widget
  • Direct song URL redirects

The key requirement is that I don’t want audio playback happening through the browser itself. I specifically need to communicate with the native Spotify desktop client. Has anyone found a solution for this type of integration?

yeah, this worked years back but spotify axed it for security. browsers can’t control desktop apps anymore - makes sense tho. the only fix i’ve seen uses custom protocols, but its hacky and breaks constantlly.

Unfortunately, what you’re aiming for isn’t currently feasible due to various security restrictions imposed by browsers and changes in Spotify’s policies. The old method via the SpotifyLocalAPI allowed for desktop integration, but it has since been discontinued. What remains are options like utilizing spotify:track:id URLs, which can initiate playback but require user interaction and aren’t seamless. While some developers have attempted to bypass these limitations through browser extensions or Electron frameworks, they necessitate additional installations, which might not be ideal for your users. Therefore, you’re largely left with using Spotify’s web playback SDK or embedded players that function within the browser environment.