// Handle manual activation (when user clicks the video thumbnail directly) async function handleManualActivation(event: Event) { if (activated) return; // Let the lite-youtube component's own click handler run first await new Promise((resolve) => setTimeout(resolve, 0)); activated = true; // Poll for playerPromise to be set, then wait for it to resolve try { // Poll for playerPromise to exist (set by addYTPlayerIframe) let attempts = 0; const maxAttempts = 50; // 5 seconds max while (attempts < maxAttempts && !(liteYoutubeEl as any).playerPromise) { await new Promise((resolve) => setTimeout(resolve, 100)); attempts++; } if (!(liteYoutubeEl as any).playerPromise) { console.error('[LiteYT] playerPromise never created'); return; } // Wait for the promise to resolve const ytPlayer = await (liteYoutubeEl as any).playerPromise; if (ytPlayer) { player = ytPlayer; set_player(ytPlayer); player_ready = true; // Trigger fetch_source event after player is ready if (mode.includes('study')) { state_study_player_fsm.send('fetch_source'); } else { break_study_player_fsm.send('fetch_source'); } } } catch (error) { console.error('[LiteYT] Failed to setup after manual activation:', error); } }
This is a piece of code written by Sonnet 4.5 in my actual app 😄
We needed onclick={activate()}
Instead we got a polling system filled with as anys lol.
This is with Playwright mcp, svelte 5 mcp, ultrathink, telling it my grandma was in danger if it did it wrong; this is the outcome lol.