diff --git a/src/lib/HeardleGame.svelte b/src/lib/HeardleGame.svelte index b6a6b73..1d6a86c 100644 --- a/src/lib/HeardleGame.svelte +++ b/src/lib/HeardleGame.svelte @@ -232,17 +232,23 @@ countdownInterval = setInterval(updateTime, 1000); widget = SC.Widget(iframeElement); - widget.bind(SC.Widget.Events.READY, () => { - widget.getDuration((d: number) => (fullDuration = d)); - widget.getCurrentSound((sound: any) => { - artworkUrl = sound.artwork_url || ''; + // wait for full page load (or you could just use setTimeout) + window.addEventListener('load', () => { + widget.bind(SC.Widget.Events.READY, () => { + widget.getDuration((d: number) => (fullDuration = d)); + widget.getCurrentSound((sound: any) => { + artworkUrl = sound.artwork_url || ''; + }); + + // give SC widget 2s to settle on Netlify before probing + setTimeout(() => { + widget.play(); + widget.pause(); + widget.seekTo(0); + loading = false; + widgetReady = true; + }, 2000); }); - // preload silently: - widget.play(); - widget.pause(); - widget.seekTo(0); - loading = false; - widgetReady = true; }); widget.bind(SC.Widget.Events.PLAY, () => {