After combining a few ideas, I got my firefox to open spotify links à la
directly in my running Linux Spotify client. Here's how:
1. Install Greasemonkey (Firefox) or Tampermonkey (Chrome) and then this script.
I modified it to not even open the web-player but directly redirect to spotify by adding the line
// @run-at document-start
in the header section of the script. I sent a request to the author to incorporate that change.
2. Create a new spotify URI handler at ~/.local/share/applications/spotify-open.desktop with the content
[Desktop Entry] Type=Application Name=Open in Spotify GenericName=Music Player Icon=spotify-client Exec=qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri %U Terminal=false MimeType=x-scheme-handler/spotify; Categories=Audio;Music;Player;AudioVideo; StartupWMClass=spotify
Make sure you have qdbus installed. On Arch Linux, this is found in package qt5-tools.
Now if you click on any open.spotify.com link, it will automatically play in your client.