Changeset 16b0c00 in Klonkt


Ignore:
Timestamp:
06/20/2026 02:52:15 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
2873b30
Parents:
5f47671
Message:

fix(embed): Spotify API via CSP whitelist + faster fallback

Diagnosis (measured live): the loader open.spotify.com (200) loads the real
API bundle from embed-cdn.spotifycdn.com, which was NOT in our CSP scriptSrc
→ API never init → 8s wait before the bare iframe = "sluggish". Not an
ad-blocker issue.

  • CSP: *.spotifycdn.com added to scriptSrc + connectSrc (+ *.scdn.co).
  • Spotify API timeout 8s → 4s so the iframe fallback appears quickly if the API still doesn't initialise (CDN 503 / origin gating).

buster embed-player.js?v=5.

Co-Authored-By: Claude <noreply@…>

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/assets/js/embed-player.js

    r5f47671 r16b0c00  
    101101      };
    102102      loadScript('https://open.spotify.com/embed/iframe-api/v1').catch(reject);
    103       setTimeout(() => reject(new Error('Spotify API timeout')), API_TIMEOUT);
     103      // Korter dan API_TIMEOUT: Spotify's bundle initialiseert snel óf helemaal
     104      // niet (CDN 503 / origin-gating). Niet 8s wachten vóór de iframe-fallback.
     105      setTimeout(() => reject(new Error('Spotify API timeout')), 4000);
    104106    });
    105107    return scripts.sp;
  • src/server.js

    r5f47671 r16b0c00  
    9393        "https://s.ytimg.com",       // YouTube player-assets
    9494        "https://w.soundcloud.com",  // SoundCloud Widget API (api.js)
    95         "https://open.spotify.com",  // Spotify iFrame API
     95        "https://open.spotify.com",  // Spotify iFrame API (loader)
     96        "https://*.spotifycdn.com",  // Spotify iFrame API (echte bundle: embed-cdn.spotifycdn.com)
    9697      ],
    9798      // Helmet's default zet script-src-attr op 'none', wat ALLE inline event-
     
    103104      styleSrc: ["'self'", "'unsafe-inline'"],
    104105      imgSrc: ["'self'", "data:", "https:"],
    105       connectSrc: ["'self'", "wss:", "ws:"],
     106      connectSrc: ["'self'", "wss:", "ws:", "https://*.spotifycdn.com", "https://*.scdn.co"],
    106107      // blob: is required for the audio player — it fetch()es track bytes and
    107108      // plays from a blob: object URL (Spotify-style). Without blob: here the
  • src/views/shell.ejs

    r5f47671 r16b0c00  
    303303<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte
    304304     player-API's + gedeelde mutual-exclusion registry met de site-speler. -->
    305 <script src="/assets/js/embed-player.js?v=4" defer></script>
     305<script src="/assets/js/embed-player.js?v=5" defer></script>
    306306<% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %>
    307307  <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
Note: See TracChangeset for help on using the changeset viewer.