Recovering PlayerAPI from React Fiber After Spotify 1.3.8
When Spotify's desktop client moved to rspack in version 1.3.8, the window.Platform and Spicetify globals that mods used to rely on disappeared. Inside ReverseSpotify, the queue tab and cover art lookups started returning empty results overnight.
Scraping the DOM was the obvious fallback, and it works for reading the currently playing track title. It falls apart as soon as you need the actual queued and nextUp lists, paused session metadata, or reliable queue skipping and removal.
Where PlayerAPI still lives
Spotify still renders its desktop UI with React. Even when the global object is no longer exposed on window, the live PlayerAPI instance still gets passed down the component tree inside memoizedProps.
In loader/reverse-loader.js, I added a scanner that walks up from any mounted DOM node's __reactFiber$ pointer:
- Query
div, button, li, [data-testid]and grab the first element that owns a__reactFiber$property. - Walk
fiber.returnupward, capped at 400 hops. - Inspect
fiber.memoizedPropson each node for an object wheretypeof v.getQueue === "function" && v._queue. - Cache the result per
windowin aWeakMap(PLAYER_API_CACHE) so repeated checks do not re-walk the tree.
const PLAYER_API_CACHE = new WeakMap();
function scanPlayerApi(win) {
const doc = win && win.document;
if (!doc || typeof doc.querySelectorAll !== "function") return null;
const els = doc.querySelectorAll("div,button,li,[data-testid]");
let fiber = null;
for (const el of els || []) {
const key = Object.keys(el).find((k) => k.indexOf("__reactFiber$") === 0);
if (key) {
fiber = el[key];
break;
}
}
for (let depth = 0; fiber && depth < 400; depth++) {
const props = fiber.memoizedProps;
if (props && typeof props === "object") {
for (const k of Object.keys(props)) {
const v = props[k];
if (v && typeof v === "object" && typeof v.getQueue === "function" && v._queue) {
return v;
}
}
}
fiber = fiber.return;
}
return null;
}
The 400-hop limit prevents runaway traversal on detached subtrees, and the WeakMap keeps the lookup at one scan per window lifetime.
Shape and signature mismatches
Once the real PlayerAPI came back, three smaller mismatches showed up right behind it:
- Queue payload shape: Older bridges expected
nextTracks, whereasPlayerAPI.getQueue()returns{ current, queued, nextUp }. Mergingqueuedfollowed bynextUpkeeps user-queued tracks ahead of context tracks. removeFromQueuesignature: The older API took(uri, index), while the 1.3.8 instance expects an array of items ([{ uri }]). CheckingqApi._queuelets the bridge call the right signature without breaking older builds.- Image URIs: Track metadata frequently returns
spotify:image:<40-hex-chars>or a bare 40-char hash instead of an HTTPS URL.normalizeImageUrl()maps both tohttps://i.scdn.co/image/<hash>.
Fixing the test blind spot
Right before this change, I also caught a testing bug: parts of the suite were importing duplicated core helper files instead of testing loader/reverse-loader.js directly. Commit d866097 removed those duplicate modules so the test runner executes against the real loader, and the fiber fix landed with 159 JS tests covering queue normalization, double-click guards, and cover resolution.
Walking React fiber internals is inherently a heuristic, not a stable API contract, and a future Spotify client update could rename _queue or restructure props. That is why createPlayerBridge keeps the fallback order Spicetify.Player -> Platform.PlayerAPI -> fiber PlayerAPI -> DOM button clicks, degrading gracefully if one layer breaks.