Apple Music Track info in tab title

Show track information in tab title in Apple Music Web

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Apple Music Track info in tab title
// @namespace    http://tampermonkey.net/
// @version      2024-01-30
// @description  Show track information in tab title in Apple Music Web
// @author       Pango
// @match        https://*.music.apple.com/*
// @icon         https://www.google.com/s2/favicons?domain=music.apple.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const sleep = ms => new Promise(r => setTimeout(r, ms)); // Don't judge me, musickitloaded event is broken and fires too early, causing MusicKit.getInstance() to return undefined

    sleep(2000).then(() => {
        const music = MusicKit.getInstance();
        music.addEventListener('nowPlayingItemDidChange', ({ item: nowPlayingItem }) => {
            document.title = `${nowPlayingItem.attributes.name} - ${nowPlayingItem.attributes.artistName} - Apple Music`;
        });
    })
})();