From 54b806d2708ec6f0b0ca6dbc39283d6905a2e10f Mon Sep 17 00:00:00 2001 From: Timo <6156589+Shik3i@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:23:14 +0200 Subject: [PATCH] Fix Media Session listener scoping by moving it to root IIFE level in content.js --- extension/content.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/extension/content.js b/extension/content.js index a64d1d0..d9414ef 100644 --- a/extension/content.js +++ b/extension/content.js @@ -1799,6 +1799,14 @@ } }); + window.addEventListener('message', (event) => { + if (event.source !== window) return; + const data = event.data; + if (data && data.__koalaMediaSessionCapture === 1) { + window.__koalaLastCapturedMediaPosition = data.state; + } + }); + // Pull localized strings for the in-page dialog/badge (English fallback above). chrome.runtime.sendMessage({ type: 'GET_HCM_STRINGS' }, (res) => { if (chrome.runtime.lastError || !res) return; @@ -1806,13 +1814,6 @@ // If the badge is already showing (early desync), refresh its text in place. // Re-creating the host element nukes the click target mid-poll and can drop a // click that landed between remove() and the re-create (L-4). - window.addEventListener('message', (event) => { - if (event.source !== window) return; - const data = event.data; - if (data && data.__koalaMediaSessionCapture === 1) { - window.__koalaLastCapturedMediaPosition = data.state; - } - }); if (hcmBadgeHost) { const span = hcmBadgeHost.shadowRoot && hcmBadgeHost.shadowRoot.querySelector('span'); if (span) span.textContent = '● ' + hcmStrings.badge;