Project
ArchivedHomepage Now Playing Widget
A bigger, two-column now-playing feature for the homepage, real album art, an accent colour pulled from the artwork, and a marquee for titles too long to fit.

UPDATE: As of October 2026 this widget has been retired and is no longer on the site. This write-up is kept as a record of how it was built.
The /about page has had a small “now playing” widget for a while displaying album art, track, artist, but nothing more. This is the bigger sibling to that: a two-column feature on the homepage itself, pulling from the same last.fm-backed Cloud Run service, just asking more of it.
Layout
Left side is the current (or last-played) track: bigger album art, a pulsing live indicator when something’s actually playing, and a decorative equaliser that animates only while live and freezes into static bars otherwise it’s not reacting to real audio, so it doesn’t pretend to. Right side is the four most recent tracks, thumbnails and all, each with a small muted relative timestamp (6m, 23m) rather than a rank number, since the list order already makes recency obvious.
![]()
One thing that’s deliberately missing: a scrub bar. Last.fm’s user.getrecenttracks endpoint tells you what’s playing, never how far into it, no position, no duration. A progress bar would have to fake a number, so it isn’t there.
Extending the API without breaking the existing widget
The backend originally fetched a single track (limit=1) and returned one flat object. Bumping that to limit=4 and adding a recentTracks array to the response was enough to power the whole homepage feature, while the existing /about widget — which only reads the top-level fields — never had to change at all.
Polling, without hammering the DOM
The widget polls every 60 minutes so a track change shows up without a refresh, pausing entirely while the tab is backgrounded and refreshing immediately the moment it’s focused again. I played with different timings on this, from once very 60 seconds, to every 5 seconds, but polling that often was quietly restarting the entire card, including an in-progress title animation, on every single tick, even when the track hadn’t changed. The fix was to key the render on track::artist::isPlaying and skip the rebuild entirely when nothing meaningful changed, only patching the “X min ago” text in place.
In the end I settled on polling every 60 minutes as this is just an example of what this function looks like. It’s not critical to have constant polling for this use case, and don’t forget the Cloud Run function is running with each request so there’s a £ cost. By all means shorten the polling time and play with your heart’s content, but also keep an eye on your billing account! 🤣
An accent colour pulled from the artwork
The dot and the equaliser bars borrow a colour sampled straight from the currently-playing album art, drawn to a tiny offscreen canvas, averaged, then desaturated and clamped to a legible lightness range so it reads as a subtle tint rather than a raw, sometimes-neon pixel average. It falls back to the site’s normal accent colour if the sample ever fails.
A marquee for long titles
Long titles truncate with an ellipsis by default. If the title is genuinely too long to fit, it scrolls: a 10-second pause, a slow scroll to reveal the end, a short pause, scroll back, repeat. It’s built on the Web Animations API rather than a CSS @keyframes rule, since the scroll distance, and how long that leg should take at a steady, readable pace, depends on exactly how much a given title overflows, which isn’t knowable until it’s actually laid out.
The one real bug here: easing belongs on each keyframe, not in the animation’s options. Setting a single top-level ease-in-out applies that curve across the entire multi-segment timeline — pause, scroll, pause, scroll — which badly warps a long pause into lasting far longer than intended, since ease-in-out starts slow. Moving the easing onto the individual keyframes (each one governing just its own segment) fixed it. Caught by literally sitting a headless browser in front of it for a minute and watching the transform values, not by reading the code.
Small things that add up
- album art gets a graceful
onerrorfallback to a placeholder, Last.fm doesn’t always have art at every size for every track - a 1px translucent border plus a soft shadow gives pale covers enough separation from a pale background without turning the card into a floating tile
min-width: 0on the grid/flex containers around the title, because the defaultmin-width: autowas letting a long nowrap title blow straight through its column instead of respecting the ellipsis meant to catch it
Along the way, testing this also turned up an unrelated site-wide bug: the service worker was treating any cross-origin request whose path happened to be /, including this API, as a same-origin page request, caching live third-party data it had no business caching. Worth fixing regardless of this widget, but it’s what surfaced it.